sestatus: show checkreqprot status
cover sestatus: show checkreqprot status
v3:
improved man-page and sestatus output wording; thanks to Stephen
v2:
rename security_checkreqprot to security_get_checkreqprot add O_CLOEXEC open flag
improve man page description and fix wrong placement hopefully improve sestatus output readability
Christian Göttsche (2):
libselinux: add security_get_checkreqprot
sestatus: show checkreqprot status
libselinux/include/selinux/selinux.h | 3 +++ libselinux/man/man3/security_getenforce.3 | 11 ++++++++- libselinux/src/checkreqprot.c | 40 +++++++++++++++++++++++++++++++ libselinux/src/selinux_internal.h | 1 + policycoreutils/sestatus/sestatus.8 | 2 ++ policycoreutils/sestatus/sestatus.c | 14 +++++++++++ 6 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 libselinux/src/checkreqprot.c
Signature · 1 line
2.11.0
PATCH 1/2 libselinux: add security_get_checkreqprot
Add security_get_checkreqprot() function, returning the current active checkreqprot value
--- libselinux/include/selinux/selinux.h | 3 +++ libselinux/man/man3/security_getenforce.3 | 11 ++++++++- libselinux/src/checkreqprot.c | 40 +++++++++++++++++++++++++++++++ libselinux/src/selinux_internal.h | 1 + 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 libselinux/src/checkreqprot.c
libselinux/include/selinux/selinux.h +3 -0
@@ -331,6 +331,9 @@ extern int security_setenforce(int value);/* Get the behavior for undefined classes/permissions */ extern int security_deny_unknown (void ); +/* Get the checkreqprot value */ +extern int security_get_checkreqprot (void ); +/* Disable SELinux at runtime (must be done prior to initial policy load). */ extern int security_disable (void );
libselinux/man/man3/security_getenforce.3 +10 -1
@@ -1,6 +1,6 @@ .TH "security_getenforce" "3" "1 January 2004" "[email protected]" "SELinux API documentation" .SH "NAME" -security_getenforce, security_setenforce, security_deny_unknown \- get or set the enforcing state of SELinux +security_getenforce, security_setenforce, security_deny_unknown, security_get_checkreqprot\- get or set the enforcing state of SELinux . .SH "SYNOPSIS" .B #include <selinux/selinux.h>
@@ -10,6 +10,8 @@ security_getenforce, security_setenforce, security_deny_unknown \- get or set th .BI "int security_setenforce(int "value ); .sp .B int security_deny_unknown(void); +.sp +.B int security_get_checkreqprot(void); . .SH "DESCRIPTION" .BR security_getenforce ()
@@ -24,6 +26,13 @@ returned. .BR security_deny_unknown () returns 0 if SELinux treats policy queries on undefined object classes or permissions as being allowed, 1 if such queries are denied, and \-1 on error. + +.BR security_get_checkreqprot () +can be used to determine whether SELinux is configured to check the +protection requested by the application or the actual protection that will +be applied by the kernel (including the effects of READ_IMPLIES_EXEC) on +mmap and mprotect calls. It returns 0 if SELinux checks the actual +protection, 1 if it checks the requested protection, and \-1 on error. . .SH "SEE ALSO" .BR selinux "(8)"
libselinux/src/checkreqprot.c new file +40 -0
@@ -0,0 +1,40 @@ +#include <unistd.h> +#include <sys/types.h> +#include <fcntl.h> +#include <stdlib.h> +#include <errno.h> +#include <string.h> +#include "selinux_internal.h" +#include "policy.h" +#include <stdio.h> +#include <limits.h> + +int security_get_checkreqprot (void ) +{ +int fd, ret, checkreqprot =0 ; +char path[PATH_MAX ]; +char buf[20 ]; + +if (!selinux_mnt) { + errno =ENOENT ; +return -1 ; + } + +snprintf (path,sizeof (path),"%s/checkreqprot" , selinux_mnt); + fd =open (path,O_RDONLY |O_CLOEXEC ); +if (fd <0 ) +return -1 ; + +memset (buf,0 ,sizeof (buf)); + ret =read (fd, buf,sizeof (buf) -1 ); +close (fd); +if (ret <0 ) +return -1 ; + +if (sscanf (buf,"%d" , &checkreqprot) !=1 ) +return -1 ; + +return checkreqprot; +} + +hidden_def (security_get_checkreqprot);
libselinux/src/selinux_internal.h +1 -0
@@ -59,6 +59,7 @@ hidden_proto(selinux_mkload_policy) hidden_proto(security_getenforce) hidden_proto(security_setenforce) hidden_proto(security_deny_unknown) + hidden_proto(security_get_checkreqprot) hidden_proto(selinux_boolean_sub) hidden_proto(selinux_current_policy_path) hidden_proto(selinux_binary_policy_path)
Signature · 1 line
2.11.0
PATCH 2/2 sestatus: show checkreqprot status
In reply to Christian GöttscheShow the current active checkreqprot state in sestatus
--- policycoreutils/sestatus/sestatus.8 | 2 ++ policycoreutils/sestatus/sestatus.c | 14 ++++++++++++++ 2 files changed, 16 insertions(+)
policycoreutils/sestatus/sestatus.8 +2 -0
@@ -33,6 +33,8 @@ Policy MLS status: enabled .br Policy deny_unknown status: allow .br +Memory protection checking: actual (secure) +.br Max kernel policy version: 26 .RE .sp
policycoreutils/sestatus/sestatus.c +14 -0
@@ -330,6 +330,20 @@ int main(int argc, char **argv)break ; } +printf_tab ("Memory protection checking:" ); + rc =security_get_checkreqprot (); +switch (rc) { +case 0 : +printf ("actual (secure)\n" ); +break ; +case 1 : +printf ("requested (insecure)\n" ); +break ; +default : +printf ("error (%s)\n" ,strerror (errno)); +break ; + } + rc =security_policyvers ();printf_tab ("Max kernel policy version:" );if (rc <0 )
Signature · 1 line
2.11.0
Stephen Smalley
AppliedQuoted 1 line · Christian Göttsche via Selinux
Show the current active checkreqprot state in sestatus
Thanks, applied. Please add a signed-off-by line in the future.
Quoted 45 lines
---
policycoreutils/sestatus/sestatus.8 | 2 ++policycoreutils/sestatus/sestatus.c| 14 ++++++++++++++2 files changed, 16 insertions(+)policycoreutils/sestatus/sestatus.8 +0
-0@@ -33,6 +33,8 @@ Policy MLS status: enabled.br
Policydeny_unknownstatus: allow
.br
+Memory protection checking: actual (secure)
+.br
Max kernel policy version: 26
.RE
.sppolicycoreutils/sestatus/sestatus.c +0
-0@@ -330,6 +330,20 @@ int main(int argc, char **argv) break; }policycoreutils/sestatus/sestatus.c +14
-0+printf_tab ("Memory protection checking:" ); + rc =security_get_checkreqprot (); +switch (rc) { +case 0 : +printf ("actual (secure)\n" ); +break ; +case 1 : +printf ("requested (insecure)\n" ); +break ; +default : +printf ("error (%s)\n" ,strerror (errno)); +break ; + } +rc =
security_policyvers();
printf_tab("Max kernel policy version:");
if (rc < 0)