[RFC PATCH v4 13/14] selftests/rootns: Add root namespace test suite
sashiko-bot at kernel.org
sashiko-bot at kernel.org
Fri Nov 20 22:44:52 UTC 2026
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] selftests/rootns: wrong _IOC_NONE direction in _io() on
wide-ioc archs
- [Low] selftests/rootns: non-blocking accepted socket in
CellService._on_accept()
- [Low] selftests/rootns: resource leaks on Cell init and test setUp()
failures
--
commit 646cdbb1cf35062e2a914f151927bb968fe747a7
Author: Jarkko Sakkinen <jarkko at kernel.org>
selftests/rootns: Add root namespace test suite
This commit adds a kselftest suite for the rootns and mount-namespace
configuration uAPI, covering privileged, unprivileged, and edge-case
scenarios.
> diff --git a/tools/testing/selftests/rootns/rootns_cells.py b/tools/testing/selftests/rootns/rootns_cells.py
> new file mode 100755
> index 0000000000000..b690ed71a5211
> --- /dev/null
> +++ b/tools/testing/selftests/rootns/rootns_cells.py
[ ... ]
> +def _io(magic: int, nr: int) -> int:
> + return _ioc(0, magic, nr, 0)
> +
> +
> +def _iowr(magic: int, nr: int, size: int) -> int:
> + rw = 6 if _is_wide_ioc_arch() else 3
> + return _ioc(rw, magic, nr, size)
[Severity: Medium]
Should _io() pass direction 1 instead of 0 when _is_wide_ioc_arch() is
True?
On PowerPC, SPARC, Alpha, and MIPS, _IOC_NONE is 1U rather than 0U, so
_IO() sets bit 29. Passing 0 encodes the wrong ioctl numbers for
ROOTNS_GET_NSFD, ROOTNS_KILL, and NS_GET_*, causing the kernel to reject
them with ENOTTY.
[ ... ]
> + at dataclass
> +class Cell:
> + name: str
> + flags: int = ROOTNS_KILL_ON_CLOSE | ROOTNS_CLOSE_ON_EXEC
> + cfd: int = field(init=False, default=-1)
> + mntns_fd: int = field(init=False, default=-1)
> + root_dfd: int = field(init=False, default=-1)
> + init_pid: int | None = field(init=False, default=None)
> + exit_status: int | None = field(init=False, default=None)
> +
> + def __post_init__(self) -> None:
> + self.cfd = rootns(self.flags)
> + self.mntns_fd = rootns_get_nsfd(self.cfd, CLONE_NEWNS)
[Severity: Low]
Does Cell.__post_init__() leak self.cfd and the namespaces it pins if
rootns_get_nsfd() raises OSError?
Similarly, in rootns_test.py, unittest does not run tearDown() when
setUp() fails or raises an exception, so CellServiceTest.setUp() leaks
self.daemon_pid and self.tmpdir if the daemon readiness loop calls
self.fail(), and RootnsUapiTest.setUp() leaks self.cell's file descriptors
if setup_rootfs() fails.
[ ... ]
> +class CellService:
> + def __init__(self, sock_path: str) -> None:
[ ... ]
> + self.srv.setblocking(False)
> + self.sel.register(self.srv, selectors.EVENT_READ, self._on_accept)
[ ... ]
> + def _on_accept(self) -> None:
> + conn, _ = self.srv.accept()
> + with conn:
> + data = b""
> + while not data.endswith(b"\n"):
> + chunk = conn.recv(4096)
> + if not chunk:
> + break
> + data += chunk
[Severity: Low]
Can conn.recv(4096) raise an uncaught BlockingIOError here?
In Python, socket.accept() on a non-blocking listening socket returns a
non-blocking client socket. If _on_accept() runs after connect() wakes the
listening socket but before the client sends its request line, conn.recv()
fails with EAGAIN and crashes serve_forever() unless conn.setblocking(True)
is called first.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261119224312.1037966-1-jarkko@kernel.org?part=13
More information about the Linux-security-module-archive
mailing list