* [PATCH 0/2] landlock: Document and test TSYNC on sibling threads
@ 2026-11-28 21:30 Christopher Lusk via B4 Relay
2026-11-28 21:30 ` [PATCH 1/2] landlock: Document TSYNC in the inheritance section Christopher Lusk via B4 Relay
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Christopher Lusk via B4 Relay @ 2026-11-28 21:30 UTC (permalink / raw)
To: Mickaël Salaün
Cc: Günther Noack, Jonathan Corbet, Shuah Khan, Randy Dunlap,
linux-security-module, linux-doc, linux-kselftest, linux-kernel,
Christopher Lusk
The inheritance section of the userspace API guide still says that a
thread's rules are not applied to its sibling threads. Patch 1 mentions
LANDLOCK_RESTRICT_SELF_TSYNC there, and that a process forked or a
program executed by a sibling before it is restricted is not affected.
Patch 2 checks that the siblings are actually restricted, including one
that switched UID with the raw setresuid(2). The existing tests only
check the return value and no_new_privs.
Based on the Landlock next branch. tsync_test passes 14/14 there and on
v7.4-rc4; without TSYNC, both new variants fail. I did not build the
HTML documentation.
Found and drafted with LLM assistance, in QEMU experiments; I reviewed,
tested and edited the patches.
Signed-off-by: Christopher Lusk <clusk@northecho.dev>
---
Christopher Lusk (2):
landlock: Document TSYNC in the inheritance section
selftests/landlock: Check that TSYNC restricts sibling threads
Documentation/userspace-api/landlock.rst | 4 +-
tools/testing/selftests/landlock/tsync_test.c | 129 ++++++++++++++++++++++++++
2 files changed, 132 insertions(+), 1 deletion(-)
---
base-commit: bb872036147b78498276986ac54634fbc609efa3
change-id: 20261128-b4-tsync-9d29944741e7
Best regards,
--
Christopher Lusk <clusk@northecho.dev>
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH 1/2] landlock: Document TSYNC in the inheritance section 2026-11-28 21:30 [PATCH 0/2] landlock: Document and test TSYNC on sibling threads Christopher Lusk via B4 Relay @ 2026-11-28 21:30 ` Christopher Lusk via B4 Relay 2026-11-28 21:30 ` [PATCH 2/2] selftests/landlock: Check that TSYNC restricts sibling threads Christopher Lusk via B4 Relay 2026-11-28 21:41 ` [PATCH 0/2] landlock: Document and test TSYNC on " sashiko-bot 2 siblings, 0 replies; 5+ messages in thread From: Christopher Lusk via B4 Relay @ 2026-11-28 21:30 UTC (permalink / raw) To: Mickaël Salaün Cc: Günther Noack, Jonathan Corbet, Shuah Khan, Randy Dunlap, linux-security-module, linux-doc, linux-kselftest, linux-kernel, Christopher Lusk From: Christopher Lusk <clusk@northecho.dev> The inheritance section says that a thread's Landlock rules are not applied to its sibling threads, which is no longer the whole story since LANDLOCK_RESTRICT_SELF_TSYNC (ABI 8). Mention the flag, and that a process forked or a program executed by a sibling before it is restricted is not affected. Found with LLM-driven testing of TSYNC. Signed-off-by: Christopher Lusk <clusk@northecho.dev> --- Documentation/userspace-api/landlock.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Documentation/userspace-api/landlock.rst b/Documentation/userspace-api/landlock.rst index 7cc5fde48262..d40915c34cd2 100644 --- a/Documentation/userspace-api/landlock.rst +++ b/Documentation/userspace-api/landlock.rst @@ -467,7 +467,9 @@ Documentation/userspace-api/seccomp_filter.rst) or any other LSM dealing with task's :manpage:`credentials(7)`. For instance, one process's thread may apply Landlock rules to itself, but they will not be automatically applied to other sibling threads (unlike POSIX thread credential changes, cf. -:manpage:`nptl(7)`). +:manpage:`nptl(7)`), unless ``LANDLOCK_RESTRICT_SELF_TSYNC`` is used. Even +then, a process forked or a program executed by a sibling before it is +restricted is not affected. When a thread sandboxes itself, we have the guarantee that the related security policy will stay enforced on all this thread's descendants. This allows -- 2.56.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] selftests/landlock: Check that TSYNC restricts sibling threads 2026-11-28 21:30 [PATCH 0/2] landlock: Document and test TSYNC on sibling threads Christopher Lusk via B4 Relay 2026-11-28 21:30 ` [PATCH 1/2] landlock: Document TSYNC in the inheritance section Christopher Lusk via B4 Relay @ 2026-11-28 21:30 ` Christopher Lusk via B4 Relay 2026-11-28 21:41 ` sashiko-bot 2026-11-28 21:41 ` [PATCH 0/2] landlock: Document and test TSYNC on " sashiko-bot 2 siblings, 1 reply; 5+ messages in thread From: Christopher Lusk via B4 Relay @ 2026-11-28 21:30 UTC (permalink / raw) To: Mickaël Salaün Cc: Günther Noack, Jonathan Corbet, Shuah Khan, Randy Dunlap, linux-security-module, linux-doc, linux-kselftest, linux-kernel, Christopher Lusk From: Christopher Lusk <clusk@northecho.dev> The TSYNC tests check the return value and the sibling threads' no_new_privs, but not that the siblings are actually restricted. Add a test that checks a sibling's write access before and after the call, with a variant where the sibling first switches to another UID with the raw setresuid(2), and that the sibling keeps its UID. Signed-off-by: Christopher Lusk <clusk@northecho.dev> --- tools/testing/selftests/landlock/tsync_test.c | 129 ++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) diff --git a/tools/testing/selftests/landlock/tsync_test.c b/tools/testing/selftests/landlock/tsync_test.c index 2b53596c986e..27f5fe1aa9c4 100644 --- a/tools/testing/selftests/landlock/tsync_test.c +++ b/tools/testing/selftests/landlock/tsync_test.c @@ -6,10 +6,13 @@ */ #define _GNU_SOURCE +#include <fcntl.h> #include <linux/landlock.h> #include <pthread.h> #include <signal.h> +#include <stdlib.h> #include <sys/prctl.h> +#include <sys/stat.h> #include "common.h" @@ -231,6 +234,132 @@ TEST(competing_enablement) EXPECT_EQ(0, close(ruleset_fd)); } +struct sibling_probe { + pthread_barrier_t *ready; + pthread_barrier_t *restricted; + const char *path; + /* If not zero, the sibling switches to this UID before the enforcement. */ + uid_t drop_to; + int drop_result; + int open_errno_before; + int open_errno_after; + int no_new_privs; + uid_t uid; +}; + +static int open_errno(const char *const path) +{ + const int fd = open(path, O_WRONLY | O_CLOEXEC); + + if (fd < 0) + return errno; + close(fd); + return 0; +} + +static void *probe_sibling(void *data) +{ + struct sibling_probe *const p = data; + + /* Unlike setresuid(3), the raw system call only changes this thread. */ + if (p->drop_to) + p->drop_result = syscall(SYS_setresuid, p->drop_to, p->drop_to, + p->drop_to); + p->open_errno_before = open_errno(p->path); + pthread_barrier_wait(p->ready); + + /* Waits for the other thread's landlock_restrict_self(2) to return. */ + pthread_barrier_wait(p->restricted); + p->open_errno_after = open_errno(p->path); + p->no_new_privs = prctl(PR_GET_NO_NEW_PRIVS, 0, 0, 0, 0); + p->uid = syscall(SYS_getuid); + return NULL; +} + +FIXTURE(tsync_sibling) +{ + char path[64]; + int ruleset_fd; +}; + +FIXTURE_VARIANT(tsync_sibling) +{ + /* The sibling thread runs with a different UID than the caller. */ + const bool diverged_creds; +}; + +/* clang-format off */ +FIXTURE_VARIANT_ADD(tsync_sibling, same_creds) { + /* clang-format on */ + .diverged_creds = false, +}; + +/* clang-format off */ +FIXTURE_VARIANT_ADD(tsync_sibling, diverged_creds) { + /* clang-format on */ + .diverged_creds = true, +}; + +FIXTURE_SETUP(tsync_sibling) +{ + int fd; + + strcpy(self->path, "/tmp/landlock_tsync_XXXXXX"); + fd = mkstemp(self->path); + ASSERT_LE(0, fd); + /* Lets a sibling with another UID write to it before the enforcement. */ + ASSERT_EQ(0, fchmod(fd, 0666)); + EXPECT_EQ(0, close(fd)); + self->ruleset_fd = create_ruleset(_metadata); +} + +FIXTURE_TEARDOWN(tsync_sibling) +{ + EXPECT_EQ(0, close(self->ruleset_fd)); + /* LANDLOCK_ACCESS_FS_REMOVE_FILE is not handled by the ruleset. */ + EXPECT_EQ(0, unlink(self->path)); +} + +/* + * Checks that a sibling thread is actually restricted once + * landlock_restrict_self(2) with LANDLOCK_RESTRICT_SELF_TSYNC returns, and + * that it keeps its own credentials apart from the Landlock domain and + * no_new_privs. + */ +TEST_F(tsync_sibling, restricted) +{ + pthread_barrier_t ready, restricted; + const uid_t caller_uid = getuid(); + struct sibling_probe probe = { + .ready = &ready, + .restricted = &restricted, + .path = self->path, + .drop_to = variant->diverged_creds ? 65534 : 0, + }; + pthread_t t; + + ASSERT_EQ(0, pthread_barrier_init(&ready, NULL, 2)); + ASSERT_EQ(0, pthread_barrier_init(&restricted, NULL, 2)); + ASSERT_EQ(0, pthread_create(&t, NULL, probe_sibling, &probe)); + pthread_barrier_wait(&ready); + + disable_caps(_metadata); + ASSERT_EQ(0, prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0)); + ASSERT_EQ(0, landlock_restrict_self(self->ruleset_fd, + LANDLOCK_RESTRICT_SELF_TSYNC)); + pthread_barrier_wait(&restricted); + ASSERT_EQ(0, pthread_join(t, NULL)); + + if (variant->diverged_creds && probe.drop_result) + SKIP(return, "Cannot switch the sibling thread's UID"); + + EXPECT_EQ(0, probe.open_errno_before); + EXPECT_EQ(EACCES, probe.open_errno_after); + EXPECT_EQ(1, probe.no_new_privs); + EXPECT_EQ(variant->diverged_creds ? 65534 : caller_uid, probe.uid); + EXPECT_EQ(EACCES, open_errno(self->path)); +} + static void signal_nop_handler(int sig) { } -- 2.56.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] selftests/landlock: Check that TSYNC restricts sibling threads 2026-11-28 21:30 ` [PATCH 2/2] selftests/landlock: Check that TSYNC restricts sibling threads Christopher Lusk via B4 Relay @ 2026-11-28 21:41 ` sashiko-bot 0 siblings, 0 replies; 5+ messages in thread From: sashiko-bot @ 2026-11-28 21:41 UTC (permalink / raw) Cc: linux-security-module Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [Medium] selftests/landlock: disable_caps() after pthread_create() diverges creds - [Low] selftests/landlock: 16-bit UID syscalls and hardcoded UID in probe_sibling() - [Low] selftests/landlock: temporary file leak in FIXTURE_SETUP(tsync_sibling) -- commit 83bc285b6627c21d80498fc8a3d7d28289805124 Author: Christopher Lusk <clusk@northecho.dev> selftests/landlock: Check that TSYNC restricts sibling threads This commit adds a kselftest verifying that LANDLOCK_RESTRICT_SELF_TSYNC restricts write access on a sibling thread, both when sharing credentials and when the sibling switches its UID via raw setresuid(2). > diff --git a/tools/testing/selftests/landlock/tsync_test.c b/tools/testing/selftests/landlock/tsync_test.c > index 2b53596c986e0..27f5fe1aa9c44 100644 > --- a/tools/testing/selftests/landlock/tsync_test.c > +++ b/tools/testing/selftests/landlock/tsync_test.c [ ... ] > @@ -231,6 +234,132 @@ TEST(competing_enablement) > EXPECT_EQ(0, close(ruleset_fd)); > } > > +struct sibling_probe { > + pthread_barrier_t *ready; > + pthread_barrier_t *restricted; > + const char *path; > + /* If not zero, the sibling switches to this UID before the enforcement. */ > + uid_t drop_to; > + int drop_result; > + int open_errno_before; > + int open_errno_after; > + int no_new_privs; > + uid_t uid; > +}; > + > +static int open_errno(const char *const path) > +{ > + const int fd = open(path, O_WRONLY | O_CLOEXEC); > + > + if (fd < 0) > + return errno; > + close(fd); > + return 0; > +} > + > +static void *probe_sibling(void *data) > +{ > + struct sibling_probe *const p = data; > + > + /* Unlike setresuid(3), the raw system call only changes this thread. */ > + if (p->drop_to) > + p->drop_result = syscall(SYS_setresuid, p->drop_to, p->drop_to, > + p->drop_to); > + p->open_errno_before = open_errno(p->path); > + pthread_barrier_wait(p->ready); > + > + /* Waits for the other thread's landlock_restrict_self(2) to return. */ > + pthread_barrier_wait(p->restricted); > + p->open_errno_after = open_errno(p->path); > + p->no_new_privs = prctl(PR_GET_NO_NEW_PRIVS, 0, 0, 0, 0); > + p->uid = syscall(SYS_getuid); > + return NULL; > +} [Severity: Low] Can syscall(SYS_getuid) and syscall(SYS_setresuid, ...) break on 32-bit architectures? On 32-bit architectures, SYS_getuid and SYS_setresuid invoke the legacy 16-bit UID syscalls, which fail with ENOSYS when CONFIG_UID16 is disabled or clamp UIDs >= 65536 to 65534 (causing probe.uid to mismatch caller_uid from 32-bit libc getuid() in same_creds). Using getuid() directly for p->uid and preferring SYS_setresuid32 when defined avoids the 16-bit truncation. Also, in TEST_F(tsync_sibling, restricted), hardcoding drop_to to 65534 is a no-op if caller_uid is already 65534. [ ... ] > +FIXTURE_SETUP(tsync_sibling) > +{ > + int fd; > + > + strcpy(self->path, "/tmp/landlock_tsync_XXXXXX"); > + fd = mkstemp(self->path); > + ASSERT_LE(0, fd); > + /* Lets a sibling with another UID write to it before the enforcement. */ > + ASSERT_EQ(0, fchmod(fd, 0666)); > + EXPECT_EQ(0, close(fd)); > + self->ruleset_fd = create_ruleset(_metadata); > +} [Severity: Low] Does FIXTURE_SETUP(tsync_sibling) leak the temporary file in /tmp when create_ruleset() fails? If an assertion fails during FIXTURE_SETUP (for example, inside create_ruleset() when Landlock is disabled), the kselftest harness exits the setup process before clearing no_teardown, so FIXTURE_TEARDOWN never runs to unlink(self->path). Calling create_ruleset(_metadata) before mkstemp(self->path) avoids leaving the file behind. > + > +FIXTURE_TEARDOWN(tsync_sibling) > +{ > + EXPECT_EQ(0, close(self->ruleset_fd)); > + /* LANDLOCK_ACCESS_FS_REMOVE_FILE is not handled by the ruleset. */ > + EXPECT_EQ(0, unlink(self->path)); > +} > + > +/* > + * Checks that a sibling thread is actually restricted once > + * landlock_restrict_self(2) with LANDLOCK_RESTRICT_SELF_TSYNC returns, and > + * that it keeps its own credentials apart from the Landlock domain and > + * no_new_privs. > + */ > +TEST_F(tsync_sibling, restricted) > +{ > + pthread_barrier_t ready, restricted; > + const uid_t caller_uid = getuid(); > + struct sibling_probe probe = { > + .ready = &ready, > + .restricted = &restricted, > + .path = self->path, > + .drop_to = variant->diverged_creds ? 65534 : 0, > + }; > + pthread_t t; > + > + ASSERT_EQ(0, pthread_barrier_init(&ready, NULL, 2)); > + ASSERT_EQ(0, pthread_barrier_init(&restricted, NULL, 2)); > + ASSERT_EQ(0, pthread_create(&t, NULL, probe_sibling, &probe)); > + pthread_barrier_wait(&ready); > + > + disable_caps(_metadata); > + ASSERT_EQ(0, prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0)); > + ASSERT_EQ(0, landlock_restrict_self(self->ruleset_fd, > + LANDLOCK_RESTRICT_SELF_TSYNC)); [Severity: Medium] Does calling disable_caps() after pthread_create() cause the main thread and sibling thread to have diverged credentials even in the same_creds variant? disable_caps() invokes cap_set_secbits() and cap_set_proc(), which allocate and commit a new struct cred on the calling thread only while the sibling thread retains the pre-disable_caps struct cred. When landlock_restrict_self() runs with LANDLOCK_RESTRICT_SELF_TSYNC, current_cred() == ctx->old_cred in restrict_one_thread() is false in both variants, so same_creds never exercises the shared-credential fast path and leaves initial effective capabilities enabled on the sibling thread. In addition, because CAP_SETUID is not raised in CAP_EFFECTIVE via set_cap(_metadata, CAP_SETUID) before SYS_setresuid, running the test as an unprivileged user with file capabilities in CAP_PERMITTED causes SYS_setresuid to fail with EPERM, while running without capabilities causes disable_caps() to fail its EXPECT_* checks before the test can reach SKIP(). Calling disable_caps() before pthread_create() (and bracketing SYS_setresuid with set_cap()/clear_cap() for CAP_SETUID) would keep the credentials shared in same_creds. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261128-b4-tsync-v1-0-31f0c0cef500@northecho.dev?part=2 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 0/2] landlock: Document and test TSYNC on sibling threads 2026-11-28 21:30 [PATCH 0/2] landlock: Document and test TSYNC on sibling threads Christopher Lusk via B4 Relay 2026-11-28 21:30 ` [PATCH 1/2] landlock: Document TSYNC in the inheritance section Christopher Lusk via B4 Relay 2026-11-28 21:30 ` [PATCH 2/2] selftests/landlock: Check that TSYNC restricts sibling threads Christopher Lusk via B4 Relay @ 2026-11-28 21:41 ` sashiko-bot 2 siblings, 0 replies; 5+ messages in thread From: sashiko-bot @ 2026-11-28 21:41 UTC (permalink / raw) Cc: linux-security-module Sashiko has finished reviewing this 2-patch series: - Patch 1: no issues found. - Patch 2 ("selftests/landlock: Check that TSYNC restricts sibli..."): 3 potential issues (1 Medium, 2 Low) A detailed review has been sent as a separate reply to patch 2. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261128-b4-tsync-v1-0-31f0c0cef500@northecho.dev ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-28 21:41 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-28 21:30 [PATCH 0/2] landlock: Document and test TSYNC on sibling threads Christopher Lusk via B4 Relay 2026-11-28 21:30 ` [PATCH 1/2] landlock: Document TSYNC in the inheritance section Christopher Lusk via B4 Relay 2026-11-28 21:30 ` [PATCH 2/2] selftests/landlock: Check that TSYNC restricts sibling threads Christopher Lusk via B4 Relay 2026-11-28 21:41 ` sashiko-bot 2026-11-28 21:41 ` [PATCH 0/2] landlock: Document and test TSYNC on " sashiko-bot
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox