Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-cached is_selinux_enabled() variant? #419

Open
praiskup opened this issue Feb 7, 2024 · 1 comment
Open

Non-cached is_selinux_enabled() variant? #419

praiskup opened this issue Feb 7, 2024 · 1 comment

Comments

@praiskup
Copy link

praiskup commented Feb 7, 2024

Consider that the caller does chroot() first, and then asks for is_selinux_enabled(). The current implementation uses cached static variable values to report if SELinux is enabled, these values are initiated by the library constructor (before the caller has the chance to call chroot()).

int is_selinux_enabled(void)
{
/* init_selinuxmnt() gets called before this function. We
* will assume that if a selinux file system is mounted, then
* selinux is enabled. */
#ifdef ANDROID
return (selinux_mnt ? 1 : 0);
#else
return (selinux_mnt && has_selinux_config);
#endif
}

static void init_lib(void) __attribute__ ((constructor));
static void init_lib(void)
{
selinux_page_size = sysconf(_SC_PAGE_SIZE);
init_selinuxmnt();
#ifndef ANDROID
has_selinux_config = (access(SELINUXCONFIG, F_OK) == 0);
#endif
}

The thing is that tools like useradd --root /some/chroot need some API to detect that SELinux is disabled in the chroot for further logic.

@cgzones
Copy link
Contributor

cgzones commented Feb 15, 2024

A call to fini_selinuxmnt(3) should cause is_selinux_enabled(3) to report disabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants