Modify audit2why analyze function to use loaded policy
PATCH 1/2 Modify audit2why analyze function to use loaded policy
Class and perms should come from the policy being used for analysis, not the system policy so use sepol_ interfaces
--- libselinux/src/audit2why.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
libselinux/src/audit2why.c +4 -4
@@ -343,8 +343,8 @@ static PyObject *analyze(PyObject *self __attribute__((unused)) , PyObject *argsif (rc <0 )RETURN (BADTCON ) - tclass = string_to_security_class(tclassstr); -if (!tclass) + rc = sepol_string_to_security_class(tclassstr, &tclass); +if (rc <0 )RETURN (BADTCLASS )/* Convert the permission list to an AV. */
@@ -365,8 +365,8 @@ static PyObject *analyze(PyObject *self __attribute__((unused)) , PyObject *args permstr =PyString_AsString ( strObj );#endif - perm =string_to_av_perm (tclass, permstr); -if (!perm) + rc =sepol_string_to_av_perm (tclass, permstr, &perm); +if (rc <0 )RETURN (BADPERM ) av |= perm;
Signature · 1 line
2.1.0
PATCH 2/2 Correctly detect unknown classes in sepol_string_to_security_class
Bail before running off the end of the class index
--- libsepol/src/services.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
libsepol/src/services.c +3 -1
@@ -1155,7 +1155,7 @@ int hidden sepol_string_to_security_class(const char *class_name,char *class =NULL ;sepol_security_class_t id; -for (id =1 ;; id++) { +for (id =1 ; id < policydb->p_classes.nprim; id++) { class = policydb->p_class_val_to_name[id -1 ];if (class ==NULL ) {ERR (NULL ,"could not convert %s to class id" , class_name);
@@ -1166,6 +1166,8 @@ int hidden sepol_string_to_security_class(const char *class_name,return STATUS_SUCCESS ; } } +ERR (NULL ,"unrecognized class %s" , class_name); +return -EINVAL ; }/*
Signature · 1 line
2.1.0
PATCH 1/1 Correctly detect unknown classes in sepol_string_to_security_class
Bail before running off the end of the class index
--- libsepol/src/services.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
libsepol/src/services.c +3 -1
@@ -1155,7 +1155,7 @@ int hidden sepol_string_to_security_class(const char *class_name,char *class =NULL ;sepol_security_class_t id; -for (id =1 ;; id++) { +for (id =1 ; id <= policydb->p_classes.nprim; id++) { class = policydb->p_class_val_to_name[id -1 ];if (class ==NULL ) {ERR (NULL ,"could not convert %s to class id" , class_name);
@@ -1166,6 +1166,8 @@ int hidden sepol_string_to_security_class(const char *class_name,return STATUS_SUCCESS ; } } +ERR (NULL ,"unrecognized class %s" , class_name); +return -EINVAL ; }/*
Signature · 1 line
2.1.0
Re: [PATCH] Correctly detect unknown classes in sepol_string_to_security_class
Quoted 2 lines · Joshua Brindle
Bail before running off the end of the class index
This one correctly goes all the way to the end of the classes index, the last version did not.
Quoted 28 lines
Change-Id I47c4eaac3c7d789f8d85047e34e37e3f0bb38b3aSigned-off-by Joshua Brindle<[email protected]>--- libsepol/src/services.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)libsepol/src/services.c +3
-1@@ -1155,7 +1155,7 @@ int hidden sepol_string_to_security_class(const char *class_name,char *class =NULL ;sepol_security_class_t id; -for (id =1 ;; id++) { +for (id =1 ; id<= policydb->p_classes.nprim; id++) { class = policydb->p_class_val_to_name[id -1 ];if (class ==NULL ) {ERR (NULL ,"could not convert %s to class id" , class_name);@@ -1166,6 +1166,8 @@ int hidden sepol_string_to_security_class(const char *class_name,return STATUS_SUCCESS ; } } +ERR (NULL ,"unrecognized class %s" , class_name); +return -EINVAL ; }/*
Stephen Smalley
AppliedRe: [PATCH] Correctly detect unknown classes in sepol_string_to_security_class
In reply to Joshua BrindleQuoted 4 lines · Joshua Brindle
Bail before running off the end of the class index
Change-Id I47c4eaac3c7d789f8d85047e34e37e3f0bb38b3aSigned-off-by Joshua Brindle <[email protected]>
Applied this one and then rewrote it to use hashtab_search(). Not sure why it wasn't that way in the first place.
Quoted 27 lines
--- libsepol/src/services.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)libsepol/src/services.c +3
-1@@ -1155,7 +1155,7 @@ int hidden sepol_string_to_security_class(const char *class_name,char *class =NULL ;sepol_security_class_t id; -for (id =1 ;; id++) { +for (id =1 ; id <= policydb->p_classes.nprim; id++) { class = policydb->p_class_val_to_name[id -1 ];if (class ==NULL ) {ERR (NULL ,"could not convert %s to class id" , class_name);@@ -1166,6 +1166,8 @@ int hidden sepol_string_to_security_class(const char *class_name,return STATUS_SUCCESS ; } } +ERR (NULL ,"unrecognized class %s" , class_name); +return -EINVAL ; }/*
Re: [PATCH] Correctly detect unknown classes in sepol_string_to_security_class
Quoted 8 lines · Stephen Smalley
Quoted 4 lines · Joshua Brindle
Bail before running off the end of the class index
Change-Id I47c4eaac3c7d789f8d85047e34e37e3f0bb38b3aSigned-off-by Joshua Brindle<[email protected]>Applied this one and then rewrote it to use
hashtab_search(). Not sure why it wasn't that way in the first place.
Thank you, that was a much better fix that I should have noticed...
Quoted 29 lines
Quoted 28 lines
--- libsepol/src/services.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)libsepol/src/services.c +3
-1@@ -1155,7 +1155,7 @@ int hidden sepol_string_to_security_class(const char *class_name,char *class =NULL ;sepol_security_class_t id; -for (id =1 ;; id++) { +for (id =1 ; id<= policydb->p_classes.nprim; id++) { class = policydb->p_class_val_to_name[id -1 ];if (class ==NULL ) {ERR (NULL ,"could not convert %s to class id" , class_name);@@ -1166,6 +1166,8 @@ int hidden sepol_string_to_security_class(const char *class_name,return STATUS_SUCCESS ; } } +ERR (NULL ,"unrecognized class %s" , class_name); +return -EINVAL ; }/*
Stephen Smalley
AppliedQuoted 8 lines · Joshua Brindle
Class and perms should come from the policy being used for analysis, not the system policy so use
sepol_interfacesChange-Id Ia0590ed2514249fd98810a8d4fe87f8bf5280561Signed-off-by Joshua Brindle <[email protected]>--- libselinux/src/audit2why.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
Thanks, applied.
Quoted 28 lines
libselinux/src/audit2why.c +4
-4@@ -343,8 +343,8 @@ static PyObject *analyze(PyObject *self __attribute__((unused)) , PyObject *argsif (rc <0 )RETURN (BADTCON ) - tclass = string_to_security_class(tclassstr); -if (!tclass) + rc = sepol_string_to_security_class(tclassstr, &tclass); +if (rc <0 )RETURN (BADTCLASS )/* Convert the permission list to an AV. */ @@ -365,8 +365,8 @@ static PyObject *analyze(PyObject *self __attribute__((unused)) , PyObject *args permstr =PyString_AsString ( strObj );#endif - perm =string_to_av_perm (tclass, permstr); -if (!perm) + rc =sepol_string_to_av_perm (tclass, permstr, &perm); +if (rc <0 )RETURN (BADPERM ) av |= perm;