Skip to contentSkip to conversation

libselinux: android: support exact match for a property key

PATCH In review Jaekyun Seok 3 participants 5 messages Oct 19, 2017 – Oct 22, 2017 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libselinux: android: support exact match for a property key

Performs exact match if a property key of property contexts ends with '$' instead of prefix match.

This will enable to define an exact rule which can avoid unexpected context assignment.

---
 libselinux/src/label_backends_android.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
libselinux/src/label_backends_android.c +7 -2
index cb8aae26..4611d396 100644
@@ -258,8 +258,13 @@ static struct selabel_lookup_rec *property_lookup(struct selabel_handle *rec,
 	}
 
 	for (i = 0; i < data->nspec; i++) {
-		if (strncmp(spec_arr[i].property_key, key,
-			    strlen(spec_arr[i].property_key)) == 0) {
+		size_t property_key_len = strlen(spec_arr[i].property_key);
+		if (spec_arr[i].property_key[property_key_len - 1] == '$' &&
+		    strlen(key) == property_key_len - 1 &&
+		    strncmp(spec_arr[i].property_key, key, property_key_len - 1) == 0) {
+			break;
+		}
+		if (strncmp(spec_arr[i].property_key, key, property_key_len) == 0) {
 			break;
 		}
 		if (strncmp(spec_arr[i].property_key, "*", 1) == 0)
Signature · 1 line
2.15.0.rc0.271.g36b669edcc-goog
#1 lore raw

Please hold off on submission. We're discussing if this is really necessary.

Quoted 35 lines · Jaekyun Seok via Selinux

Performs exact match if a property key of property contexts ends with '$' instead of prefix match.

This will enable to define an exact rule which can avoid unexpected context assignment.

---
 libselinux/src/label_backends_android.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
libselinux/src/label_backends_android.c +7 -3
index cb8aae26..4611d396 100644
@@ -258,8 +258,13 @@ static struct selabel_lookup_rec *property_lookup(struct selabel_handle *rec,
        }
 
        for (i = 0; i < data->nspec; i++) {
-               if (strncmp(spec_arr[i].property_key, key,
-                           strlen(spec_arr[i].property_key)) == 0) {
+               size_t property_key_len = strlen(spec_arr[i].property_key);
+               if (spec_arr[i].property_key[property_key_len - 1] == '$' &&
+                   strlen(key) == property_key_len - 1 &&
+                   strncmp(spec_arr[i].property_key, key, property_key_len - 1) == 0) {
+                       break;
+               }
+               if (strncmp(spec_arr[i].property_key, key, property_key_len) == 0) {
                        break;
                }
                if (strncmp(spec_arr[i].property_key, "*", 1) == 0)
--

2.15.0.rc0.271.g36b669edcc-goog

#2 lore raw
Quoted 1 line · Jeffrey Vander Stoep via Selinux

Please hold off on submission. We're discussing if this is really necessary.

Yeah I'd like to hear about what issues the current longest match logic was causing
in the commit message.

Quoted 5 lines
Quoted 2 lines · Jaekyun Seok via Selinux

Performs exact match if a property key of property contexts ends with '$' instead of prefix match.

This seems like an overly verbose way to accomplish exact match. The property_contexts
file has things like:

* <-- match everything
foo.bar. <- match prefix foo.bar. properties
foo.bar.baz <-- currently matches foo.bar.baz, foo.bar.bazbaz, etc. No trailing .
could be changed to mean exact match.

Really what you would want is that if it doesn't end with a dot, don't do a prefix
match. No need to add the $ semantic AFAICT.

Quoted 34 lines
Quoted 33 lines

This will enable to define an exact rule which can avoid unexpected context assignment.

---
 libselinux/src/label_backends_android.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
libselinux/src/label_backends_android.c +7 -3
index cb8aae26..4611d396 100644
@@ -258,8 +258,13 @@ static struct selabel_lookup_rec *property_lookup(struct selabel_handle *rec,
        }
 
        for (i = 0; i < data->nspec; i++) {
-               if (strncmp(spec_arr[i].property_key, key,
-                           strlen(spec_arr[i].property_key)) == 0) {
+               size_t property_key_len = strlen(spec_arr[i].property_key);
+               if (spec_arr[i].property_key[property_key_len - 1] == '$' &&
+                   strlen(key) == property_key_len - 1 &&
+                   strncmp(spec_arr[i].property_key, key, property_key_len - 1) == 0) {
+                       break;
+               }
+               if (strncmp(spec_arr[i].property_key, key, property_key_len) == 0) {
                        break;
                }
                if (strncmp(spec_arr[i].property_key, "*", 1) == 0)
--

2.15.0.rc0.271.g36b669edcc-goog

Signature · 3 lines
Respectfully,

William C Roberts
#3 lore raw

Please see my inline comments.

Thanks,

Quoted 9 lines · William Roberts
Quoted 1 line · Jeffrey Vander Stoep via Selinux

Please hold off on submission. We're discussing if this is really

necessary.

Yeah I'd like to hear about what issues the current longest match logic was causing
in the commit message.

I am working to whitelist properties which should be restricted from being accessed by some components.

To do that, exact match should be supported.

Quoted 18 lines
Quoted 5 lines
Quoted 1 line · Jaekyun Seok via Selinux

Performs exact match if a property key of property contexts ends with

'$'

Quoted 1 line
Quoted 1 line

instead of prefix match.

This seems like an overly verbose way to accomplish exact match. The property_contexts
file has things like:

* <-- match everything
foo.bar. <- match prefix foo.bar. properties
foo.bar.baz <-- currently matches foo.bar.baz, foo.bar.bazbaz, etc. No trailing .
could be changed to mean exact match.

Quoted 4 lines

Really what you would want is that if it doesn't end with a dot, don't do a prefix
match. No need to add the $ semantic AFAICT.

Sounds good to me. I will discuss this way internally.

Quoted 49 lines
Quoted 11 lines

Review

Quoted 11 lines

This will enable to define an exact rule which can avoid unexpected context assignment.

---
 libselinux/src/label_backends_android.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/libselinux/src/label_backends_android.c

Quoted 4 lines

libselinux/src/label_backends_android.c static struct selabel_lookup_rec

Quoted 4 lines

index cb8aae26..4611d396 100644

libselinux/src/label_backends_android.c +0 -0
@@ -258,8 +258,13 @@ static struct selabel_lookup_rec

*property_lookup(struct selabel_handle *rec,

Quoted 6 lines

libselinux/src/label_backends_android.c static struct selabel_lookup_rec *property_lookup(struct selabel_handle *rec,

Quoted 6 lines
libselinux/src/label_backends_android.c +1 -2
        }
 
        for (i = 0; i < data->nspec; i++) {
-               if (strncmp(spec_arr[i].property_key, key,
-                           strlen(spec_arr[i].property_key)) == 0) {
+               size_t property_key_len = strlen(spec_arr[i].property_

key);

Quoted 1 line

libselinux/src/label_backends_android.c static struct selabel_lookup_rec · line 262

Quoted 1 line
libselinux/src/label_backends_android.c +1 -0
+               if (spec_arr[i].property_key[property_key_len - 1] ==

'$' &&

Quoted 2 lines

libselinux/src/label_backends_android.c static struct selabel_lookup_rec · line 264

Quoted 2 lines
libselinux/src/label_backends_android.c +2 -0
+                   strlen(key) == property_key_len - 1 &&
+                   strncmp(spec_arr[i].property_key, key,

property_key_len - 1) == 0) {

Quoted 3 lines

libselinux/src/label_backends_android.c static struct selabel_lookup_rec *property_lookup(struct selabel_handle *rec,

Quoted 3 lines
libselinux/src/label_backends_android.c +3 -0
+                       break;
+               }
+               if (strncmp(spec_arr[i].property_key, key,

property_key_len) == 0) {

Quoted 8 lines
Quoted 7 lines
libselinux/src/label_backends_android.c +0 -1
                        break;
                }
                if (strncmp(spec_arr[i].property_key, "*", 1) == 0)
--

2.15.0.rc0.271.g36b669edcc-goog

--
Respectfully,

William C Roberts

Signature · 1 line
Jaekyun Seok | Software Engineer | [email protected] | +82 2 531 9235
#4 lore raw

FYI, I've uploaded
https://android-review.googlesource.com/#/c/platform/external/selinux/+/517958/
for public discussion.

Thanks,

Quoted 105 lines · Jaekyun Seok

Please see my inline comments.

Thanks,

On Sat, Oct 21, 2017 at 1:02 AM, William Roberts <[email protected]

Quoted 11 lines

wrote:

Quoted 1 line · Jeffrey Vander Stoep via Selinux

Please hold off on submission. We're discussing if this is really

necessary.

Yeah I'd like to hear about what issues the current longest match logic was causing
in the commit message.

I am working to whitelist properties which should be restricted from being accessed by some components.

To do that, exact match should be supported.

Quoted 18 lines
Quoted 5 lines
Quoted 1 line · Jaekyun Seok via Selinux

Performs exact match if a property key of property contexts ends with

'$'

Quoted 1 line
Quoted 1 line

instead of prefix match.

This seems like an overly verbose way to accomplish exact match. The property_contexts
file has things like:

* <-- match everything
foo.bar. <- match prefix foo.bar. properties
foo.bar.baz <-- currently matches foo.bar.baz, foo.bar.bazbaz, etc. No trailing .
could be changed to mean exact match.

Quoted 4 lines

Really what you would want is that if it doesn't end with a dot, don't do a prefix
match. No need to add the $ semantic AFAICT.

Sounds good to me. I will discuss this way internally.

Quoted 44 lines
Quoted 11 lines

Review

Quoted 11 lines

This will enable to define an exact rule which can avoid unexpected context assignment.

---
 libselinux/src/label_backends_android.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/libselinux/src/label_backends_android.c

Quoted 4 lines

libselinux/src/label_backends_android.c static struct selabel_lookup_rec

Quoted 4 lines

index cb8aae26..4611d396 100644

libselinux/src/label_backends_android.c +0 -0
@@ -258,8 +258,13 @@ static struct selabel_lookup_rec

*property_lookup(struct selabel_handle *rec,

Quoted 6 lines

libselinux/src/label_backends_android.c static struct selabel_lookup_rec *property_lookup(struct selabel_handle *rec,

Quoted 6 lines
libselinux/src/label_backends_android.c +1 -2
        }
 
        for (i = 0; i < data->nspec; i++) {
-               if (strncmp(spec_arr[i].property_key, key,
-                           strlen(spec_arr[i].property_key)) == 0) {
+               size_t property_key_len =

strlen(spec_arr[i].property_key);

Quoted 1 line

libselinux/src/label_backends_android.c static struct selabel_lookup_rec · line 262

Quoted 1 line
libselinux/src/label_backends_android.c +1 -0
+               if (spec_arr[i].property_key[property_key_len - 1] ==

'$' &&

Quoted 2 lines

libselinux/src/label_backends_android.c static struct selabel_lookup_rec · line 264

Quoted 2 lines
libselinux/src/label_backends_android.c +2 -0
+                   strlen(key) == property_key_len - 1 &&
+                   strncmp(spec_arr[i].property_key, key,

property_key_len - 1) == 0) {

Quoted 3 lines

libselinux/src/label_backends_android.c static struct selabel_lookup_rec *property_lookup(struct selabel_handle *rec,

Quoted 3 lines
libselinux/src/label_backends_android.c +3 -0
+                       break;
+               }
+               if (strncmp(spec_arr[i].property_key, key,

property_key_len) == 0) {

Quoted 8 lines
Quoted 7 lines
libselinux/src/label_backends_android.c +0 -1
                        break;
                }
                if (strncmp(spec_arr[i].property_key, "*", 1) == 0)
--

2.15.0.rc0.271.g36b669edcc-goog

Quoted 5 lines

--
Respectfully,

William C Roberts

--
Jaekyun Seok | Software Engineer | [email protected] | +82 2 531 9235 <+82%202-531-9235>

Signature · 1 line
Jaekyun Seok | Software Engineer | [email protected] | +82 2 531 9235