libsepol: fix checkpolicy dontaudit compiler bug
PATCH v2 1/1 libsepol: fix checkpolicy dontaudit compiler bug
From: William Roberts <[email protected]>
The combining logic for dontaudit rules was wrong, causing a dontaudit A B:C *; rule to be clobbered by a dontaudit A B:C p; rule.
This is a reimplimation of 6201bb5e2 that avoids the cumbersome pointer assignments on alloced.
--- libsepol/src/expand.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-)
libsepol/src/expand.c +20 -7
@@ -1604,7 +1604,8 @@ static int expand_range_trans(expand_state_t * state,static avtab_ptr_t find_avtab_node (sepol_handle_t * handle,avtab_t * avtab,avtab_key_t * key,cond_av_list_t ** cond, -av_extended_perms_t *xperms) +av_extended_perms_t *xperms, +uint32_t init_data) {avtab_ptr_t node;avtab_datum_t avdatum;
@@ -1640,6 +1641,7 @@ static avtab_ptr_t find_avtab_node(sepol_handle_t * handle,if (!node) {memset (&avdatum,0 ,sizeof avdatum); + avdatum.data = init_data;/* this is used to get the node - insertion is actually unique */ node =avtab_insert_nonunique (avtab, key, &avdatum);if (!node) {
@@ -1663,6 +1665,17 @@ static avtab_ptr_t find_avtab_node(sepol_handle_t * handle,return node; } +static inline uint32_t specified_to_init_value (uint32_t specified) +{ +/* +* Things that get &= start life with values as ~0 and get unset as +* they continue life. +* Things that are |=, start as 0. +*/ +return (specified &AVRULE_DONTAUDIT ) + || (specified &AVRULE_AUDITDENY ) ? ~0 :0 ; +} +#define EXPAND_RULE_SUCCESS 1#define EXPAND_RULE_CONFLICT 0#define EXPAND_RULE_ERROR -1
@@ -1750,7 +1763,8 @@ static int expand_terule_helper(sepol_handle_t * handle,return EXPAND_RULE_CONFLICT ; } - node =find_avtab_node (handle, avtab, &avkey, cond,NULL ); + node =find_avtab_node (handle, avtab, &avkey, cond,NULL , +specified_to_init_value (specified));if (!node)return -1 ;if (enabled) {
@@ -1824,7 +1838,9 @@ static int expand_avrule_helper(sepol_handle_t * handle, avkey.target_class = cur->tclass; avkey.specified = spec; - node =find_avtab_node (handle, avtab, &avkey, cond, extended_perms); + node =find_avtab_node (handle, avtab, &avkey, cond, + extended_perms, +specified_to_init_value (specified));if (!node)return EXPAND_RULE_ERROR ;if (enabled) {
@@ -1850,10 +1866,7 @@ static int expand_avrule_helper(sepol_handle_t * handle,*/ avdatump->data &= cur->data; }else if (specified &AVRULE_DONTAUDIT ) { -if (avdatump->data) - avdatump->data &= ~cur->data; -else - avdatump->data = ~cur->data; + avdatump->data &= ~cur->data; }else if (specified &AVRULE_XPERMS ) { xperms = avdatump->xperms;if (!xperms) {
Signature · 1 line
2.7.4
Quoted 8 lines · On 11/15/2016 04:06 PM, [email protected] wrote:
From: William Roberts <[email protected]>
The combining logic for dontaudit rules was wrong, causing a dontaudit A B:C *; rule to be clobbered by a dontaudit A B:C p; rule.
This is a reimplimation of
6201bb5e2that avoids the cumbersome pointer assignments on alloced.
s/reimplimation/reimplementation/
s/6201bb5e2/commit 6201bb5e258e2b5bcc04d502d6fbc05c69d21d71 ("libsepol:
fix checkpolicy dontaudit compiler bug")/
Quoted 32 lines
Reported-by Nick Kralevich <[email protected]>Signed-off-by William Roberts <[email protected]>--- libsepol/src/expand.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-)libsepol/src/expand.c +3
-1@@ -1604,7 +1604,8 @@ static int expand_range_trans(expand_state_t * state,static avtab_ptr_t find_avtab_node (sepol_handle_t * handle,avtab_t * avtab,avtab_key_t * key,cond_av_list_t ** cond, -av_extended_perms_t *xperms) +av_extended_perms_t *xperms, +uint32_t init_data) {avtab_ptr_t node;avtab_datum_t avdatum;@@ -1640,6 +1641,7 @@ static avtab_ptr_t find_avtab_node(sepol_handle_t * handle,if (!node) {memset (&avdatum,0 ,sizeof avdatum); + avdatum.data = init_data;/* this is used to get the node - insertion is actually unique */ node =avtab_insert_nonunique (avtab, key, &avdatum);if (!node) {@@ -1663,6 +1665,17 @@ static avtab_ptr_t find_avtab_node(sepol_handle_t * handle,return node; }
libsepol/src/expand.c static avtab_ptr_t find_avtab_node(sepol_handle_t * handle, · line 1676
Quoted 10 lines
libsepol/src/expand.c +9
-0+static inline uint32_t specified_to_init_value (uint32_t specified) +{ +/* +* Things that get &= start life with values as ~0 and get unset as +* they continue life. +* Things that are |=, start as 0. +*/ +return (specified &AVRULE_DONTAUDIT ) + || (specified &AVRULE_AUDITDENY ) ? ~0 :0 ;
This can be simpler, e.g. (specified & (AVRULE_DONTAUDIT|AVRULE_AUDITDENY)). In fact, you can do one better by passing spec rather than specified in which case it is just (spec == AVTAB_AUDITDENY) since they are both converted to auditdeny vectors in the avtab.
libsepol/src/expand.c static int expand_terule_helper(sepol_handle_t * handle, · line 1767
Quoted 12 lines
libsepol/src/expand.c +4
-1+} +#define EXPAND_RULE_SUCCESS 1#define EXPAND_RULE_CONFLICT 0#define EXPAND_RULE_ERROR -1@@ -1750,7 +1763,8 @@ static int expand_terule_helper(sepol_handle_t * handle,return EXPAND_RULE_CONFLICT ; } - node =find_avtab_node (handle, avtab, &avkey, cond,NULL ); + node =find_avtab_node (handle, avtab, &avkey, cond,NULL , +specified_to_init_value (specified));
This one should always be 0, since the datum is a type value, not an access vector.
Quoted 27 lines
libsepol/src/expand.c +4
-5if (!node)return -1 ;if (enabled) {@@ -1824,7 +1838,9 @@ static int expand_avrule_helper(sepol_handle_t * handle, avkey.target_class = cur->tclass; avkey.specified = spec; - node =find_avtab_node (handle, avtab, &avkey, cond, extended_perms); + node =find_avtab_node (handle, avtab, &avkey, cond, + extended_perms, +specified_to_init_value (specified));if (!node)return EXPAND_RULE_ERROR ;if (enabled) {@@ -1850,10 +1866,7 @@ static int expand_avrule_helper(sepol_handle_t * handle,*/ avdatump->data &= cur->data; }else if (specified &AVRULE_DONTAUDIT ) { -if (avdatump->data) - avdatump->data &= ~cur->data; -else - avdatump->data = ~cur->data; + avdatump->data &= ~cur->data; }else if (specified &AVRULE_XPERMS ) { xperms = avdatump->xperms;if (!xperms) {
Quoted 47 lines · Stephen Smalley
Quoted 8 lines · On 11/15/2016 04:06 PM, [email protected] wrote:
From: William Roberts <[email protected]>
The combining logic for dontaudit rules was wrong, causing a dontaudit A B:C *; rule to be clobbered by a dontaudit A B:C p; rule.
This is a reimplimation of
6201bb5e2that avoids the cumbersome pointer assignments on alloced.s/reimplimation/reimplementation/
s/6201bb5e2/commit6201bb5e258e2b5bcc04d502d6fbc05c69d21d71("libsepol:
fix checkpolicy dontaudit compiler bug")/Quoted 33 lines
Reported-by Nick Kralevich <[email protected]>Signed-off-by William Roberts <[email protected]>--- libsepol/src/expand.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-)libsepol/src/expand.c +3
-1@@ -1604,7 +1604,8 @@ static int expand_range_trans(expand_state_t * state,static avtab_ptr_t find_avtab_node (sepol_handle_t * handle,avtab_t * avtab,avtab_key_t * key,cond_av_list_t ** cond, -av_extended_perms_t *xperms) +av_extended_perms_t *xperms, +uint32_t init_data) {avtab_ptr_t node;avtab_datum_t avdatum;@@ -1640,6 +1641,7 @@ static avtab_ptr_t find_avtab_node(sepol_handle_t * handle,if (!node) {memset (&avdatum,0 ,sizeof avdatum); + avdatum.data = init_data;/* this is used to get the node - insertion is actually unique */ node =avtab_insert_nonunique (avtab, key, &avdatum);if (!node) {@@ -1663,6 +1665,17 @@ static avtab_ptr_t find_avtab_node(sepol_handle_t * handle,return node; }
Quoted 12 lines
libsepol/src/expand.c static avtab_ptr_t find_avtab_node(sepol_handle_t * handle, · line 1676
Quoted 9 lines
libsepol/src/expand.c +9
-0+static inline uint32_t specified_to_init_value (uint32_t specified) +{ +/* +* Things that get &= start life with values as ~0 and get unset as +* they continue life. +* Things that are |=, start as 0. +*/ +return (specified &AVRULE_DONTAUDIT ) + || (specified &AVRULE_AUDITDENY ) ? ~0 :0 ;This can be simpler, e.g. (specified &
(AVRULE_DONTAUDIT|AVRULE_AUDITDENY)).
True.
In fact, you can do one better by
Quoted 3 lines
passing spec rather than specified in which case it is just (spec ==
AVTAB_AUDITDENY) since they are both converted to auditdeny vectors in the avtab.
I didn't want to pollute the subroutine with knowledge of spec, but considering this is all
in one C file, I suppose it doesn't matter. I actually had that originally.
Quoted 10 lines
Quoted 10 lines
libsepol/src/expand.c +2
-0+} +#define EXPAND_RULE_SUCCESS 1#define EXPAND_RULE_CONFLICT 0#define EXPAND_RULE_ERROR -1@@ -1750,7 +1763,8 @@ static int expand_terule_helper(sepol_handle_t * handle,return EXPAND_RULE_CONFLICT ; }
Quoted 6 lines
libsepol/src/expand.c static int expand_terule_helper(sepol_handle_t * handle, · line 1767
Quoted 3 lines
libsepol/src/expand.c +2
-1- node =find_avtab_node (handle, avtab, &avkey, cond,NULL ); + node =find_avtab_node (handle, avtab, &avkey, cond,NULL , +specified_to_init_value (specified));This one should always be 0, since the datum is a type value, not an access vector.
Roger that.
Quoted 34 lines
Quoted 18 lines
libsepol/src/expand.c +3
-1if (!node)return -1 ;if (enabled) {@@ -1824,7 +1838,9 @@ static int expand_avrule_helper(sepol_handle_t * handle, avkey.target_class = cur->tclass; avkey.specified = spec; - node =find_avtab_node (handle, avtab, &avkey, cond, extended_perms); + node =find_avtab_node (handle, avtab, &avkey, cond, + extended_perms, +specified_to_init_value (specified));if (!node)return EXPAND_RULE_ERROR ;if (enabled) {@@ -1850,10 +1866,7 @@ static int expand_avrule_helper(sepol_handle_t * handle,*/ libsepol/src/expand.c static int expand_avrule_helper(sepol_handle_t * handle, · line 1872
Quoted 10 lines
libsepol/src/expand.c +1
-4avdatump->data &= cur->data; }else if (specified &AVRULE_DONTAUDIT ) { -if (avdatump->data) - avdatump->data &= ~cur->data; -else - avdatump->data = ~cur->data; + avdatump->data &= ~cur->data; }else if (specified &AVRULE_XPERMS ) { xperms = avdatump->xperms;if (!xperms) {_______________________________________________
Selinux mailing list
[email protected]
To unsubscribe, send email to [email protected].
To get help, send an email containing "help" to [email protected].
Signature · 3 lines
Respectfully, William C Roberts