From: Mathias Krause Date: Fri, 7 Jun 2013 00:08:46 +0000 (+1000) Subject: kprobes: handle empty/invalid input to debugfs "enabled" file X-Git-Tag: next-20130607~2^2~234 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=0aec8814080918ab3b15f0bcfaa6a60a5eb1eaa5;p=karo-tx-linux.git kprobes: handle empty/invalid input to debugfs "enabled" file When writing invalid input to 'debug/kprobes/enabled' it'll silently be ignored. Even worse, when writing an empty string to this file, the outcome is purely random as the switch statement will make its decision based on the value of an uninitialized stack variable. Fix this by handling invalid/empty input as error returning -EINVAL. Signed-off-by: Mathias Krause Cc: Ananth N Mavinakayanahalli Cc: Anil S Keshavamurthy Cc: "David S. Miller" Cc: Masami Hiramatsu Signed-off-by: Andrew Morton --- diff --git a/kernel/kprobes.c b/kernel/kprobes.c index 3fed7f0cbcdf..948b597671dd 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -2322,6 +2322,7 @@ static ssize_t write_enabled_file_bool(struct file *file, if (copy_from_user(buf, user_buf, buf_size)) return -EFAULT; + buf[buf_size] = '\0'; switch (buf[0]) { case 'y': case 'Y': @@ -2333,6 +2334,8 @@ static ssize_t write_enabled_file_bool(struct file *file, case '0': disarm_all_kprobes(); break; + default: + return -EINVAL; } return count;