Skip to contentSkip to conversation

sestatus: show checkreqprot status

PATCH In review Christian Göttsche 2 participants 5 messages May 4, 2017 – May 5, 2017 SELinux security module

lore
Share & tools
lore
#0 lore raw

cover sestatus: show checkreqprot status

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 |  9 ++++++-
 libselinux/src/checkreqprot.c             | 40 +++++++++++++++++++++++++++++++
 libselinux/src/selinux_internal.h         |  1 +
 policycoreutils/sestatus/sestatus.c       | 14 +++++++++++
 5 files changed, 66 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 |  9 ++++++-
 libselinux/src/checkreqprot.c             | 40 +++++++++++++++++++++++++++++++
 libselinux/src/selinux_internal.h         |  1 +
 4 files changed, 52 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 +8 -1
index 7658014a..346b2cbd 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,11 @@ 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 ()
+returns 0 if SELinux checks protection on mmap and mprotect calls preset by
+the kernel, 1 if SELinux checks the protection on mmap and mprotect calls
+requested by the application, 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

Re: [PATCH 1/2] libselinux: add security_get_checkreqprot

Quoted 63 lines · Christian Göttsche via Selinux

Add security_get_checkreqprot() function, returning the current active
checkreqprot value
---
 libselinux/include/selinux/selinux.h      |  3 +++ libselinux/man/man3/security_getenforce.3 |  9 ++++++- libselinux/src/checkreqprot.c             | 40
+++++++++++++++++++++++++++++++
 libselinux/src/selinux_internal.h         |  1 +

 4 files changed, 52 insertions(+), 1 deletion(-)

 create mode 100644 libselinux/src/checkreqprot.c

libselinux/include/selinux/selinux.h +0 -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);

libselinux/include/selinux/selinux.h +3 -0
+/* 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 +0 -0
index 7658014a..346b2cbd 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>

libselinux/man/man3/security_getenforce.3 +0 -0
@@ -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 ()

libselinux/man/man3/security_getenforce.3 +0 -0
@@ -24,6 +26,11 @@ 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.

libselinux/man/man3/security_getenforce.3 +3 -0
+
+.BR security_get_checkreqprot ()
+returns 0 if SELinux checks protection on mmap and mprotect calls
Quoted 4 lines

preset by
+the kernel, 1 if SELinux checks the protection on mmap and mprotect calls
+requested by the application, and \-1 on error.

I don't think this is very clear. How about:
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.

Quoted 64 lines

 .
 .SH "SEE ALSO"
 .BR selinux "(8)"

libselinux/src/checkreqprot.c new file +23 -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);

libselinux/src/checkreqprot.c new file +17 -0
+	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)
#3 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.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
policycoreutils/sestatus/sestatus.c +14 -0
index 2111b15d..a461251d 100644
@@ -330,6 +330,20 @@ int main(int argc, char **argv)
 			break;
 	}
 
+	printf_tab("Current checkreqprot mode:");
+	rc = security_get_checkreqprot();
+	switch (rc) {
+		case 0:
+			printf("Kernel preset\n");
+			break;
+		case 1:
+			printf("Application requested\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
#4 lore raw
Quoted 14 lines · Christian Göttsche via Selinux

Show the current active checkreqprot state in sestatus
---
 policycoreutils/sestatus/sestatus.c | 14 ++++++++++++++

 1 file changed, 14 insertions(+)
policycoreutils/sestatus/sestatus.c +0 -0
index 2111b15d..a461251d 100644
@@ -330,6 +330,20 @@ int main(int argc, char **argv)
  			break;
  	}

policycoreutils/sestatus/sestatus.c int main(int argc, char **argv) · line 337

Quoted 5 lines
policycoreutils/sestatus/sestatus.c +5 -0
+	printf_tab("Current checkreqprot mode:");
+	rc = security_get_checkreqprot();
+	switch (rc) {
+		case 0:
+			printf("Kernel preset\n");

As with the other one, "kernel preset" isn't very clear. The difference is between the actual protection applied by the kernel and the protection requested by the application.

Quoted 9 lines
policycoreutils/sestatus/sestatus.c +9 -0
+			break;
+		case 1:
+			printf("Application requested\n");
+			break;
+		default:
+			printf("error (%s)\n", strerror(errno));
+			break;
+	}
+
Quoted 3 lines

  rc = security_policyvers();
  printf_tab("Max kernel policy version:");
  if (rc < 0)

Don't think this really conveys the right meaning or will be understandable to users. My previous suggestions were:
Check requested protection: false/true
or
Memory protection checking: actual/requested
or
Memory protection checking: secure/insecure

Even if you really want to stick with "Current checkreqprot mode:", the values (false/true, actual/requested, secure/insecure) still make sense.