All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] libselinux: is_selinux_enabled(): drop no-policy-loaded test.
@ 2015-04-17 13:42 Stephen Smalley
  2015-05-11 13:40 ` Petr Lautrbach
  0 siblings, 1 reply; 14+ messages in thread
From: Stephen Smalley @ 2015-04-17 13:42 UTC (permalink / raw)
  To: selinux; +Cc: Stephen Smalley

SELinux can be disabled via the selinux=0 kernel parameter or via
/sys/fs/selinux/disable (triggered by setting SELINUX=disabled in
/etc/selinux/config).  In either case, selinuxfs will be unmounted
and unregistered and therefore it is sufficient to check for the
selinuxfs mount.  We do not need to check for no-policy-loaded and
treat that as SELinux-disabled anymore; that is a relic of Fedora Core 2
days.  Drop the no-policy-loaded test, which was a bit of a hack anyway
(checking whether getcon_raw() returned "kernel" as that can only happen
if no policy is yet loaded and therefore security_sid_to_context() only
has the initial SID name available to return as the context).

May possibly fix https://bugzilla.redhat.com/show_bug.cgi?id=1195074
by virtue of removing the call to getcon_raw() and therefore avoiding
use of tls on is_selinux_enabled() calls.  Regardless, it will make
is_selinux_enabled() faster and simpler.

Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
---
 libselinux/src/enabled.c | 18 +-----------------
 1 file changed, 1 insertion(+), 17 deletions(-)

diff --git a/libselinux/src/enabled.c b/libselinux/src/enabled.c
index 5c252dd..1731ac3 100644
--- a/libselinux/src/enabled.c
+++ b/libselinux/src/enabled.c
@@ -11,26 +11,10 @@
 
 int is_selinux_enabled(void)
 {
-	int enabled = 0;
-	char * con;
-
 	/* init_selinuxmnt() gets called before this function. We
  	 * will assume that if a selinux file system is mounted, then
  	 * selinux is enabled. */
-	if (selinux_mnt) {
-
-		/* Since a file system is mounted, we consider selinux
-		 * enabled. If getcon_raw fails, selinux is still enabled.
-		 * We only consider it disabled if no policy is loaded. */
-		enabled = 1;
-		if (getcon_raw(&con) == 0) {
-			if (!strcmp(con, "kernel"))
-				enabled = 0;
-			freecon(con);
-		}
-        }
-
-	return enabled;
+	return (selinux_mnt ? 1 : 0);
 }
 
 hidden_def(is_selinux_enabled)
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2015-05-12 14:27 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-17 13:42 [PATCH] libselinux: is_selinux_enabled(): drop no-policy-loaded test Stephen Smalley
2015-05-11 13:40 ` Petr Lautrbach
2015-05-11 13:43   ` Stephen Smalley
2015-05-11 13:49     ` Petr Lautrbach
2015-05-11 14:02       ` Stephen Smalley
2015-05-11 14:04         ` Stephen Smalley
2015-05-11 14:11           ` Petr Lautrbach
2015-05-11 14:52             ` Stephen Smalley
2015-05-11 15:27               ` Dominick Grift
2015-05-12 12:54               ` Petr Lautrbach
2015-05-12 12:56                 ` Stephen Smalley
2015-05-12 13:51                   ` Petr Lautrbach
2015-05-12 13:59                     ` Stephen Smalley
2015-05-12 14:27                       ` Petr Lautrbach

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.