libsepol: Check all the permissions in sepol_check_access()
PATCH v2 1/1 libsepol: Check all the permissions in sepol_check_access()
The program sepol_check_access() takes five arguments: a path to a policy, a source context string, a target context string, a security class string, and a comma-separated list of permissions. It calls functions to turn all the strings into values that can be passed to sepol_compute_av_reason_buffer(). Unfortunately, as each permission in the permission list is converted to an access vector, the previous access vector value is overwritten, so only the last permission is used in the access check.
Use a temporary access vector when converting each permission string to an access vector and "or" it to the final access vector before processing the next permission string.
---
v2: Fix commit message based on Stephen's suggestions
libsepol/utils/sepol_check_access.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
libsepol/utils/sepol_check_access.c +5 -2
@@ -12,7 +12,7 @@ int main(int argc, char *argv[])sepol_security_id_t ssid, tsid;sepol_security_class_t tclass;const char *permlist; -sepol_access_vector_t av; +sepol_access_vector_t av =0 ;struct sepol_av_decision avd;unsigned int reason;char *reason_buf;
@@ -58,6 +58,7 @@ int main(int argc, char *argv[])char *tmp =NULL ;const char *perm;const char *delim =strchr (permlist,',' ); +sepol_access_vector_t perm_av;if (delim) { tmp =strndup (permlist, delim - permlist);
@@ -71,7 +72,7 @@ int main(int argc, char *argv[]) perm = tmp ? tmp : permlist; -if (sepol_string_to_av_perm (tclass, perm, &av) <0 ) { +if (sepol_string_to_av_perm (tclass, perm, &perm_av) <0 ) {fprintf (stderr,"Invalid permission %s for security class %s: %s\n" , perm, argv[4 ],strerror (errno));
@@ -79,6 +80,8 @@ int main(int argc, char *argv[])return 1 ; } + av |= perm_av; +free (tmp); permlist =strchr (permlist,',' );
Signature · 1 line
2.55.0
Stephen Smalley
maintainerQuoted 2 lines · James Carter
The program
sepol_check_access()takes five arguments: a path to
Can fix on merge but both on the line above and the subject line it still has () as if it was a function whereas it is a program/utility.
Quoted 62 lines
a policy, a source context string, a target context string, a security class string, and a comma-separated list of permissions. It calls functions to turn all the strings into values that can be passed to
sepol_compute_av_reason_buffer(). Unfortunately, as each permission in the permission list is converted to an access vector, the previous access vector value is overwritten, so only the last permission is used in the access check.Use a temporary access vector when converting each permission string to an access vector and "or" it to the final access vector before processing the next permission string.
Signed-off-by James Carter <[email protected]>Acked-by Stephen Smalley <[email protected]>---
v2: Fix commit message based on Stephen's suggestionslibsepol/utils/sepol_check_access.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)libsepol/utils/sepol_check_access.c +5
-3@@ -12,7 +12,7 @@ int main(int argc, char *argv[])sepol_security_id_t ssid, tsid;sepol_security_class_t tclass;const char *permlist; -sepol_access_vector_t av; +sepol_access_vector_t av =0 ;struct sepol_av_decision avd;unsigned int reason;char *reason_buf;@@ -58,6 +58,7 @@ int main(int argc, char *argv[])char *tmp =NULL ;const char *perm;const char *delim =strchr (permlist,',' ); +sepol_access_vector_t perm_av;if (delim) { tmp =strndup (permlist, delim - permlist);@@ -71,7 +72,7 @@ int main(int argc, char *argv[]) perm = tmp ? tmp : permlist; -if (sepol_string_to_av_perm (tclass, perm, &av) <0 ) { +if (sepol_string_to_av_perm (tclass, perm, &perm_av) <0 ) {fprintf (stderr,"Invalid permission %s for security class %s: %s\n" , perm, argv[4 ],strerror (errno));@@ -79,6 +80,8 @@ int main(int argc, char *argv[])return 1 ; } + av |= perm_av; +free (tmp); permlist =strchr (permlist,',' ); --2.55.0
Quoted 8 lines · Stephen Smalley
Quoted 2 lines · James Carter
The program
sepol_check_access()takes five arguments: a path toCan fix on merge but both on the line above and the subject line it still has () as if it was a function whereas it is a program/utility.
Merged with fixed (again) commit message.
Thanks,
Jim
Quoted 62 lines
Quoted 62 lines
a policy, a source context string, a target context string, a security class string, and a comma-separated list of permissions. It calls functions to turn all the strings into values that can be passed to
sepol_compute_av_reason_buffer(). Unfortunately, as each permission in the permission list is converted to an access vector, the previous access vector value is overwritten, so only the last permission is used in the access check.Use a temporary access vector when converting each permission string to an access vector and "or" it to the final access vector before processing the next permission string.
Signed-off-by James Carter <[email protected]>Acked-by Stephen Smalley <[email protected]>---
v2: Fix commit message based on Stephen's suggestionslibsepol/utils/sepol_check_access.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)libsepol/utils/sepol_check_access.c +5
-3@@ -12,7 +12,7 @@ int main(int argc, char *argv[])sepol_security_id_t ssid, tsid;sepol_security_class_t tclass;const char *permlist; -sepol_access_vector_t av; +sepol_access_vector_t av =0 ;struct sepol_av_decision avd;unsigned int reason;char *reason_buf;@@ -58,6 +58,7 @@ int main(int argc, char *argv[])char *tmp =NULL ;const char *perm;const char *delim =strchr (permlist,',' ); +sepol_access_vector_t perm_av;if (delim) { tmp =strndup (permlist, delim - permlist);@@ -71,7 +72,7 @@ int main(int argc, char *argv[]) perm = tmp ? tmp : permlist; -if (sepol_string_to_av_perm (tclass, perm, &av) <0 ) { +if (sepol_string_to_av_perm (tclass, perm, &perm_av) <0 ) {fprintf (stderr,"Invalid permission %s for security class %s: %s\n" , perm, argv[4 ],strerror (errno));@@ -79,6 +80,8 @@ int main(int argc, char *argv[])return 1 ; } + av |= perm_av; +free (tmp); permlist =strchr (permlist,',' ); --2.55.0