Support for sebool in seapp_contexts
PATCH 1/1 Support for sebool in seapp_contexts
You can now specify a sebool= flag in seapp_contexts and that rule will ONLY be applied on a match to that boolean, and only if the boolean is set to true.
Change-Id: Ifdba35cd3a78ce1c8173786514db649203018e28
--- src/android.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 files changed, 37 insertions(+), 2 deletions(-)
src/android.c +37 -2
@@ -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
@@ -308,6 +320,17 @@ int selinux_android_setfilecon2(const char *pkgdir,for (i =0 ; i < nspec; i++) { cur = seapp_contexts[i]; +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; + } + } +/* isSystemServer=true is only for app process labeling. */ if (cur->isSystemServer)continue ;
@@ -443,6 +466,18 @@ int selinux_android_setcontext(uid_t uid,for (i =0 ; i < nspec; i++) { cur = seapp_contexts[i]; + +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 (cur->isSystemServer != isSystemServer)continue ;if (cur->user) {
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.
Quoted 12 lines · William Roberts
You can now specify a sebool= flag in
seapp_contextsand that rule will ONLY be applied on a match to that boolean, and only if the boolean is set to true.Change-Id: Ifdba35cd3a78ce1c8173786514db649203018e28
--- src/android.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 files changed, 37 insertions(+), 2 deletions(-)src/android.c +0
-0@@ -308,6 +320,17 @@ int selinux_android_setfilecon2(const char *pkgdir,for (i =0 ; i < nspec; i++) { cur = seapp_contexts[i];
src/android.c int selinux_android_setfilecon2(const char *pkgdir, · line 331
Quoted 10 lines
src/android.c +9
-0+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; + }
I'd suggest just issuing a warning and continuing in the error cases. Otherwise a typo in a boolean name or the removal or renaming of a boolean in policy could prevent apps from being started at all.
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.
A message that is not in the archive (sent off-list or not yet received): E24EB765E1998A40A0C06DE52672C4820176F6C8A5F5@staex7mb1.telecom.sna.samsung.com
Quoted 3 lines · William Roberts
I've been thinking of checking the enforcing level. If it is enforcing then it should error, if it is permissive then it should warn and let the app start in the wrong context.
When brining the system up on new platforms this is often a problem. I will make this change and resubmit.
Do you mean in general (i.e. changing the err block to check security_getenforce), or just for the case where a boolean isn't defined?
I have mixed feelings about checking and using security_getenforce() for anything other than permission denials, as it can hide problems during testing. Also, in Android, it is a bit harder to switch the system back to permissive mode than on a conventional Linux system.
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.
In general I would like to add this feature. I think it is much more palatable checking for denials and errors with the device "working", rather then having it freak out at the splash screen. For instance, suppose the launcher isn't in the right domain, you fix that, just to find out some other app luanched off the launcher would fail too. If you could just audit, you could review the denials and then make your policy change in one movement.
Just doing it for sebool doesn't make sense to me, as adding the boolean rule is no different than seinfo or other rules. Either it matches or not.
Quoted 18 lines · Stephen Smalley
Quoted 3 lines · William Roberts
I've been thinking of checking the enforcing level. If it is enforcing then it should error, if it is permissive then it should warn and let the app start in the wrong context.
When brining the system up on new platforms this is often a problem. I will make this change and resubmit.
Do you mean in general (i.e. changing the err block to check
security_getenforce), or just for the case where a boolean isn't defined?I have mixed feelings about checking and using
security_getenforce()for anything other than permission denials, as it can hide problems during testing. Also, in Android, it is a bit harder to switch the system back to permissive mode than on a conventional Linux system.--
Stephen Smalley
National Security Agency
Signature · 8 lines
Respectfully, William C Roberts -- 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.
Quoted 11 lines · William Roberts
In general I would like to add this feature. I think it is much more palatable checking for denials and errors with the device "working", rather then having it freak out at the splash screen. For instance, suppose the launcher isn't in the right domain, you fix that, just to find out some other app luanched off the launcher would fail too. If you could just audit, you could review the denials and then make your policy change in one movement.
Just doing it for sebool doesn't make sense to me, as adding the boolean rule is no different than seinfo or other rules. Either it matches or not.
Understood. But here's the counterargument. Let's suppose I am testing my system in permissive mode, looking for avc denials in my dmesg and logcat output (the latter for zygote denials), and everything looks ok. Now I switch to enforcing mode and suddenly find that all apps fail to launch because there was an error in my seapp_contexts configuration. I never thought to look for other kinds of error messages while in permissive mode (and SEAndroidManager won't currently show me these other messages). And now I can't switch back to permissive mode without going to ADB because I can't even run my SEAndroidManager app to set it. See the concern?
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.
Yeah but the Zygote failures will be in logcat, so if you missed them when you were testing in permissive mode, then its your problem. This is the same behavior as the rest of the system, we just need to agree upon a "avc denied" message for Zygote and teach the SEAndroidManager app to look for those too.
I don't think I can advise as to the best message and was looking to you for a possible formatting for it?
Quoted 28 lines · Stephen Smalley
Quoted 11 lines · William Roberts
In general I would like to add this feature. I think it is much more palatable checking for denials and errors with the device "working", rather then having it freak out at the splash screen. For instance, suppose the launcher isn't in the right domain, you fix that, just to find out some other app luanched off the launcher would fail too. If you could just audit, you could review the denials and then make your policy change in one movement.
Just doing it for sebool doesn't make sense to me, as adding the boolean rule is no different than seinfo or other rules. Either it matches or not.
Understood. But here's the counterargument. Let's suppose I am testing my system in permissive mode, looking for avc denials in my dmesg and logcat output (the latter for zygote denials), and everything looks ok. Now I switch to enforcing mode and suddenly find that all apps fail to launch because there was an error in my
seapp_contextsconfiguration. I never thought to look for other kinds of error messages while in permissive mode (and SEAndroidManager won't currently show me these other messages). And now I can't switch back to permissive mode without going to ADB because I can't even run my SEAndroidManager app to set it. See the concern?--
Stephen Smalley
National Security Agency
Signature · 8 lines
Respectfully, William C Roberts -- 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.
Quoted 8 lines · William Roberts
Yeah but the Zygote failures will be in logcat, so if you missed them when you were testing in permissive mode, then its your problem. This is the same behavior as the rest of the system, we just need to agree upon a "avc denied" message for Zygote and teach the SEAndroidManager app to look for those too.
I don't think I can advise as to the best message and was looking to you for a possible formatting for it?
It isn't an avc denial. I don't remember now whether we wired up the callback to prefix these messages with SELinux? If so, then that should suffice as a keyword for filtering the logs.
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.
Quoted 7 lines · Stephen Smalley
Quoted 6 lines · William Roberts
Yeah but the Zygote failures will be in logcat, so if you missed them when you were testing in permissive mode, then its your problem. This is the same behavior as the rest of the system, we just need to agree upon a "avc denied" message for Zygote and teach the SEAndroidManager app to look for those too.
Quoted 6 lines
Quoted 2 lines
I don't think I can advise as to the best message and was looking to you for a possible formatting for it?
It isn't an avc denial. I don't remember now whether we wired up the callback to prefix these messages with SELinux? If so, then that should suffice as a keyword for filtering the logs.
Commented out the untrusted_app line and tried running a third party app. Got this message in logcat *:E:
E/SELinux ( 1229): selinux_android_setcontext: No match for app with uid 10055, seinfo default, name com.adobe.reader
So you can already use SELinux as the keyword for filtering, and then pull out the relevant fields. It isn't an AVC message though.
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.
Yeah IMO the SELinux Error messages in Logact are sufficient and their is no need to make it more complex.
I wasn't sure if we wanted to follow the kernel convention.
Quoted 27 lines · Stephen Smalley
Quoted 7 lines · Stephen Smalley
Quoted 6 lines · William Roberts
Yeah but the Zygote failures will be in logcat, so if you missed them when you were testing in permissive mode, then its your problem. This is the same behavior as the rest of the system, we just need to agree upon a "avc denied" message for Zygote and teach the SEAndroidManager app to look for those too.
Quoted 6 lines
Quoted 2 lines
I don't think I can advise as to the best message and was looking to you for a possible formatting for it?
It isn't an avc denial. I don't remember now whether we wired up the callback to prefix these messages with SELinux? If so, then that should suffice as a keyword for filtering the logs.
Commented out the
untrusted_appline and tried running a third party app. Got this message in logcat *:E:
E/SELinux ( 1229):selinux_android_setcontext: No match for app with uid 10055, seinfo default, name com.adobe.readerSo you can already use SELinux as the keyword for filtering, and then pull out the relevant fields. It isn't an AVC message though.
--
Stephen Smalley
National Security Agency
Signature · 8 lines
Respectfully, William C Roberts -- 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.
Quoted 13 lines · William Roberts
You can now specify a sebool= flag in
seapp_contextsand that rule will ONLY be applied on a match to that boolean, and only if the boolean is set to true.Change-Id: Ifdba35cd3a78ce1c8173786514db649203018e28
--- src/android.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 files changed, 37 insertions(+), 2 deletions(-)src/android.c +0
-0@@ -308,6 +320,17 @@ int selinux_android_setfilecon2(const char *pkgdir,for (i =0 ; i < nspec; i++) { cur = seapp_contexts[i];
src/android.c int selinux_android_setfilecon2(const char *pkgdir, · line 332
Quoted 10 lines
src/android.c +10
-0+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; + } + }
Move this block after all other selectors have been checked, i.e. after the check of cur->name, so that we don't waste time fetching the active boolean value if this entry isn't going to match anyway due to one of the other selectors. Ditto for the one in selinux_android_setcontext(). Might also want to distinguish errno cases, e.g. errno == ENOENT should mean that the boolean wasn't defined vs EACCES (not allowed to read selinuxfs) vs ENOMEM (memory allocation failure when fetching the boolean).
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.