From: Petr Lautrbach <plautrba@redhat.com>
To: selinux@tycho.nsa.gov
Subject: is_selinux_enabled() after chroot()
Date: Mon, 18 Jun 2018 21:24:44 +0200 [thread overview]
Message-ID: <20180618192443.GA8162@workstation> (raw)
[-- Attachment #1: Type: text/plain, Size: 1848 bytes --]
Hello,
libselinux sets selinut_mnt and has_selinux_config only in its constructor and
is_selinux_enabled() and others just use selinux_mnt to check if SELinux is
enabled. But it doesn't work correctly when you use chroot() to a directory without /proc
and /sys/fs/selinux mounted as it was discovered in
https://bugzilla.redhat.com/show_bug.cgi?id=1321375
In this case, is_selinux_enabled() after chroot() returns true while in a new
program run from chrooted process it returns false. It can be demonstrated by
the steps below.
The solution could be to check if selinux_mnt still exists whenever a function
depending on this is called. Would this be acceptable?
$ sudo dnf --nogpg --installroot=/var/lib/machines/example install systemd
$ cat > test_libselinux.c <<EOF
#include <selinux/selinux.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
pid_t pid;
int wstatus;
if (argc > 1) {
printf("SELinux in chrooted process: %d\n", is_selinux_enabled());
return 0;
}
if (chroot("/var/lib/machines/example") != 0)
return -1;
printf("SELinux in process after chroot(): %d\n", is_selinux_enabled());
printf("/sys/fs/selinux exists: %d\n", access("/sys/fs/selinux", F_OK));
printf("/etc/selinux/config exists: %d\n\n", access("/etc/selinux/config", F_OK));
if ((pid = fork()) == 0 ) {
execv("./test_is_selinux_enabled", (char *[]){ "./test_is_selinux_enabled", "chrooted", NULL});
}
wait(&wstatus);
return 0;
}
EOF
$ gcc -o test_is_selinux_enabled test_libselinux.c -lselinux
$ sudo ./test_is_selinux_enabled
SELinux in process after chroot(): 1
/sys/fs/selinux exists: -1
/etc/selinux/config exists: -1
SELinux in chrooted process: 0
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next reply other threads:[~2018-06-18 19:24 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-18 19:24 Petr Lautrbach [this message]
2018-06-18 20:06 ` is_selinux_enabled() after chroot() Stephen Smalley
2018-06-19 16:32 ` Petr Lautrbach
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180618192443.GA8162@workstation \
--to=plautrba@redhat.com \
--cc=selinux@tycho.nsa.gov \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.