Skip to contentSkip to conversation

checkpolicy: fix operator precedence in flavor check

PATCH In review Stephen Smalley 2 participants 3 messages Aug 25 – Aug 26 SELinux security module

lore
Share & tools
lore

Stephen Smalley

author maintainer
#0 lore raw

PATCH 1/1 checkpolicy: fix operator precedence in flavor check

get_local_type() and get_local_role() intend to reject an existing symbol whose flavor disagrees with the caller's isattr, but:

     if (dest->flavor != isattr ? TYPE_ATTRIB : TYPE_TYPE)
parses as:
     if ((dest->flavor != isattr) ? TYPE_ATTRIB : TYPE_TYPE)

since != takes precedence over ?:. This happens to be equivalent to the intended check today becase TYPE_TYPE is 0 and TYPE_ATTRIB is 1, matching the isattr values, and TYPE_ALIAS is rejected either way. Add the parentheses so that the code reads as intended and stays correct if the constants ever change.

No functional change.

---
 checkpolicy/module_compiler.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
checkpolicy/module_compiler.c +4 -2
index d59e493e..07f2b3bd 100644
@@ -636,7 +636,8 @@ type_datum_t *get_local_type(char *id, uint32_t value, unsigned char isattr)
 
 	} else {
 		free(id);
-		if (dest_typdatum->flavor != isattr ? TYPE_ATTRIB : TYPE_TYPE) {
+		if (dest_typdatum->flavor !=
+		    (isattr ? TYPE_ATTRIB : TYPE_TYPE)) {
 			return NULL;
 		}
 	}
@@ -685,7 +686,8 @@ role_datum_t *get_local_role(char *id, uint32_t value, unsigned char isattr)
 		}
 	} else {
 		free(id);
-		if (dest_roledatum->flavor != isattr ? ROLE_ATTRIB : ROLE_ROLE)
+		if (dest_roledatum->flavor !=
+		    (isattr ? ROLE_ATTRIB : ROLE_ROLE))
 			return NULL;
 	}
 
Signature · 1 line
2.55.0
Acked-by on v1 1/1
#1 lore raw
Quoted 12 lines · Stephen Smalley

get_local_type() and get_local_role() intend to reject an existing symbol whose flavor disagrees with the caller's isattr, but:

     if (dest->flavor != isattr ? TYPE_ATTRIB : TYPE_TYPE)
parses as:
     if ((dest->flavor != isattr) ? TYPE_ATTRIB : TYPE_TYPE)

since != takes precedence over ?:. This happens to be equivalent to the intended check today becase TYPE_TYPE is 0 and TYPE_ATTRIB is 1, matching the isattr values, and TYPE_ALIAS is rejected either way. Add the parentheses so that the code reads as intended and stays correct if the constants ever change.

Quoted 3 lines

No functional change.

Quoted 31 lines
---
 checkpolicy/module_compiler.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
checkpolicy/module_compiler.c +4 -3
index d59e493e..07f2b3bd 100644
@@ -636,7 +636,8 @@ type_datum_t *get_local_type(char *id, uint32_t value, unsigned char isattr)
 
        } else {
                free(id);
-               if (dest_typdatum->flavor != isattr ? TYPE_ATTRIB : TYPE_TYPE) {
+               if (dest_typdatum->flavor !=
+                   (isattr ? TYPE_ATTRIB : TYPE_TYPE)) {
                        return NULL;
                }
        }
@@ -685,7 +686,8 @@ role_datum_t *get_local_role(char *id, uint32_t value, unsigned char isattr)
                }
        } else {
                free(id);
-               if (dest_roledatum->flavor != isattr ? ROLE_ATTRIB : ROLE_ROLE)
+               if (dest_roledatum->flavor !=
+                   (isattr ? ROLE_ATTRIB : ROLE_ROLE))
                        return NULL;
        }
 
--

2.55.0

author maintainer
#2 lore raw
Quoted 15 lines · James Carter
Quoted 12 lines · Stephen Smalley

get_local_type() and get_local_role() intend to reject an existing symbol whose flavor disagrees with the caller's isattr, but:

     if (dest->flavor != isattr ? TYPE_ATTRIB : TYPE_TYPE)
parses as:
     if ((dest->flavor != isattr) ? TYPE_ATTRIB : TYPE_TYPE)

since != takes precedence over ?:. This happens to be equivalent to the intended check today becase TYPE_TYPE is 0 and TYPE_ATTRIB is 1, matching the isattr values, and TYPE_ALIAS is rejected either way. Add the parentheses so that the code reads as intended and stays correct if the constants ever change.

Quoted 5 lines
Quoted 3 lines

No functional change.

Thanks, merged.