]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
s390/debug: Reject zero-length input before trimming a newline
authorPengpeng Hou <pengpeng@iscas.ac.cn>
Fri, 17 Apr 2026 07:35:30 +0000 (15:35 +0800)
committerAlexander Gordeev <agordeev@linux.ibm.com>
Tue, 28 Apr 2026 12:45:02 +0000 (14:45 +0200)
debug_get_user_string() duplicates the userspace buffer with
memdup_user_nul() and then unconditionally looks at buffer[user_len - 1]
to strip a trailing newline.

A zero-length write reaches this helper unchanged, so the newline trim
reads before the start of the allocated buffer.

Reject empty writes before accessing the last input byte.

Fixes: 66a464dbc8e0 ("[PATCH] s390: debug feature changes")
Cc: stable@vger.kernel.org
Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>
Reviewed-by: Benjamin Block <bblock@linux.ibm.com>
Reviewed-by: Vasily Gorbik <gor@linux.ibm.com>
Tested-by: Vasily Gorbik <gor@linux.ibm.com>
Link: https://lore.kernel.org/r/20260417073530.96002-1-pengpeng@iscas.ac.cn
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
arch/s390/kernel/debug.c

index 31430e9bcfdd9d479f88d4b3d576a5e74ef0ad0b..2612f634e8262ffaaab95668ad928aeed7d4e576 100644 (file)
@@ -1414,6 +1414,9 @@ static inline char *debug_get_user_string(const char __user *user_buf,
 {
        char *buffer;
 
+       if (!user_len)
+               return ERR_PTR(-EINVAL);
+
        buffer = memdup_user_nul(user_buf, user_len);
        if (IS_ERR(buffer))
                return buffer;