libselinux: Only check SELinux enabled status once in selinux_check_access().
PATCH 1/2 libselinux: Only check SELinux enabled status once in selinux_check_access().
Move the SELinux enabled check to the once handler so that we do not perform this on each call to selinux_check_access(). Reduces overhead in both the SELinux-enabled and the SELinux-disabled cases.
Extracted from the Android external/libselinux tree.
Change-Id I61fe85bc04fe53cbf840ba712c81bdb06e4e0c2f
Signed-off-by Stephen Smalley <[email protected]>
--- libselinux/src/checkAccess.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
libselinux/src/checkAccess.c +7 -4
@@ -8,10 +8,13 @@#include "avc_internal.h" static pthread_once_t once =PTHREAD_ONCE_INIT ; +static int selinux_enabled;static void avc_init_once (void ) { -avc_open (NULL ,0 ); + selinux_enabled =is_selinux_enabled (); +if (selinux_enabled ==1 ) +avc_open (NULL ,0 ); }int selinux_check_access (const char *scon,const char *tcon,const char *class,const char *perm,void *aux) {
@@ -21,11 +24,11 @@ int selinux_check_access(const char *scon, const char *tcon, const char *class,security_class_t sclass;access_vector_t av; -if (is_selinux_enabled () ==0 ) -return 0 ; -__selinux_once (once, avc_init_once); +if (selinux_enabled !=1 ) +return 0 ; + rc =avc_context_to_sid (scon, &scon_id);if (rc <0 )return rc;
Signature · 1 line
1.9.3
PATCH 2/2 libselinux: Adjustments to android property backend.
From: Robert Craig <[email protected]>
Allow the android property backend parser to accept the SELABEL_OPT_VALIDATE option and to perform a validate callback.
Extracted from the Android external/libselinux tree.
Change-Id If061502c5e2489a1155798fac1d8357dbb8d13ba
Signed-off-by Robert Craig <[email protected]>
--- libselinux/src/label_android_property.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
libselinux/src/label_android_property.c +8 -4
@@ -124,6 +124,14 @@ static int process_line(struct selabel_handle *rec, path, lineno, context);return -1 ; } + +if (rec->validating) { +if (selabel_validate (rec, &spec_arr[nspec].lr) <0 ) { +selinux_log (SELINUX_WARNING , +"%s: line %d has invalid context %s\n" , + path, lineno, spec_arr[nspec].lr.ctx_raw); + } + } } data->nspec = ++nspec;
@@ -147,10 +155,6 @@ static int init(struct selabel_handle *rec, struct selinux_opt *opts,case SELABEL_OPT_PATH : path = opts[n].value;break ; -default : -selinux_log (SELINUX_WARNING , -"Argument type (%d) not recognized. Skipping\n" , opts[n].type); -break ; }if (!path)
Signature · 1 line
1.9.3