libsepol: fix checkpolicy dontaudit compiler bug
In continuing the recent discussions on the topics:
- [PATCH] libsepol: fix checkpolicy dontaudit compiler bug
- checkpolicy dontaudit compiler bug?
This is my proposed solution to the problem that avoids the return via-pointer alloced approach.
Unfortunatly the proposed clear than set approach for bitsetting won't work here, becuase the initial set off of cur->data is required as noted by Stepehen's original patch.
ie a modification of this logic wont work:
void setbit(u32 *data, u32 value, u32 position) {
*data = ((*data) & ~(1<<position)) | (value & 0x1 << position);
}Quoted 1 line
From current master, with the old fix applied, and the new fix, the
output from sesearch will always yield the same hash:
$ sesearch --dontaudit -s su -c capability,capability2 ~/tmp/bullhead.policy | md5sum ba1c1e09b910127daeb474d641265950 -
$ sesearch --dontaudit -s su -c capability,capability2 ~/tmp/marlin.policy | md5sum ba1c1e09b910127daeb474d641265950 -
[PATCH 1/2] Revert "libsepol: fix checkpolicy dontaudit compiler bug" [PATCH 2/2] libsepol: fix checkpolicy dontaudit compiler bug
PATCH 1/2 Revert "libsepol: fix checkpolicy dontaudit compiler bug"
From: William Roberts <[email protected]>
This reverts commit 6201bb5e258e2b5bcc04d502d6fbc05c69d21d71.
--- libsepol/src/expand.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)
libsepol/src/expand.c +4 -12
@@ -1604,8 +1604,7 @@ 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, -char *alloced) +av_extended_perms_t *xperms) {avtab_ptr_t node;avtab_datum_t avdatum;
@@ -1659,11 +1658,6 @@ static avtab_ptr_t find_avtab_node(sepol_handle_t * handle, nl->next = *cond; *cond = nl; } -if (alloced) - *alloced =1 ; - }else { -if (alloced) - *alloced =0 ; }return node;
@@ -1756,7 +1750,7 @@ static int expand_terule_helper(sepol_handle_t * handle,return EXPAND_RULE_CONFLICT ; } - node =find_avtab_node (handle, avtab, &avkey, cond,NULL ,NULL ); + node =find_avtab_node (handle, avtab, &avkey, cond,NULL );if (!node)return -1 ;if (enabled) {
@@ -1796,7 +1790,6 @@ static int expand_avrule_helper(sepol_handle_t * handle,class_perm_node_t *cur;uint32_t spec =0 ;unsigned int i; -char alloced;if (specified &AVRULE_ALLOWED ) { spec =AVTAB_ALLOWED ;
@@ -1831,8 +1824,7 @@ 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, &alloced); + node =find_avtab_node (handle, avtab, &avkey, cond, extended_perms);if (!node)return EXPAND_RULE_ERROR ;if (enabled) {
@@ -1858,7 +1850,7 @@ static int expand_avrule_helper(sepol_handle_t * handle,*/ avdatump->data &= cur->data; }else if (specified &AVRULE_DONTAUDIT ) { -if (!alloced) +if (avdatump->data) avdatump->data &= ~cur->data;else avdatump->data = ~cur->data;
Signature · 1 line
2.7.4
PATCH 2/2 libsepol: fix checkpolicy dontaudit compiler bug
In reply to [email protected]From: Stephen Smalley <[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 | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
libsepol/src/expand.c +14 -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) {
@@ -1750,7 +1752,7 @@ 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 ,0 );if (!node)return -1 ;if (enabled) {
@@ -1824,7 +1826,15 @@ 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, +/* +* dontaudit rules need to be +* initialized on creation, others can +* be 0. +*/ + specified &AVRULE_DONTAUDIT + ? ~cur->data :0 );if (!node)return EXPAND_RULE_ERROR ;if (enabled) {
@@ -1850,10 +1860,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 50 lines · On 11/15/2016 02:40 PM, [email protected] wrote:
From: Stephen Smalley <[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.Reported-by Nick Kralevich <[email protected]>Signed-off-by William Roberts <[email protected]>--- libsepol/src/expand.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)libsepol/src/expand.c +4
-2@@ -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) {@@ -1750,7 +1752,7 @@ 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 ,0 );if (!node)return -1 ;if (enabled) {@@ -1824,7 +1826,15 @@ static int expand_avrule_helper(sepol_handle_t * handle, avkey.target_class = cur->tclass; avkey.specified = spec;
libsepol/src/expand.c static int expand_avrule_helper(sepol_handle_t * handle, · line 1837
Quoted 10 lines
libsepol/src/expand.c +9
-1- node =find_avtab_node (handle, avtab, &avkey, cond, extended_perms); + node =find_avtab_node (handle, avtab, &avkey, cond, + extended_perms, +/* +* dontaudit rules need to be +* initialized on creation, others can +* be 0. +*/ + specified &AVRULE_DONTAUDIT + ? ~cur->data :0 );
There seems to be a lack of symmetry here. Either we should initialize them all to the proper value (including AUDITDENY, which I think might be broken too, although no one uses it anymore since the transition to DONTAUDIT), or we should initialize the ones that are ORed to 0 and the ones that are ANDed to ~0 and then let the subsequent OR'ing or AND'ing adjust appropriately.
Quoted 16 lines
libsepol/src/expand.c +1
-4if (!node)return EXPAND_RULE_ERROR ;if (enabled) {@@ -1850,10 +1860,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 2 lines · Stephen Smalley
Quoted 1 line · On 11/15/2016 02:40 PM, [email protected] wrote:
From: Stephen Smalley <[email protected]>
Also, you don't have to keep me as the author as the patch is a rewrite after a revert.
Quoted 7 lines
Quoted 7 lines
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/6201bb532/commit 6201bb5e258e2b5bcc04d502d6fbc05c69d21d71 ("libsepol:
fix checkpolicy dontaudit compiler bug")/
Quoted 77 lines
Quoted 42 lines
Reported-by Nick Kralevich <[email protected]>Signed-off-by William Roberts <[email protected]>--- libsepol/src/expand.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)libsepol/src/expand.c +4
-2@@ -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) {@@ -1750,7 +1752,7 @@ 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 ,0 );if (!node)return -1 ;if (enabled) {@@ -1824,7 +1826,15 @@ static int expand_avrule_helper(sepol_handle_t * handle, avkey.target_class = cur->tclass; avkey.specified = spec;libsepol/src/expand.c static int expand_avrule_helper(sepol_handle_t * handle, · line 1837
Quoted 10 lines
libsepol/src/expand.c +9
-1- node =find_avtab_node (handle, avtab, &avkey, cond, extended_perms); + node =find_avtab_node (handle, avtab, &avkey, cond, + extended_perms, +/* +* dontaudit rules need to be +* initialized on creation, others can +* be 0. +*/ + specified &AVRULE_DONTAUDIT + ? ~cur->data :0 );There seems to be a lack of symmetry here. Either we should initialize them all to the proper value (including AUDITDENY, which I think might be broken too, although no one uses it anymore since the transition to DONTAUDIT), or we should initialize the ones that are ORed to 0 and the ones that are ANDed to ~0 and then let the subsequent OR'ing or AND'ing adjust appropriately.
Quoted 16 lines
libsepol/src/expand.c +1
-4if (!node)return EXPAND_RULE_ERROR ;if (enabled) {@@ -1850,10 +1860,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 7 lines · Stephen Smalley
Quoted 2 lines · Stephen Smalley
Quoted 1 line · On 11/15/2016 02:40 PM, [email protected] wrote:
From: Stephen Smalley <[email protected]>
Also, you don't have to keep me as the author as the patch is a rewrite after a revert.
I didn't realize -C kept the author on git commit.
Quoted 20 lines
Quoted 8 lines
Quoted 8 lines
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/6201bb532/commit6201bb5e258e2b5bcc04d502d6fbc05c69d21d71("libsepol:
fix checkpolicy dontaudit compiler bug")/Quoted 7 lines
Quoted 7 lines
Reported-by Nick Kralevich <[email protected]>Signed-off-by William Roberts <[email protected]>--- libsepol/src/expand.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
Quoted 5 lines
Quoted 5 lines
libsepol/src/expand.c static int expand_range_trans(expand_state_t *
Quoted 5 lines
libsepol/src/expand.c +0
-0@@ -1604,7 +1604,8 @@ static int expand_range_trans(expand_state_t *
state,
Quoted 10 lines
Quoted 10 lines
libsepol/src/expand.c static avtab_ptr_t
Quoted 10 lines
libsepol/src/expand.c +2
-1static 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,
Quoted 5 lines
Quoted 5 lines
libsepol/src/expand.c static avtab_ptr_t find_avtab_node(sepol_handle_t * handle,
Quoted 5 lines
libsepol/src/expand.c +1
-0if (!node) {memset (&avdatum,0 ,sizeof avdatum); + avdatum.data = init_data;/* this is used to get the node - insertion is actually
unique */
Quoted 3 lines
Quoted 3 lines
libsepol/src/expand.c static int expand_terule_helper(sepol_handle_t *
Quoted 3 lines
libsepol/src/expand.c +0
-0node =avtab_insert_nonunique (avtab, key, &avdatum);if (!node) {@@ -1750,7 +1752,7 @@ static int expand_terule_helper(sepol_handle_t *
handle,
Quoted 5 lines
Quoted 5 lines
libsepol/src/expand.c static int expand_terule_helper(sepol_handle_t * handle,
Quoted 5 lines
libsepol/src/expand.c +1
-1return EXPAND_RULE_CONFLICT ; } - node =find_avtab_node (handle, avtab, &avkey, cond,NULL ); + node = find_avtab_node(handle, avtab, &avkey, cond, NULL,
0);
Quoted 4 lines
Quoted 4 lines
libsepol/src/expand.c static int expand_avrule_helper(sepol_handle_t
Quoted 4 lines
libsepol/src/expand.c +0
-0if (!node)return -1 ;if (enabled) {@@ -1824,7 +1826,15 @@ static int expand_avrule_helper(sepol_handle_t
* handle,
Quoted 4 lines
Quoted 4 lines
libsepol/src/expand.c static int expand_avrule_helper(sepol_handle_t * handle,
Quoted 4 lines
libsepol/src/expand.c +0
-1avkey.target_class = cur->tclass; avkey.specified = spec; - node = find_avtab_node(handle, avtab, &avkey, cond,
extended_perms);
Quoted 5 lines
Quoted 5 lines
libsepol/src/expand.c static int expand_avrule_helper(sepol_handle_t * handle,
Quoted 5 lines
libsepol/src/expand.c +5
-0+ node = find_avtab_node(handle, avtab, &avkey, cond, + extended_perms, +/* +* dontaudit rules need to be +* initialized on creation, others
can
Quoted 12 lines
Quoted 12 lines
libsepol/src/expand.c static int expand_avrule_helper(sepol_handle_t * handle, · line 1837
Quoted 4 lines
libsepol/src/expand.c +4
-0+* be 0. +*/ + specified &AVRULE_DONTAUDIT + ? ~cur->data : 0);There seems to be a lack of symmetry here. Either we should initialize them all to the proper value (including AUDITDENY, which I think might be broken too, although no one uses it anymore since the transition to DONTAUDIT), or we should initialize the ones that are ORed to 0 and the ones that are ANDed to ~0 and then let the subsequent OR'ing or AND'ing adjust appropriately.
Quoted 4 lines
Quoted 4 lines
libsepol/src/expand.c static int expand_avrule_helper(sepol_handle_t
Quoted 4 lines
libsepol/src/expand.c +0
-0if (!node)return EXPAND_RULE_ERROR ;if (enabled) {@@ -1850,10 +1860,7 @@ static int expand_avrule_helper(sepol_handle_t
* handle,
Quoted 14 lines
Quoted 4 lines
Quoted 4 lines
libsepol/src/expand.c +0
-1*/ avdatump->data &= cur->data; }else if (specified &AVRULE_DONTAUDIT ) { -if (avdatump->data)Quoted 9 lines
libsepol/src/expand.c static int expand_avrule_helper(sepol_handle_t * handle, · line 1866
Quoted 8 lines
libsepol/src/expand.c +1
-3- avdatump->data &= ~cur->data; - else - avdatump->data = ~cur->data; + avdatump->data &= ~cur->data; }else if (specified &AVRULE_XPERMS ) { xperms = avdatump->xperms;if (!xperms) {
Quoted 5 lines
_______________________________________________
Selinux mailing list
[email protected]
To unsubscribe, send email to [email protected]. To get help, send an email containing "help" to
Quoted 17 lines · Stephen Smalley
Quoted 15 lines · On 11/15/2016 02:40 PM, [email protected] wrote:
From: Stephen Smalley <[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.Reported-by Nick Kralevich <[email protected]>Signed-off-by William Roberts <[email protected]>--- libsepol/src/expand.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
Quoted 5 lines
libsepol/src/expand.c static int expand_range_trans(expand_state_t *
Quoted 5 lines
libsepol/src/expand.c +0
-0@@ -1604,7 +1604,8 @@ static int expand_range_trans(expand_state_t *
state,
Quoted 10 lines
libsepol/src/expand.c static avtab_ptr_t find_avtab_node(sepol_handle_t
Quoted 10 lines
libsepol/src/expand.c +2
-1static 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,
Quoted 5 lines
libsepol/src/expand.c static avtab_ptr_t find_avtab_node(sepol_handle_t * handle,
Quoted 5 lines
libsepol/src/expand.c +1
-0if (!node) {memset (&avdatum,0 ,sizeof avdatum); + avdatum.data = init_data;/* this is used to get the node - insertion is actually
unique */
Quoted 3 lines
libsepol/src/expand.c static int expand_terule_helper(sepol_handle_t *
Quoted 3 lines
libsepol/src/expand.c +0
-0node =avtab_insert_nonunique (avtab, key, &avdatum);if (!node) {@@ -1750,7 +1752,7 @@ static int expand_terule_helper(sepol_handle_t *
handle,
Quoted 5 lines
libsepol/src/expand.c static int expand_terule_helper(sepol_handle_t * handle,
Quoted 5 lines
libsepol/src/expand.c +1
-1return EXPAND_RULE_CONFLICT ; } - node =find_avtab_node (handle, avtab, &avkey, cond,NULL ); + node = find_avtab_node(handle, avtab, &avkey, cond, NULL,
0);
Quoted 4 lines
libsepol/src/expand.c static int expand_avrule_helper(sepol_handle_t *
Quoted 4 lines
libsepol/src/expand.c +0
-0if (!node)return -1 ;if (enabled) {@@ -1824,7 +1826,15 @@ static int expand_avrule_helper(sepol_handle_t *
handle,
Quoted 4 lines
libsepol/src/expand.c static int expand_avrule_helper(sepol_handle_t * handle,
Quoted 4 lines
libsepol/src/expand.c +0
-1avkey.target_class = cur->tclass; avkey.specified = spec; - node = find_avtab_node(handle, avtab, &avkey, cond,
extended_perms);
Quoted 5 lines
libsepol/src/expand.c static int expand_avrule_helper(sepol_handle_t * handle,
Quoted 5 lines
libsepol/src/expand.c +5
-0+ node = find_avtab_node(handle, avtab, &avkey, cond, + extended_perms, +/* +* dontaudit rules need to be +* initialized on creation, others
can
Quoted 11 lines
libsepol/src/expand.c static int expand_avrule_helper(sepol_handle_t * handle, · line 1837
Quoted 4 lines
libsepol/src/expand.c +4
-0+* be 0. +*/ + specified &AVRULE_DONTAUDIT + ? ~cur->data : 0);There seems to be a lack of symmetry here. Either we should initialize them all to the proper value (including AUDITDENY, which I think might be broken too, although no one uses it anymore since the transition to DONTAUDIT), or we should initialize the ones that are ORed to 0 and the ones that are ANDed to ~0 and then let the subsequent OR'ing or AND'ing adjust appropriately.
I noticed that and thought of doing that, so I'm OK with that. I'll send a v2.
Quoted 5 lines
libsepol/src/expand.c static int expand_avrule_helper(sepol_handle_t *
Quoted 5 lines
libsepol/src/expand.c +0
-0if (!node)return EXPAND_RULE_ERROR ;if (enabled) {@@ -1850,10 +1860,7 @@ static int expand_avrule_helper(sepol_handle_t *
handle,
Quoted 13 lines
libsepol/src/expand.c static int expand_avrule_helper(sepol_handle_t * handle, · line 1866
Quoted 12 lines
libsepol/src/expand.c +1
-4*/ 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 5 lines
_______________________________________________
Selinux mailing list
[email protected]
To unsubscribe, send email to [email protected]. To get help, send an email containing "help" to