s390/debug: reject zero-length input before trimming a newline
PATCH 1/1 s390/debug: reject zero-length input before trimming a newline
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.
--- arch/s390/kernel/debug.c | 3 +++ 1 file changed, 3 insertions(+)
arch/s390/kernel/debug.c +3 -0
@@ -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;
Signature · 1 line
2.50.1 (Apple Git-155)
Quoted 11 lines · Pengpeng Hou
debug_get_user_string()duplicates the userspace buffer withmemdup_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")
There shouldn't be a blank line here.
Quoted 10 lines
Signed-off-by Pengpeng Hou <[email protected]>--- arch/s390/kernel/debug.c | 3 +++ 1 file changed, 3 insertions(+)arch/s390/kernel/debug.c +0
-0
arch/s390/kernel/debug.c static inline char *debug_get_user_string(const char __user *user_buf, · line 1422
Quoted 9 lines
arch/s390/kernel/debug.c +3
-0@@ -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;
Otherwise this looks good to me.
Signature · 4 lines
Best Regards, Benjamin Block / Linux on IBM Z Kernel Development IBM Deutschland Research & Development GmbH / https://www.ibm.com/privacy Vors. Aufs.-R.: Wolfgang Wendt / Geschäftsführung: David Faller Sitz der Ges.: Ehningen / Registergericht: AmtsG Stuttgart, HRB 243294
Quoted 7 lines · Pengpeng Hou
debug_get_user_string()duplicates the userspace buffer withmemdup_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.
Quoted 8 lines
Reject empty writes before accessing the last input byte.
Fixes 66a464dbc8e0 ("[PATCH] s390: debug feature changes")Signed-off-by Pengpeng Hou <[email protected]>--- arch/s390/kernel/debug.c | 3 +++ 1 file changed, 3 insertions(+)
Added
Cc: [email protected]
And applied, thank you!
I've also addressed Sashiko's complaint [1] about debug_input_flush_fn() as a separate patch.
[1] https://sashiko.dev/#/patchset/20260417073530.96002-1-pengpeng%40iscas.ac.cn