summaryrefslogtreecommitdiff
path: root/include/linux/tc_act/git@git.tavy.me:linux-stable.git
diff options
context:
space:
mode:
authorKees Cook <kees@kernel.org>2026-03-23 10:17:14 -0700
committerJohannes Berg <johannes.berg@intel.com>2026-03-27 08:21:09 +0100
commit8aae2da6104ab98799b203c10cb3e0bd719fe02b (patch)
treea408375842a078592137133de60b563f195be573 /include/linux/tc_act/git@git.tavy.me:linux-stable.git
parentd1895c15fc7d90a615bc8c455feb02acaf08ef1e (diff)
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>
Diffstat (limited to 'include/linux/tc_act/git@git.tavy.me:linux-stable.git')
0 files changed, 0 insertions, 0 deletions