From: sashiko-bot@kernel.org
Cc: linux-security-module@vger.kernel.org
Subject: Re: [PATCH v5 5/8] selftests/landlock: Add namespace restriction tests
Date: Wed, 07 Oct 2026 10:23:01 +0000 [thread overview]
Message-ID: <sashiko-outbox-162856@kernel.org> (raw)
In-Reply-To: <20261007100255.1333386-6-mic@digikod.net>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] selftests: Build failure due to missing AT_RECURSIVE macro definition
- [Low] selftests: Missing clear_cap() for CAP_SYS_CHROOT in combined_cap_ns test
- [Low] selftests: is_in_init_user_ns() misidentifies user namespaces in unprivileged containers
--
commit aa1731ea4300b766831441aec03fce370fdad94e
Author: Mickaël Salaün <mic@digikod.net>
selftests/landlock: Add namespace restriction tests
Add tests covering LANDLOCK_PERMISSION_NAMESPACE_USE (namespace creation
via unshare/clone and namespace entry via setns) and its interaction
with LANDLOCK_PERMISSION_CAPABILITY_USE.
> diff --git a/tools/testing/selftests/landlock/common.h b/tools/testing/selftests/landlock/common.h
> --- a/tools/testing/selftests/landlock/common.h
> +++ b/tools/testing/selftests/landlock/common.h
> @@ -130,6 +130,29 @@ static void __maybe_unused clear_ambient_cap(
> EXPECT_EQ(0, cap_get_ambient(cap));
> }
>
> +/*
> + * Returns true if the current process is in the initial user namespace.
> + * Compares the readlink targets of /proc/self/ns/user and /proc/1/ns/user.
> + */
> +static bool __maybe_unused is_in_init_user_ns(void)
> +{
[ ... ]
> + if (self_len != init_len)
> + return false;
> +
> + return memcmp(self_buf, init_buf, self_len) == 0;
> +}
[Severity: Low]
Is it possible for this check to misidentify the initial user namespace when
running in an unprivileged container?
In a container with its own PID namespace, PID 1 refers to the container's
init, which shares the container's user namespace. This causes the function
to incorrectly return true.
This can result in the test proceeding and attempting host-only operations:
> diff --git a/tools/testing/selftests/landlock/ns_test.c b/tools/testing/selftests/landlock/ns_test.c
> new file mode 100644
> --- /dev/null
> +++ b/tools/testing/selftests/landlock/ns_test.c
[ ... ]
> +FIXTURE_SETUP(ns_audit)
> +{
> + ASSERT_TRUE(is_in_init_user_ns());
> +
> + disable_caps(_metadata);
> +
> + set_cap(_metadata, CAP_AUDIT_CONTROL);
> + self->audit_fd = audit_init_with_exe_filter(&self->audit_filter);
> + EXPECT_LE(0, self->audit_fd);
If the environment is misidentified, audit_init_with_exe_filter() will fail
with a misleading -EPERM error instead of explicitly failing the environment
check or skipping the test cleanly.
[ ... ]
> +TEST(combined_cap_ns)
> +{
[ ... ]
> + /* CAP_SYS_ADMIN use allowed by capability rule. */
> + set_cap(_metadata, CAP_SYS_ADMIN);
> + EXPECT_EQ(0, sethostname("test", 4));
> + clear_cap(_metadata, CAP_SYS_ADMIN);
> +
> + /* CAP_SYS_CHROOT denied (not in allowed capability rules). */
> + set_cap(_metadata, CAP_SYS_CHROOT);
> + EXPECT_EQ(-1, chroot("/"));
> + EXPECT_EQ(EPERM, errno);
[Severity: Low]
Should clear_cap(_metadata, CAP_SYS_CHROOT) be called after this check to
avoid leaving the capability unintentionally active for the remainder of the
test?
[ ... ]
> +TEST_F(ns_mount_fd, open_tree_clone)
> +{
[ ... ]
> + set_cap(_metadata, CAP_SYS_ADMIN);
> + fd = sys_open_tree(AT_FDCWD, "/",
> + OPEN_TREE_CLONE | OPEN_TREE_CLOEXEC | AT_RECURSIVE);
[Severity: Medium]
Will this fail to compile on older distributions due to a missing
AT_RECURSIVE definition?
sys_open_tree() is called with the AT_RECURSIVE flag, but the file includes
<fcntl.h> instead of the kernel's <linux/fcntl.h>. Older glibc versions do
not define AT_RECURSIVE in their userspace headers.
Without an explicit fallback definition or an inclusion of <linux/fcntl.h>,
compiling these selftests could result in an 'AT_RECURSIVE undeclared' error.
This also applies to the usage in open_tree_namespace:
> +TEST_F(ns_mount_fd, open_tree_namespace)
> +{
[ ... ]
> + set_cap(_metadata, CAP_SYS_ADMIN);
> + fd = sys_open_tree(AT_FDCWD, "/",
> + OPEN_TREE_NAMESPACE | OPEN_TREE_CLOEXEC |
> + AT_RECURSIVE);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261007100255.1333386-1-mic@digikod.net?part=5
next prev parent reply other threads:[~2026-10-07 10:23 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-07 10:02 [PATCH v5 0/8] Landlock: Namespace and capability control Mickaël Salaün
2026-10-07 10:02 ` [PATCH v5 1/8] landlock: Rename quiet_masks to quiet_access Mickaël Salaün
2026-10-07 10:09 ` sashiko-bot
2026-10-07 10:02 ` [PATCH v5 2/8] landlock: Wrap per-layer access masks in struct layer_config Mickaël Salaün
2026-10-07 10:10 ` sashiko-bot
2026-10-07 10:02 ` [PATCH v5 3/8] landlock: Enforce namespace use restrictions Mickaël Salaün
2026-10-07 10:15 ` sashiko-bot
2026-10-07 10:02 ` [PATCH v5 4/8] landlock: Enforce capability restrictions Mickaël Salaün
2026-10-07 10:11 ` sashiko-bot
2026-10-07 10:02 ` [PATCH v5 5/8] selftests/landlock: Add namespace restriction tests Mickaël Salaün
2026-10-07 10:23 ` sashiko-bot [this message]
2026-10-07 10:02 ` [PATCH v5 6/8] selftests/landlock: Add capability " Mickaël Salaün
2026-10-07 10:13 ` sashiko-bot
2026-10-07 10:02 ` [PATCH v5 7/8] samples/landlock: Add capability and namespace restriction support Mickaël Salaün
2026-10-07 10:11 ` sashiko-bot
2026-10-07 10:02 ` [PATCH v5 8/8] landlock: Add documentation for capability and namespace restrictions Mickaël Salaün
2026-10-07 10:10 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-162856@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox