From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795902118; b=ZuQHJJbxexHrwIfoHinHBOhlKg3uGfBTJCfru65bkyyOyFYFVX7lWWRGUd2yUEOvF4UB KwsFlgmCSWuVLPxcbtslryYIRoHxei05o+QoqU73bo6UaB6TGGRqaPpfCzmOFXIxh0bhH rjznGTAsxHMafWraaZQjqdXbhwfwKrjFZZzOXEu3jWpaHe1mdxzGZN9Y95W/8TeIqHTXv j74RLoVAplF63efw9ylu7eNGnY+j+ap2AFeakvJlovIUtFtewlK0pTfTM3E2p3bnEF9rh omylWuokzVRW69t4yYvHDyv+dosrFiCb9/lUdO6ES1fS5B12qM1DzjfD4wc9T88S+Uw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795902118; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=HVuXQC0LxLDcnkp3zxwPUym3Ai1zGKMW/bdUCdvwXSI=; b=tKNZjb8kVtO6ll8dOTSHzoXmWwWgQkai3xKzlY23tatUnotpaaNsAqRS2Hbodjto+SCc ZU9D6iR6bj3vl+U5LtFLMB64PiRZn/6e9ms0+25869olLBj4YQu+EproQvN3CwPonwjIL hiTYtkFxIwnxJXPUb7h+TTwxbv0TX0VlT8jRrOawYYdNPmwOsAZrxx4w0r/5LD78NwHbU ABmBtbuEA/vuk14tYHGYaUiEJ45SLfrWePBL9OS/9CMD8oVAS22zZsTuG8Pk0hd39ptJx BHyrut5+c8ABmy9wEc228a3oFt1yvW/h7nQej/TgGyvPzDTbbo0Ekz3sWKp+DbKEfFA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=nTLHrMfn; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 04E64606A31C for ; Sat, 28 Nov 2026 21:41:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=nTLHrMfn Received: by smtp.kernel.org (Postfix) with ESMTPSA id 90C481F00897 for ; Sat, 28 Nov 2026 21:41:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795902117; bh=HVuXQC0LxLDcnkp3zxwPUym3Ai1zGKMW/bdUCdvwXSI=; h=From:Subject:Reply-To:Cc:In-Reply-To:References:Date; b=nTLHrMfn8PbzltNWwOj08A0c+kOLgOaFiX5q/MA5o0c+Dvmu9zUcYR+AVZhO8ZYo9 q4XLtFv1bewYmHDEFO3Q7L+1lC0+hwG+nfkScW8+pzUqj7lou5zdE8r/EwRaO0peOh LYL+ktC78Fn6huoDa7NyZ4Tic3I463vNmFSXcIMsrhzNM4C47sSVx/kTXPu5iofOzq AC16990+qowwZyp3mlY789lICXwxI7S/jL+9WQUyKBFUr+gtMUbArQL4cP6Fljx7Jt pFhRM4ZZ3lU+o9TAyfqZMfbEH/f3pO4B2S1Bz+vkcB/lMR9SYr55S3T7XCNIKc5Kf2 hyba2DWWiYwNw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 2/2] selftests/landlock: Check that TSYNC restricts sibling threads Reply-To: sashiko-reviews@lists.linux.dev Cc: linux-security-module@vger.kernel.org In-Reply-To: <20261128-b4-tsync-v1-2-31f0c0cef500@northecho.dev> References: <20261128-b4-tsync-v1-0-31f0c0cef500@northecho.dev> <20261128-b4-tsync-v1-2-31f0c0cef500@northecho.dev> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 28 Nov 2026 21:41:57 +0000 X-Mailing-List: linux-security-module@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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/testin= g/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)); > } > =20 > +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 =3D 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 =3D data; > + > + /* Unlike setresuid(3), the raw system call only changes this thread. */ > + if (p->drop_to) > + p->drop_result =3D syscall(SYS_setresuid, p->drop_to, p->drop_to, > + p->drop_to); > + p->open_errno_before =3D 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 =3D open_errno(p->path); > + p->no_new_privs =3D prctl(PR_GET_NO_NEW_PRIVS, 0, 0, 0, 0); > + p->uid =3D 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 >=3D 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 =3D 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 =3D 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 =3D getuid(); > + struct sibling_probe probe =3D { > + .ready =3D &ready, > + .restricted =3D &restricted, > + .path =3D self->path, > + .drop_to =3D 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() =3D=3D ctx->old_cred in restrict_one_thread() is false in bo= th 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261128-b4-tsync-v= 1-0-31f0c0cef500@northecho.dev?part=3D2