diff options
| author | Natasha Klaus <natalie.klaus@runtimeverification.com> | 2026-09-30 14:28:53 +0300 |
|---|---|---|
| committer | Christian Brauner <brauner@kernel.org> | 2026-10-12 11:01:20 +0200 |
| commit | 09a71b58a25d8166b6aed491c87d3c1e4425c702 (patch) | |
| tree | fdf212fa99f66ae9b0064b1afdb0989a5cf5b853 /tools/lib/python/kdoc/python_version.py | |
| parent | 15aa70de9f706fb0e3852f636b8a0a9d5bc048ab (diff) | |
| download | linux-next-09a71b58a25d8166b6aed491c87d3c1e4425c702.tar.gz linux-next-09a71b58a25d8166b6aed491c87d3c1e4425c702.zip | |
userns: reject uid_map/gid_map values that do not fit in u32
map_write() parses each line written to uid_map, gid_map or projid_map
with simple_strtoul() and stores the results in the u32 fields of
struct uid_gid_extent. On 64-bit kernels a value above U32_MAX is
silently truncated modulo 2^32. The coding assistant flagged this
truncation site while reading map_write(), and I confirmed it by hand
on a running kernel, where writing to the uid_map of a fresh user
namespace installs a different mapping than the one requested:
"4294967296 1000 1" -> installed as "0 1000 1"
"4294967297 1000 1" -> installed as "1 1000 1"
"4294967301 1000 1" -> installed as "5 1000 1"
The same happens to the lower_first and count fields. Only a literal of
2^64 or more is rejected, and only because simple_strtoul() saturates
to ULLONG_MAX, which truncates onto the (u32)-1 value map_write()
already refuses. On 32-bit kernels unsigned long is itself 32 bits
wide, so the same truncation happens inside simple_strtoul().
The write succeeds, so a runtime that computes ranges and gets one
wrong ends up with a different map than it asked for and no error to
tell it so.
Parse each field with kstrtou32() instead. A new helper,
map_parse_u32(), terminates the field at the next whitespace or NUL,
parses it and puts the original character back, leaving pos where
simple_strtoul() used to leave it. The checks after each field, the
trailing junk check and every later check are unchanged and run in the
same order. A field that is not a decimal number fitting in u32 now
fails the write with -EINVAL, like any other malformed line.
Besides the range check, the one visible difference is that kstrtou32()
accepts a single leading '+', so "+5 1000 1" is now installed as
"5 1000 1" where it used to be rejected.
This makes the parser more correct; it is not a security fix: the
truncated values are valid ids and every later check still applies to
them.
Suggested-by: Eric W. Biederman <ebiederm@xmission.com>
Signed-off-by: Natasha Klaus <natalie.klaus@runtimeverification.com>
Link: https://patch.msgid.link/20260930112854.373184-2-natalie.klaus@runtimeverification.com
Acked-by: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Diffstat (limited to 'tools/lib/python/kdoc/python_version.py')
0 files changed, 0 insertions, 0 deletions
