MCPcopy Create free account
hub / github.com/apache/cloudberry / sepgsql_avc_compute

Function sepgsql_avc_compute

contrib/sepgsql/uavc.c:199–288  ·  view source on GitHub ↗

* sepgsql_avc_compute * * A fallback path, when cache mishit. It asks SELinux its access control * decision for the supplied pair of security context and object class. */

Source from the content-addressed store, hash-verified

197 * decision for the supplied pair of security context and object class.
198 */
199static avc_cache *
200sepgsql_avc_compute(const char *scontext, const char *tcontext, uint16 tclass)
201{
202 char *ucontext = NULL;
203 char *ncontext = NULL;
204 MemoryContext oldctx;
205 avc_cache *cache;
206 uint32 hash;
207 int index;
208 struct av_decision avd;
209
210 hash = sepgsql_avc_hash(scontext, tcontext, tclass);
211 index = hash % AVC_NUM_SLOTS;
212
213 /*
214 * Validation check of the supplied security context. Because it always
215 * invoke system-call, frequent check should be avoided. Unless security
216 * policy is reloaded, validation status shall be kept, so we also cache
217 * whether the supplied security context was valid, or not.
218 */
219 if (security_check_context_raw(tcontext) != 0)
220 ucontext = sepgsql_avc_unlabeled();
221
222 /*
223 * Ask SELinux its access control decision
224 */
225 if (!ucontext)
226 sepgsql_compute_avd(scontext, tcontext, tclass, &avd);
227 else
228 sepgsql_compute_avd(scontext, ucontext, tclass, &avd);
229
230 /*
231 * It also caches a security label to be switched when a client labeled as
232 * 'scontext' executes a procedure labeled as 'tcontext', not only access
233 * control decision on the procedure. The security label to be switched
234 * shall be computed uniquely on a pair of 'scontext' and 'tcontext',
235 * thus, it is reasonable to cache the new label on avc, and enables to
236 * reduce unnecessary system calls. It shall be referenced at
237 * sepgsql_needs_fmgr_hook to check whether the supplied function is a
238 * trusted procedure, or not.
239 */
240 if (tclass == SEPG_CLASS_DB_PROCEDURE)
241 {
242 if (!ucontext)
243 ncontext = sepgsql_compute_create(scontext, tcontext,
244 SEPG_CLASS_PROCESS, NULL);
245 else
246 ncontext = sepgsql_compute_create(scontext, ucontext,
247 SEPG_CLASS_PROCESS, NULL);
248 if (strcmp(scontext, ncontext) == 0)
249 {
250 pfree(ncontext);
251 ncontext = NULL;
252 }
253 }
254
255 /*
256 * Set up an avc_cache object

Callers 1

sepgsql_avc_lookupFunction · 0.85

Calls 10

sepgsql_avc_hashFunction · 0.85
sepgsql_avc_unlabeledFunction · 0.85
sepgsql_compute_avdFunction · 0.85
sepgsql_compute_createFunction · 0.85
MemoryContextSwitchToFunction · 0.85
sepgsql_avc_reclaimFunction · 0.85
lconsFunction · 0.85
pfreeFunction · 0.50
palloc0Function · 0.50
pstrdupFunction · 0.50

Tested by

no test coverage detected