[Bug]: linux.mountLabel makes the /dev/mqueue mount fail with EINVAL (every Podman container on an SELinux host)
Bug Description
With linux.mountLabel set on an SELinux-enabled host, youki adds context=<label> to every mount except proc and sysfs (crates/libcontainer/src/rootfs/mount.rs:578-586 at eb07b60173fca880e4287d5bc0de2580edec2c91; the label comes from rootfs.rs:88). The kernel refuses context= for mqueue with EINVAL, so the container fails with failed to prepare rootfs.
Podman sets mountLabel and mounts /dev/mqueue for every container on an SELinux host, so none of them start with youki.
How the others do it:
- runc (v1.4.1,
libcontainer/rootfs_linux.go:628-634) mounts mqueue without the label, then sets it withlabel.SetFileLabelon the mount point. - crun (1.30,
src/libcrun/linux.c:2842-2851,get_mount_label_how()) returnsLABEL_XATTRfor mqueue: label by xattr, not by mount option.
The spec (config-linux.md, mountLabel) says only that it "will set the Selinux context for the mounts in the container". It doesn't require the mount option.
Steps to Reproduce
On an SELinux-enabled host, as root or rootless:
#!/bin/sh
# repro.sh <runtime> [workdir]: a bundle with linux.mountLabel set, on an SELinux-enabled host.
# `youki spec` / `crun spec` bundles mount /dev/mqueue (type mqueue). Prints the labels of
# /dev/mqueue, /dev/shm and /dev/pts, read from the host through /proc/<pid>/root.
set -eu
RT=$1; W=${2:-$(pwd)/work-$RT}
LABEL=${LABEL:-system_u:object_r:container_file_t:s0:c100,c200}
here=$(cd "$(dirname "$0")" && pwd)
rm -rf "$W"; mkdir -p "$W/bundle/rootfs"
tar -xzf "$here/alpine-minirootfs-3.24.2-x86_64.tar.gz" -C "$W/bundle/rootfs" 2>/dev/null
cd "$W/bundle"
if [ "$(id -u)" = 0 ]; then "$RT" spec; else "$RT" spec --rootless; fi
python3 - "$LABEL" <<'P'
import json, sys
s = json.load(open('config.json'))
s['process']['terminal'] = False
s['process']['args'] = ['sleep', '5']
s['linux']['mountLabel'] = sys.argv[1]
print('mounts:', [m['destination'] + ':' + m.get('type', '') for m in s['mounts'] if m['destination'] in ('/dev/mqueue', '/dev/shm', '/dev/pts')])
json.dump(s, open('config.json', 'w'), indent=2)
P
"$RT" --root "$W/state" run --detach --bundle "$W/bundle" c1 </dev/null >/dev/null 2>"$W/err" || { cat "$W/err"; exit 1; }
pid=$("$RT" --root "$W/state" state c1 | python3 -c 'import json,sys; print(json.load(sys.stdin)["pid"])')
ls -dZ /proc/$pid/root/dev/mqueue /proc/$pid/root/dev/shm /proc/$pid/root/dev/pts | sed "s|/proc/$pid/root||"
"$RT" --root "$W/state" kill c1 KILL >/dev/null 2>&1 || true
sleep 1; "$RT" --root "$W/state" delete --force c1 >/dev/null 2>&1 || trueyouki at eb07b601, as root:
mounts: ['/dev/pts:devpts', '/dev/shm:tmpfs', '/dev/mqueue:mqueue']
ERROR libcontainer::rootfs::mount: failed to mount Mount { destination: "/dev/mqueue", typ: Some("mqueue"), source: Some("mqueue"), options: Some(["nosuid", "noexec", "nodev"]), uid_mappings: None, gi
ERROR libcontainer::process::init::process: failed to prepare rootfs err=Mount(Syscall(Nix(EINVAL)))
ERROR youki: error in executing command: failed to create container: exec process failed with error failed to prepare rootfs
exit=1The same rootless. crun 1.27, root and rootless:
mounts: ['/dev/pts:devpts', '/dev/shm:tmpfs', '/dev/mqueue:mqueue']
system_u:object_r:container_file_t:s0:c100,c200 /dev/mqueue
system_u:object_r:container_file_t:s0:c100,c200 /dev/pts
system_u:object_r:container_file_t:s0:c100,c200 /dev/shm
exit=0Expectation
The container starts, and /dev/mqueue carries the mount label like the other mounts, as with crun.
System and Setup Info
Velrix OS rig VM: AlmaLinux 10.2 (bootc), kernel 6.12.0-211.56.1.el10_2.x86_64, SELinux enforcing, targeted policy, crun 1.27, Podman 5.8.2.
youki built from eb07b60173fca880e4287d5bc0de2580edec2c91 (youki version 0.7.0, static musl, features systemd,v2,seccomp).
Additional Context
#2688 (linux_mount_label contest test) and #3034 (formatting the mount label with the SELinux library) touch mount labels, but not the mqueue case.
Source: youki-dev/youki