Files
nvdriver/tools
Patrick Hamid 02cf1e18cc fix(tools): survive unreadable parent mount-ns in the launcher namespace guard (#613)
[T] Observed live on physical silicon (Tesla P100 SXM2, host-native
nvidia_rs lanes, kernel 6.12.105, driver 8f5bf596):

do_namespace() reads /proc/<getppid()>/ns/mnt unconditionally. When the
launcher is started through a container-runtime or supervisor chain
(incus exec, docker exec, systemd wrappers) the spawning process can
already be gone or invisible in the PID namespace, getppid() reports
pid 0, and the readlink aborts the launcher with:

    FileNotFoundError: [Errno 2] No such file or directory: '/proc/0/ns/mnt'

before any mount step runs. This reproduced on every lane start in that
setup until the guard was made tolerant.

Fix: fall back to the namespace init's mount ns (/proc/1/ns/mnt), which
is the original mount namespace the app process must diverge from, and
if even that link is unreadable (hidepid / ptrace checks under a
non-root test run) degrade to the self-comparison alone. The guard
stays fail-closed in all three paths: if unshare() did not create a
private namespace, now == before still aborts.

Verification (both on the patch, python 3.12):
- non-root, getppid() -> 0: launcher now passes the guard and stops at
  unshare(CLONE_NEWNS) EPERM (was: FileNotFoundError crash at the guard)
- root, getppid() -> 0: do_namespace() completes, in_private_namespace
  True, ns id differs from before (guard + unshare + check all work)
- unchanged behavior when getppid()'s ns is readable (first path taken)

Signed-off-by: Patrick Hamid <phamid@users.noreply.github.com>
Co-authored-by: Patrick Hamid <phamid@users.noreply.github.com>
2026-12-05 07:20:40 -08:00
..