Skip to contentSkip to conversation

Question

PATCH New Justin Smith 2 participants 3 messages Dec 19, 2001 – Dec 21, 2001 SELinux security module

lore
Share & tools
lore
#0 lore raw

Is there a simple way to determine whether the system is in enforcing or permissive mode (other than issuing the avc_toggle command twice)?

Signature · 4 lines
--
You have received this message because you are subscribed to the selinux list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#1 lore raw
Quoted 2 lines · Justin Smith

Is there a simple way to determine whether the system is in enforcing or permissive mode (other than issuing the avc_toggle command twice)?

Not currently. We originally created the Development option and avc_toggle with the intent of only using it for the development of security policy configurations, expecting that one would build a kernel without the option for operational use once the desired policy configuration had been developed. However, some people may choose to always use a kernel with this option enabled and use avc_toggle in an rc script to switch into enforcing mode during initialization so that they can revert to permissive mode later from an authorized domain. In that situation, I can see that it would be useful to be able to determine whether the kernel is currently permissive or enforcing. Curiously, I received this same question via private email from another person earlier this week.

I suppose that we can add this to our TODO list. It should be quite trivial.

--
Stephen D. Smalley, NAI Labs
[email protected]

--
You have received this message because you are subscribed to the selinux list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#2 lore raw

PATCH 1/1 avc_enforcing (Was: Re: Question)

In reply to Justin Smith
Quoted 2 lines · Justin Smith

Is there a simple way to determine whether the system is in enforcing or permissive mode (other than issuing the avc_toggle command twice)?

The attached patches add a call and program that will allow you to test whether the system is enforcing or permissive without toggling. The first patch should be applied to the lsm tree, and the second patch should be applied to the selinux tree. Apply the patches, rebuild your kernel, do a 'make install' in the selinux/module directory to reinstall the header files used by libsecure, and rebuild and install libsecure. After booting the new kernel, you can run avc_enforcing to see whether the system is enforcing or permissive.

--
Stephen D. Smalley, NAI Labs
[email protected]

Index: lsm/security/selinux/avc.c

security/selinux/avc.c renamed from security/selinux/avc.c:1.2 +10 -0
diff -u lsm/security/selinux/avc.c:1.2 lsm/security/selinux/avc.c:1.3
@@ -1126,10 +1126,20 @@
 	}
 	return avc_debug_always_allow;
 }
+
+long sys_avc_enforcing(void) 
+{
+	return !avc_debug_always_allow;
+}
 #else
 long sys_avc_toggle(void) 
 {
 	return 0;
+}
+
+long sys_avc_enforcing(void) 
+{
+	return 1;
 }
 #endif
 

Index: lsm/security/selinux/arch/i386/syscalls.c

security/selinux/arch/i386/syscalls.c renamed from security/selinux/arch/i386/syscalls.c:1.1 +5 -1
diff -u lsm/security/selinux/arch/i386/syscalls.c:1.1 lsm/security/selinux/arch/i386/syscalls.c:1.2
@@ -155,7 +155,8 @@
 	AL(4), /* execve */
 	AL(3), /* stat64 */
 	AL(3), /* lstat64 */
-	AL(3)  /* fstat64 */
+	AL(3), /* fstat64 */
+	AL(0)  /* avc_enforcing */
 };
 #undef AL
 
@@ -327,6 +328,9 @@
 		err = sys_fstat64_secure(a0, 
 				       (struct stat64*)a1, 
 				       (security_id_t*)a[2]);
+		break;
+	case SELINUXCALL_AVC_ENFORCING:
+		err = sys_avc_enforcing();
 		break;
 	default:
 		err = -EINVAL;

Index: lsm/security/selinux/include/linux/flask/syscalls.h

security/selinux/include/linux/flask/syscalls.h renamed from security/selinux/include/linux/flask/syscalls.h:1.1 +4 -1
diff -u lsm/security/selinux/include/linux/flask/syscalls.h:1.1 lsm/security/selinux/include/linux/flask/syscalls.h:1.3
@@ -55,8 +55,10 @@
 #define SELINUXCALL_LSTAT64       38
 #define SELINUXCALL_FSTAT64       39
 
-#define SELINUXCALL_NUM           39
+#define SELINUXCALL_AVC_ENFORCING 40
 
+#define SELINUXCALL_NUM           40
+
 /* Structure definitions for compute_av call */
 struct security_query {
 	security_id_t ssid;
@@ -119,6 +121,7 @@
 				       __u32 *nel);
 
 extern long sys_avc_toggle(void);
+extern long sys_avc_enforcing(void);
 
 #endif /* __KERNEL__ */
 

Index: selinux/libsecure/include/ss.h

libsecure/include/ss.h renamed from libsecure/include/ss.h:1.1 +2 -0
diff -u selinux/libsecure/include/ss.h:1.1 selinux/libsecure/include/ss.h:1.2
@@ -5,6 +5,8 @@
 
 extern int avc_toggle(void);
 
+extern int avc_enforcing(void);
+
 /* Individual security server calls. */
 
 extern int security_compute_av(struct security_query *query, 

Index: selinux/libsecure/src/avc_enforcing.c

libsecure/src/avc_enforcing.c new file +6 -0
diff -u /dev/null selinux/libsecure/src/avc_enforcing.c:1.1
@@ -0,0 +1,6 @@
+#include <ss.h>
+
+int avc_enforcing(void)
+{
+	return lsm(SELINUX_MAGIC, SELINUXCALL_AVC_ENFORCING, 0);
+}

Index: selinux/libsecure/test/avc_enforcing.c

libsecure/test/avc_enforcing.c new file +25 -0
diff -u /dev/null selinux/libsecure/test/avc_enforcing.c:1.1
@@ -0,0 +1,25 @@
+#include <stdlib.h>
+
+int main(int argc, char **argv, char **envp)
+{
+	int ret;
+
+	if (argc != 1) {
+		printf("usage:  %s\n", argv[0]);
+		exit(1);
+	}
+
+	ret = avc_enforcing();
+	switch (ret) {
+	case 1:
+		printf("enforcing\n");
+		break;
+	case 0:
+		printf("permissive\n");
+		break;
+	default:
+		perror(argv[0]);
+	}
+
+	exit(0);
+}