Skip to content

network: resolve chroot named unix sockets on-behalf - #337

Open
congwang-mk wants to merge 1 commit into
mainfrom
chroot-relative-unix-path
Open

congwang-mk wants to merge 1 commit into
mainfrom
chroot-relative-unix-path

Conversation

@congwang-mk

Copy link
Copy Markdown
Contributor

Follow-up to #328, which fixed relative named unix socket paths in non-chroot mode.

Chroot mode never moves the child's real root or cwd, yet the named unix gate checked the raw sun_path lexically and returned Continue, leaving the kernel to resolve it on the host:

  • An absolute virtual path such as /tmp/svc.sock reached the host socket of that name instead of the one in the rootfs. Where Landlock cannot gate unix connect (ABI < 9), that is an escape to host sockets under a granted prefix.
  • A relative path was checked as if anchored at / but resolved against the cwd the child was exec'ed in, so ./svc.sock from a granted cwd was refused while tmp/x.sock from an ungranted one passed.

This serves chroot connect/sendto/sendmsg/sendmmsg on-behalf like non-chroot: build the virtual path against the tracked virtual cwd, pin the inode inside the root (mount aware) with openat2(RESOLVE_IN_ROOT), and check can_write on where the pinned inode really sits. The trap stays on under chroot even with Landlock ABI v9, since the kernel cannot resolve virtual paths. As in non-chroot pre-v9, the peer's SO_PEERCRED then names the supervisor.

Tests: a new unix-send rootfs-helper command and three chroot integration tests (absolute and relative stream connects, relative datagram, relative path outside the grant, symlink out of the grant). All fail on main and pass here.

Chroot mode never moves the child's real root or cwd, yet the named unix
gate checked the raw sun_path lexically and returned Continue, leaving the
kernel to resolve it on the host. An absolute virtual path therefore
reached the host's socket of that name (an escape where Landlock cannot
gate unix connect), and a relative one was checked as if anchored at /
but resolved against the cwd the child was exec'ed in, so ./svc.sock from
a granted cwd was refused while tmp/x.sock from an ungranted one passed.

Serve chroot connect/sendto/sendmsg/sendmmsg on-behalf like non-chroot:
build the virtual path against the tracked virtual cwd, pin the inode
inside the root (mount aware), and check write access on where it really
sits. The trap now stays on under chroot even with Landlock ABI v9.

Signed-off-by: Cong Wang <cwang@multikernel.io>

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

1 participant