Skip to content

Commit

Permalink
libselinux: fix selinux_restorecon() on non-SELinux hosts
Browse files Browse the repository at this point in the history
The kernel only supports seclabel if it is >= 2.6.30 _and_
SELinux is enabled, since seclabel is generated by SELinux
based partly on policy (e.g. is the filesystem type configured in policy
with a labeling behavior that supports userspace labeling). For some
reason, when this logic was moved from setfiles to libselinux,
the test of whether SELinux was enabled was dropped.  Restore it.

This is necessary to enable use of setfiles on non-SELinux hosts
without requiring explicit use of the -m option.

Fixes: 602347c ("policycoreutils: setfiles - Modify to use selinux_restorecon")
Reported-by: sajjad ahmed <[email protected]>
Signed-off-by: Stephen Smalley <[email protected]>
Cc: Richard Haines <[email protected]>
Reported-by: sajjad ahmed &lt;<a href="mailto:[email protected]" target="_blank">[email protected]</a>&gt;<br>
Signed-off-by: Stephen Smalley &lt;<a href="mailto:[email protected]" target="_blank">[email protected]</a>&gt;<br>
  • Loading branch information
stephensmalley authored and bachradsusi committed Feb 20, 2019
1 parent 60a9285 commit 6b89b1f
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions libselinux/src/selinux_restorecon.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ static int exclude_non_seclabel_mounts(void)
/* Check to see if the kernel supports seclabel */
if (uname(&uts) == 0 && strverscmp(uts.release, "2.6.30") < 0)
return 0;
if (is_selinux_enabled() <= 0)
return 0;

fp = fopen("/proc/mounts", "re");
if (!fp)
Expand Down

0 comments on commit 6b89b1f

Please sign in to comment.