linux/arch/um/kernel/skas
Kees Cook 8aae2da610 um: Replace strncpy() with strnlen()+memcpy_and_pad() in strncpy_chunk_from_user()
Replace the deprecated[1] strncpy() with strnlen() on the source
followed by memcpy_and_pad().

This function is a chunk callback for UML's strncpy_from_user()
implementation, called by buffer_op() to process userspace memory one
page at a time. The source is a kernel-mapped userspace address that
is not guaranteed to be NUL-terminated; "len" bounds how many bytes
to read from it.

By measuring the source string length first with strnlen(), we avoid
reading past the NUL terminator in the source. memcpy_and_pad() then
copies the string content and zero-fills the remainder of the chunk,
preserving the original strncpy() behavior exactly: copy up to the
first NUL, then pad with zeros to the full length.

strtomem_pad() would be the idiomatic helper for this strnlen() +
memcpy_and_pad() pattern, but it requires a compile-time-determinable
destination size (via ARRAY_SIZE()). Here the destination is a char *
into a caller-provided buffer and the chunk length is a runtime value,
so the explicit two-step is necessary.

No behavioral change: the same bytes are written to the destination
(string content followed by zero padding), the pointer advances by
the same amount, and the NUL-found return condition is unchanged.

Link: https://github.com/KSPP/linux/issues/90 [1]
Signed-off-by: Kees Cook <kees@kernel.org>
Link: https://patch.msgid.link/20260323171713.work.839-kees@kernel.org
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
2026-03-27 08:21:09 +01:00
..
.gitignore um: use execveat to create userspace MMs 2024-10-10 13:37:16 +02:00
Makefile um: fix stub exe build with CONFIG_GCOV 2024-10-26 16:06:10 +02:00
mmu.c um: Fix incorrect __acquires/__releases annotations 2026-01-05 16:43:32 +01:00
process.c um: Add initial SMP support 2025-10-27 16:41:15 +01:00
stub_exe_embed.S um: use execveat to create userspace MMs 2024-10-10 13:37:16 +02:00
stub_exe.c um: pass FD for memory operations when needed 2025-06-02 16:20:10 +02:00
stub.c um: fix address-of CMSG_DATA() rvalue in stub 2026-03-21 10:41:44 +01:00
syscall.c um: simplify syscall header files 2025-07-11 08:49:02 +02:00
uaccess.c um: Replace strncpy() with strnlen()+memcpy_and_pad() in strncpy_chunk_from_user() 2026-03-27 08:21:09 +01:00