Re: [PATCH] kprobes: handle empty/invalid input to debugfs "enabled"file

From: Masami Hiramatsu
Date: Mon Jun 03 2013 - 01:47:50 EST


(2013/06/01 6:15), Mathias Krause wrote:
> 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.

Oops, right.

>
> Fix this by handling invalid/empty input as error returning -EINVAL.

Thanks!

Reviewed-by: Masami Hiramatsu <masami.hiramatsu.pt@xxxxxxxxxxx>

>
> Cc: Ananth N Mavinakayanahalli <ananth@xxxxxxxxxx>
> Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@xxxxxxxxx>
> Cc: "David S. Miller" <davem@xxxxxxxxxxxxx>
> Cc: Masami Hiramatsu <masami.hiramatsu.pt@xxxxxxxxxxx>
> Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
> Signed-off-by: Mathias Krause <minipli@xxxxxxxxxxxxxx>
> ---
> kernel/kprobes.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> index 3fed7f0..948b597 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;
>


--
Masami HIRAMATSU
IT Management Research Dept. Linux Technology Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: masami.hiramatsu.pt@xxxxxxxxxxx


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/