diff options
-rw-r--r-- | recipes-security/selinux/libselinux/libselinux-mount-procfs-before-check.patch | 74 | ||||
-rw-r--r-- | recipes-security/selinux/libselinux_2.4.bb | 1 | ||||
-rw-r--r-- | recipes-security/selinux/libselinux_git.bb | 1 |
3 files changed, 76 insertions, 0 deletions
diff --git a/recipes-security/selinux/libselinux/libselinux-mount-procfs-before-check.patch b/recipes-security/selinux/libselinux/libselinux-mount-procfs-before-check.patch new file mode 100644 index 0000000..dc27aaa --- /dev/null +++ b/recipes-security/selinux/libselinux/libselinux-mount-procfs-before-check.patch | |||
@@ -0,0 +1,74 @@ | |||
1 | commit 9df498884665d79474b79f0f30d1cd67df11bd3e | ||
2 | Author: Ben Shelton <ben.shelton@ni.com> | ||
3 | Date: Wed Apr 15 15:56:57 2015 -0500 | ||
4 | |||
5 | libselinux: Mount procfs before checking /proc/filesystems | ||
6 | |||
7 | In the case where the SELinux security module is not loaded in the | ||
8 | kernel and it's early enough in the boot process that /proc has not yet | ||
9 | been mounted, selinuxfs_exists() will incorrectly return 1, and | ||
10 | selinux_init_load_policy() will print a message like this to the | ||
11 | console: | ||
12 | |||
13 | Mount failed for selinuxfs on /sys/fs/selinux: No such file or directory | ||
14 | |||
15 | To fix this, mount the procfs before attempting to open | ||
16 | /proc/filesystems, and unmount it when done if it was initially not | ||
17 | mounted. This is the same thing that selinux_init_load_policy() does | ||
18 | when reading /proc/cmdline. | ||
19 | |||
20 | Signed-off-by: Ben Shelton <ben.shelton@ni.com> | ||
21 | |||
22 | Upstream-Status: Accepted | ||
23 | |||
24 | diff --git a/src/init.c b/src/init.c | ||
25 | index 6d1ef33..179e0d0 100644 | ||
26 | --- a/src/init.c | ||
27 | +++ b/src/init.c | ||
28 | @@ -11,6 +11,7 @@ | ||
29 | #include <sys/vfs.h> | ||
30 | #include <stdint.h> | ||
31 | #include <limits.h> | ||
32 | +#include <sys/mount.h> | ||
33 | |||
34 | #include "dso.h" | ||
35 | #include "policy.h" | ||
36 | @@ -54,15 +55,20 @@ static int verify_selinuxmnt(const char *mnt) | ||
37 | |||
38 | int selinuxfs_exists(void) | ||
39 | { | ||
40 | - int exists = 0; | ||
41 | + int exists = 0, mnt_rc = 0; | ||
42 | FILE *fp = NULL; | ||
43 | char *buf = NULL; | ||
44 | size_t len; | ||
45 | ssize_t num; | ||
46 | |||
47 | + mnt_rc = mount("proc", "/proc", "proc", 0, 0); | ||
48 | + | ||
49 | fp = fopen("/proc/filesystems", "r"); | ||
50 | - if (!fp) | ||
51 | - return 1; /* Fail as if it exists */ | ||
52 | + if (!fp) { | ||
53 | + exists = 1; /* Fail as if it exists */ | ||
54 | + goto out; | ||
55 | + } | ||
56 | + | ||
57 | __fsetlocking(fp, FSETLOCKING_BYCALLER); | ||
58 | |||
59 | num = getline(&buf, &len, fp); | ||
60 | @@ -76,6 +82,14 @@ int selinuxfs_exists(void) | ||
61 | |||
62 | free(buf); | ||
63 | fclose(fp); | ||
64 | + | ||
65 | +out: | ||
66 | +#ifndef MNT_DETACH | ||
67 | +#define MNT_DETACH 2 | ||
68 | +#endif | ||
69 | + if (mnt_rc == 0) | ||
70 | + umount2("/proc", MNT_DETACH); | ||
71 | + | ||
72 | return exists; | ||
73 | } | ||
74 | hidden_def(selinuxfs_exists) | ||
diff --git a/recipes-security/selinux/libselinux_2.4.bb b/recipes-security/selinux/libselinux_2.4.bb index ac80bdd..64fa81d 100644 --- a/recipes-security/selinux/libselinux_2.4.bb +++ b/recipes-security/selinux/libselinux_2.4.bb | |||
@@ -13,4 +13,5 @@ SRC_URI += "\ | |||
13 | file://libselinux-define-FD_CLOEXEC-as-necessary.patch \ | 13 | file://libselinux-define-FD_CLOEXEC-as-necessary.patch \ |
14 | file://libselinux-get-pywrap-depends-on-selinux.py.patch \ | 14 | file://libselinux-get-pywrap-depends-on-selinux.py.patch \ |
15 | file://0001-src-Makefile-fix-includedir-in-libselinux.pc.patch \ | 15 | file://0001-src-Makefile-fix-includedir-in-libselinux.pc.patch \ |
16 | file://libselinux-mount-procfs-before-check.patch \ | ||
16 | " | 17 | " |
diff --git a/recipes-security/selinux/libselinux_git.bb b/recipes-security/selinux/libselinux_git.bb index 1cd4dde..20b5534 100644 --- a/recipes-security/selinux/libselinux_git.bb +++ b/recipes-security/selinux/libselinux_git.bb | |||
@@ -13,4 +13,5 @@ SRC_URI += "\ | |||
13 | file://libselinux-define-FD_CLOEXEC-as-necessary.patch \ | 13 | file://libselinux-define-FD_CLOEXEC-as-necessary.patch \ |
14 | file://libselinux-get-pywrap-depends-on-selinux.py.patch \ | 14 | file://libselinux-get-pywrap-depends-on-selinux.py.patch \ |
15 | file://0001-src-Makefile-fix-includedir-in-libselinux.pc.patch \ | 15 | file://0001-src-Makefile-fix-includedir-in-libselinux.pc.patch \ |
16 | file://libselinux-mount-procfs-before-check.patch \ | ||
16 | " | 17 | " |