external/libselinux
This patch series enables supoprt for two features:
1. Allow the specification of an sebool flag in seapp_contexts, cleaned up per Stephen's requests. A specified sebool= is matched over unspecified sebool=.
2. Allowing spawned apps to launch in the Zygote's context when SELinux is in permissive mode and a match is not found.
[PATCH 1/2] Allow zygote to spawn non matched apps in permissive mode [PATCH 2/2] You can now specify a sebool= flag in seapp_contexts
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
PATCH 1/2 Allow zygote to spawn non matched apps in permissive mode
This patch will allow non-matched apps in seapp_contexts to still be spawned via the zygote. An error message will be sent to logcat.
--- src/android.c | 5 ++--- 1 files changed, 2 insertions(+), 3 deletions(-)
src/android.c +2 -3
@@ -491,8 +491,7 @@ int selinux_android_setcontext(uid_t uid,selinux_log (SELINUX_ERROR ,"%s: No match for app with uid %d, seinfo %s, name %s\n" , __FUNCTION__, uid, seinfo, pkgname); - rc =-1 ; - goto out; + goto err; } ctx_str =context_str (ctx);
@@ -524,7 +523,7 @@ err:"%s: Error setting context for app with uid %d, seinfo %s: %s\n" , __FUNCTION__, uid, seinfo, strerror(errno)); - rc =-1 ; + rc = (security_getenforce () ==0 ) ?0 :-1 ; goto out; oom:selinux_log (SELINUX_ERROR ,"%s: Out of memory\n" , __FUNCTION__);
Signature · 7 lines
1.7.0.4 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Re: [PATCH 1/2] Allow zygote to spawn non matched apps in permissive mode
Quoted 15 lines · William Roberts
This patch will allow non-matched apps in
seapp_contextsto still be spawned via the zygote. An error message will be sent to logcat.Change-Id I9fb5dcfeb384a26e6a01d69bffd2ef14af74c51cSigned-off-by William Roberts <[email protected]>--- src/android.c | 5 ++--- 1 files changed, 2 insertions(+), 3 deletions(-)src/android.c +0
-0
src/android.c int selinux_android_setcontext(uid_t uid, · line 494
Quoted 6 lines
src/android.c +1
-2@@ -491,8 +491,7 @@ int selinux_android_setcontext(uid_t uid,selinux_log (SELINUX_ERROR ,"%s: No match for app with uid %d, seinfo %s, name %s\n" , __FUNCTION__, uid, seinfo, pkgname); - rc =-1 ; - goto out; + goto err;
Falls over when testing with a deliberately broken seapp_contexts configuration in enforcing mode. Test scenario:
- Comment out line for untrusted_app in seapp_contexts, push to device.
- Install third party app.
- Start third party app in permissive mode (works, logs message).
- Switch to enforcing mode.
- Try starting third party app (fails with log message followed by double free warning, blank screen).
Quoted 12 lines
src/android.c +1
-1} ctx_str =context_str (ctx);@@ -524,7 +523,7 @@ err:"%s: Error setting context for app with uid %d, seinfo %s: %s\n" , __FUNCTION__, uid, seinfo, strerror(errno)); - rc =-1 ; + rc = (security_getenforce () ==0 ) ?0 :-1 ; goto out; oom:selinux_log (SELINUX_ERROR ,"%s: Out of memory\n" , __FUNCTION__);
Signature · 8 lines
Stephen Smalley National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
PATCH 2/2 You can now specify a sebool= flag in seapp_contexts
In reply to William Robertsand that rule will ONLY be applied on a match to that boolean, and only if the boolean is set to true.
--- src/android.c | 41 ++++++++++++++++++++++++++++++++++++++--- 1 files changed, 38 insertions(+), 3 deletions(-)
src/android.c +38 -3
@@ -45,6 +45,7 @@ struct seapp_context {char *domain;char *type;char *level; +char *sebool;char levelFromUid; };
@@ -85,6 +86,12 @@ static int seapp_context_cmp(const void *A, const void *B)if (!s1->name && s2->name)return 1 ; +/* Give precedence to a specified sebool= over an unspecified sebool=. */ +if (s1->sebool && !s2->sebool) +return -1 ; +if (!s1->sebool && s2->sebool) +return 1 ; +/* Anything else has equal precedence. */ return 0 ; }
@@ -196,6 +203,10 @@ int selinux_android_seapp_context_reload(void) cur->level =strdup (value);if (!cur->level) goto oom; + }else if (!strcasecmp (name,"sebool" )) { + cur->sebool =strdup (value); +if (!cur->sebool) + goto oom; }else goto err;
@@ -217,12 +228,13 @@ int selinux_android_seapp_context_reload(void)int i;for (i =0 ; i < nspec; i++) { cur = seapp_contexts[i]; -selinux_log (SELINUX_INFO ,"%s: isSystemServer=%s user=%s seinfo=%s name=%s -> domain=%s type=%s level=%s levelFromUid=%s" , +selinux_log (SELINUX_INFO ,"%s: isSystemServer=%s user=%s seinfo=%s name=%s -> domain=%s type=%s level=%s levelFromUid=%s sebool=%s" , __FUNCTION__, cur->isSystemServer ?"true" :"false" , cur->user, cur->seinfo, cur->name, cur->domain, cur->type, cur->level, - cur->levelFromUid ?"true" :"false" ); + cur->levelFromUid ?"true" :"false" , + cur->sebool); } }#endif
@@ -335,6 +347,17 @@ int selinux_android_setfilecon2(const char *pkgdir,if (!cur->type)continue ; +if (cur->sebool) { +int value =security_get_boolean_active (cur->sebool); +if (value ==0 ) +continue ; +else if (value ==-1 ) { +selinux_log (SELINUX_ERROR , \ +"Could not find boolean: %s " , cur->sebool); + goto err; + } + } +if (context_type_set (ctx, cur->type)) goto oom;
@@ -348,7 +371,7 @@ int selinux_android_setfilecon2(const char *pkgdir,if (context_range_set (ctx, cur->level)) goto oom; } - +break ; }
@@ -443,6 +466,7 @@ int selinux_android_setcontext(uid_t uid,for (i =0 ; i < nspec; i++) { cur = seapp_contexts[i]; +if (cur->isSystemServer != isSystemServer)continue ;if (cur->user) {
@@ -466,6 +490,17 @@ int selinux_android_setcontext(uid_t uid,if (!cur->domain)continue ; +if (cur->sebool) { +int value =security_get_boolean_active (cur->sebool); +if (value ==0 ) +continue ; +else if (value ==-1 ) { +selinux_log (SELINUX_ERROR , \ +"Could not find boolean: %s " , cur->sebool); + goto err; + } + } +if (context_type_set (ctx, cur->domain)) goto oom;
Signature · 7 lines
1.7.0.4 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Re: [PATCH 2/2] You can now specify a sebool= flag in seapp_contexts
Quoted 13 lines · William Roberts
and that rule will ONLY be applied on a match to that boolean, and only if the boolean is set to true.
Change-Id Ifdba35cd3a78ce1c8173786514db649203018e28Signed-off-by William Roberts <[email protected]>--- src/android.c | 41 ++++++++++++++++++++++++++++++++++++++--- 1 files changed, 38 insertions(+), 3 deletions(-)src/android.c +0
-0@@ -217,12 +228,13 @@ int selinux_android_seapp_context_reload(void)int i;for (i =0 ; i < nspec; i++) {
src/android.c int selinux_android_seapp_context_reload(void) · line 237
Quoted 10 lines
src/android.c +3
-2cur = seapp_contexts[i]; -selinux_log (SELINUX_INFO ,"%s: isSystemServer=%s user=%s seinfo=%s name=%s -> domain=%s type=%s level=%s levelFromUid=%s" , +selinux_log (SELINUX_INFO ,"%s: isSystemServer=%s user=%s seinfo=%s name=%s -> domain=%s type=%s level=%s levelFromUid=%s sebool=%s" , __FUNCTION__, cur->isSystemServer ?"true" :"false" , cur->user, cur->seinfo, cur->name, cur->domain, cur->type, cur->level, - cur->levelFromUid ?"true" :"false" ); + cur->levelFromUid ?"true" :"false" , + cur->sebool);
sebool is an input selector, thus belongs right after name=%s before ->.
src/android.c int selinux_android_setcontext(uid_t uid, · line 469
Quoted 5 lines
src/android.c +1
-0@@ -443,6 +466,7 @@ int selinux_android_setcontext(uid_t uid,for (i =0 ; i < nspec; i++) { cur = seapp_contexts[i]; +
Extraneous whitespace change.
Quoted 3 lines
src/android.c +0
-0if (cur->isSystemServer != isSystemServer)continue ;if (cur->user) {
Signature · 8 lines
Stephen Smalley National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.