Skip to contentSkip to conversation

sestatus: show checkreqprot status

PATCH Applied Christian Göttsche 2 participants 4 messages May 6, 2017 – May 8, 2017 SELinux security module

lore
Share & tools
lore
#0 lore raw

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
#1 lore raw

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
index 45dd6ca5..01201eee 100644
@@ -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
index 7658014a..29cf3de7 100644
@@ -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
new file mode 100644
index 00000000..9b4b12d7
@@ -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
index 3d5c9fb4..54949c13 100644
@@ -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
#2 lore raw

PATCH 2/2 sestatus: show checkreqprot status

In reply to Christian Göttsche

Show 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
index 51ff0566..a89c53fd 100644
@@ -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
index 2111b15d..b05e794c 100644
@@ -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
#3 lore raw
Quoted 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
index 51ff0566..a89c53fd 100644
@@ -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 +0 -0
index 2111b15d..b05e794c 100644
@@ -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)