From: Stephen Smalley <stephen.smalley.work@gmail.com>
To: selinux@vger.kernel.org
Cc: paul@paul-moore.com, cgzones@googlemail.com,
Stephen Smalley <stephen.smalley.work@gmail.com>
Subject: [RFC PATCH v3 2/2] systemd: perform SELinux initialization again in a SELinux namespace
Date: Mon, 6 Oct 2025 10:30:54 -0400 [thread overview]
Message-ID: <20251006143052.271761-4-stephen.smalley.work@gmail.com> (raw)
In-Reply-To: <20251006143052.271761-2-stephen.smalley.work@gmail.com>
RFC only, this demonstrates the changes required to systemd to
perform SELinux setup and initialization when run in its own
SELinux namespace. Otherwise, by default, systemd currently skips
SELinux processing when run within a container to avoid conflicting
with the host.
Modify systemd to perform SELinux setup and initialization when
run in its own SELinux namespace.
Signed-off-by: Stephen Smalley <stephen.smalley.work@gmail.com>
---
v3 reverts to setting and checking the SELINUXNS environment variable
for detection of whether the SELinux namespace was unshared since
systemd-nspawn sets seccomp filters that do not allow-list the
lsm_get_self_attr(2) system call.
src/core/main.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/src/core/main.c b/src/core/main.c
index 4fc870d6c0..eb8075fb79 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -3124,6 +3124,22 @@ int main(int argc, char *argv[]) {
log_set_target(LOG_TARGET_JOURNAL_OR_KMSG);
} else {
+ const char *selinuxns = getenv("SELINUXNS");
+
+ if (selinuxns) {
+ r = mac_selinux_setup(&loaded_policy);
+ if (r < 0) {
+ error_message = "Failed to setup SELinux namespace support";
+ goto finish;
+ }
+
+ r = mac_selinux_init();
+ if (r < 0) {
+ error_message = "Failed to initialize SELinux namespace support";
+ goto finish;
+ }
+ }
+
/* Running inside a container, as PID 1 */
log_set_target_and_open(LOG_TARGET_CONSOLE);
--
2.51.0
prev parent reply other threads:[~2025-10-06 14:35 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-06 14:30 [RFC PATCH v3 1/2] nspawn: add --selinux-namespace option to unshare SELinux namespace Stephen Smalley
2025-10-06 14:30 ` Stephen Smalley [this message]
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=20251006143052.271761-4-stephen.smalley.work@gmail.com \
--to=stephen.smalley.work@gmail.com \
--cc=cgzones@googlemail.com \
--cc=paul@paul-moore.com \
--cc=selinux@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).