* 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. */
| 197 | * decision for the supplied pair of security context and object class. |
| 198 | */ |
| 199 | static avc_cache * |
| 200 | sepgsql_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 |
no test coverage detected