From: "Eric W. Biederman" <ebiederm@xmission.com>
To: Natasha Klaus <natalie.klaus@runtimeverification.com>
Cc: Christian Brauner <brauner@kernel.org>,
Kees Cook <kees@kernel.org>, Shuah Khan <shuah@kernel.org>,
Jeff Layton <jlayton@kernel.org>,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 0/2] userns: reject out-of-range uid_map/gid_map values
Date: Mon, 28 Sep 2026 08:58:46 -0500 [thread overview]
Message-ID: <87tsn932ax.fsf@email.froward.int.ebiederm.org> (raw)
In-Reply-To: <20260928072537.115668-1-natalie.klaus@runtimeverification.com> (Natasha Klaus's message of "Mon, 28 Sep 2026 10:25:35 +0300")
Natasha Klaus <natalie.klaus@runtimeverification.com> writes:
> map_write() silently truncates uid_map/gid_map/projid_map values above
> U32_MAX modulo 2^32 on 64-bit kernels, so e.g. "4294967301 1000 1" is
> installed as "5 1000 1" without an error. Patch 1 rejects such values
> with -EINVAL. Patch 2 adds a selftest for all three fields and for the
> unchanged in-range path.
>
> This is hardening, not a security fix.
Well error in more cases. *Shrug* I don't think that even really
hardens anything but it is moderately more correct.
> The patch and the selftest were drafted by Claude Code (Claude Opus 5.5)
> in an interactive session; I reviewed, built and tested them. The
> assistant flagged the truncation while reading map_write(), and I
> confirmed it by writing to uid_map on a running kernel.
>
> Tested on v7.3-rc4-393-g165768bb7026 under virtme-ng, x86_64 defconfig
> with CONFIG_USER_NS: all five selftest cases pass on the patched kernel.
> On an unpatched 6.8 host, four of the five fail as expected.
Storing an unsigned long into an unsigned long long instead of an
unsigned is a mistake in the opposite direction and is more costly.
A more targeted fix would be to replace simple_strtoul with
kstrtou32.
As for tests you probably also want to test some negative values as
well, and probably a few good values.
Eric
>
> Natasha Klaus (2):
> userns: reject uid_map/gid_map values that do not fit in u32
> selftests/namespaces: add uid_map/gid_map range tests
>
> kernel/user_namespace.c | 14 +-
> tools/testing/selftests/namespaces/.gitignore | 1 +
> tools/testing/selftests/namespaces/Makefile | 3 +-
> .../selftests/namespaces/uid_map_range_test.c | 155 ++++++++++++++++++
> 4 files changed, 169 insertions(+), 4 deletions(-)
> create mode 100644 tools/testing/selftests/namespaces/uid_map_range_test.c
>
>
> base-commit: 165768bb70265b5c38cf0b73fafd75be235f8b14
prev parent reply other threads:[~2026-09-28 14:24 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-28 7:25 Natasha Klaus
2026-09-28 7:25 ` [PATCH 1/2] userns: reject uid_map/gid_map values that do not fit in u32 Natasha Klaus
2026-09-28 7:25 ` [PATCH 2/2] selftests/namespaces: add uid_map/gid_map range tests Natasha Klaus
2026-09-28 13:58 ` Eric W. Biederman [this message]
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=87tsn932ax.fsf@email.froward.int.ebiederm.org \
--to=ebiederm@xmission.com \
--cc=brauner@kernel.org \
--cc=jlayton@kernel.org \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=natalie.klaus@runtimeverification.com \
--cc=shuah@kernel.org \
/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
all inboxes | Powered by JetHome®