linux-security-module.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH 0/5] landlock: Pathname-based UNIX connect() control
@ 2026-01-01 13:40 Günther Noack
  2026-01-01 13:40 ` [RFC PATCH 1/5] landlock/selftests: add a missing close(srv_fd) call Günther Noack
                   ` (5 more replies)
  0 siblings, 6 replies; 22+ messages in thread
From: Günther Noack @ 2026-01-01 13:40 UTC (permalink / raw)
  To: Mickaël Salaün, Paul Moore
  Cc: linux-security-module, Tingmao Wang, Justin Suess,
	Samasth Norway Ananda, Matthieu Buffet, Mikhail Ivanov,
	konstantin.meskhidze, Demi Marie Obenour, Alyssa Ross, Jann Horn,
	Tahera Fahimi, Günther Noack

Happy New Year!

This patch set introduces a file-system-based Landlock restriction
mechanism for connecting to Unix sockets.

## Motivation

Currently, landlocked processes can connect() to named UNIX sockets
through the BSD socket API described in unix(7), by invoking socket(2)
followed by connect(2) with a suitable struct sockname_un holding the
socket's filename.  This can come as a surprise for users (e.g. in
[1]) and it can be used to escape a sandbox when a Unix service offers
command execution (some scenarios were listed by Tingmao Wang in [2]).

These patches are built on Justin Suess's patch which adds the LSM
hook:
https://lore.kernel.org/all/20251231213314.2979118-1-utilityemal77@gmail.com/

I am keeping this tagged as "RFC" since Justin's patch is RFC as well
so far.

The original feature request is at [4].

## Alternatives and Related Work

### Alternative: Use existing LSM hooks

The existing hooks security_unix_stream_connect(),
security_unix_may_send() and security_socket_connect() do not give
access to the resolved file system path.

Resolving the file system path again within Landlock would in my
understanding produce a TOCTOU race, so making the decision based on
the struct sockaddr_un contents is not an option.

It is tempting to use the struct path that the listening socket is
bound to, which can be acquired through the existing hooks.
Unfortunately, the listening socket may have been bound from within a
different namespace, and it is therefore a path that can not actually
be referenced by the sandboxed program at the time of constructing the
Landlock policy.  (More details are on the Github issue at [6]).

### Related work: Scope Control for Pathname Unix Sockets

The motivation for this patch is the same as in Tingmao Wang's patch
set for "scoped" control for pathname Unix sockets [2], originally
proposed in the Github feature request [5].

In my reply to this patch set [3], I have discussed the differences
between these two approaches.  On the related discussions on Github
[4] and [5], there was consensus that the scope-based control is
complimentary to the file system based control, but does not replace
it.  Mickael's opening remark on [5] says:

> This scoping would be complementary to #36 which would mainly be
> about allowing a sandboxed process to connect to a more privileged
> service (identified with a path).

## Credits

The feature was originally suggested by Jann Horn in [7].

Tingmao Wang and Demi Marie Obenour have taken the initiative to
revive this discussion again in [1], [4] and [5] and Tingmao Wang has
sent the patch set for the scoped access control for pathname Unix
sockets [2].

Justin Suess has sent the patch for the LSM hook in [8].

Ryan Sullivan has started on an initial implementation and has brought
up relevant discussion points on the Github issue at [4] that lead to
the current approach.

[1] https://lore.kernel.org/landlock/515ff0f4-2ab3-46de-8d1e-5c66a93c6ede@gmail.com/
[2] Tingmao Wang's "Implemnet scope control for pathname Unix sockets"
    https://lore.kernel.org/all/cover.1767115163.git.m@maowtm.org/
[3] https://lore.kernel.org/all/20251230.bcae69888454@gnoack.org/
[4] Github issue for FS-based control for named Unix sockets:
    https://github.com/landlock-lsm/linux/issues/36
[5] Github issue for scope-based restriction of named Unix sockets:
    https://github.com/landlock-lsm/linux/issues/51
[6] https://github.com/landlock-lsm/linux/issues/36#issuecomment-2950632277
[7] https://lore.kernel.org/linux-security-module/CAG48ez3NvVnonOqKH4oRwRqbSOLO0p9djBqgvxVwn6gtGQBPcw@mail.gmail.com/
[8] Patch for the LSM hook:
    https://lore.kernel.org/linux-security-module/CAG48ez3NvVnonOqKH4oRwRqbSOLO0p9djBqgvxVwn6gtGQBPcw@mail.gmail.com/

Günther Noack (5):
  landlock/selftests: add a missing close(srv_fd) call
  landlock: Control connections to pathname UNIX sockets by path
  samples/landlock: Add support for LANDLOCK_ACCESS_FS_CONNECT_UNIX
  landlock/selftests: test LANDLOCK_ACCESS_FS_CONNECT_UNIX
  landlock: Document LANDLOCK_ACCESS_FS_UNIX_CONNECT

 Documentation/userspace-api/landlock.rst     | 14 ++-
 include/uapi/linux/landlock.h                |  3 +
 samples/landlock/sandboxer.c                 | 11 ++-
 security/landlock/access.h                   |  2 +-
 security/landlock/audit.c                    |  1 +
 security/landlock/fs.c                       |  9 +-
 security/landlock/limits.h                   |  2 +-
 security/landlock/syscalls.c                 |  2 +-
 tools/testing/selftests/landlock/base_test.c |  2 +-
 tools/testing/selftests/landlock/fs_test.c   | 94 ++++++++++++++++----
 10 files changed, 113 insertions(+), 27 deletions(-)

-- 
2.52.0


^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2026-01-02 18:37 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-01 13:40 [RFC PATCH 0/5] landlock: Pathname-based UNIX connect() control Günther Noack
2026-01-01 13:40 ` [RFC PATCH 1/5] landlock/selftests: add a missing close(srv_fd) call Günther Noack
2026-01-01 13:40 ` [RFC PATCH 2/5] landlock: Control connections to pathname UNIX sockets by path Günther Noack
2026-01-01 13:41 ` [RFC PATCH 3/5] samples/landlock: Add support for LANDLOCK_ACCESS_FS_CONNECT_UNIX Günther Noack
2026-01-01 19:30   ` Justin Suess
2026-01-01 22:07     ` Tingmao Wang
2026-01-01 22:11       ` Demi Marie Obenour
2026-01-01 22:19         ` Tingmao Wang
2026-01-01 22:36           ` Demi Marie Obenour
2026-01-01 22:38           ` Justin Suess
2026-01-01 22:39             ` Demi Marie Obenour
2026-01-02  9:53               ` Günther Noack
2026-01-01 13:41 ` [RFC PATCH 4/5] landlock/selftests: test LANDLOCK_ACCESS_FS_CONNECT_UNIX Günther Noack
2026-01-01 13:41 ` [RFC PATCH 5/5] landlock: Document LANDLOCK_ACCESS_FS_UNIX_CONNECT Günther Noack
2026-01-01 22:14 ` [RFC PATCH 0/5] landlock: Pathname-based UNIX connect() control Demi Marie Obenour
2026-01-01 22:34   ` Tingmao Wang
2026-01-01 22:44     ` Demi Marie Obenour
2026-01-02 10:16       ` Günther Noack
2026-01-02 10:25         ` Günther Noack
2026-01-02 10:27         ` Demi Marie Obenour
2026-01-02 10:50           ` Günther Noack
2026-01-02 18:37             ` Demi Marie Obenour

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).