* [PATCH] kprobes: handle empty/invalid input to debugfs "enabled" file
@ 2013-05-31 21:15 Mathias Krause
2013-06-03 5:47 ` Masami Hiramatsu
0 siblings, 1 reply; 2+ messages in thread
From: Mathias Krause @ 2013-05-31 21:15 UTC (permalink / raw)
To: Ananth N Mavinakayanahalli, Anil S Keshavamurthy,
Masami Hiramatsu
Cc: linux-kernel, Mathias Krause, David S. Miller, Andrew Morton
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.
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Mathias Krause <minipli@googlemail.com>
---
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;
--
1.7.10.4
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] kprobes: handle empty/invalid input to debugfs "enabled" file
2013-05-31 21:15 [PATCH] kprobes: handle empty/invalid input to debugfs "enabled" file Mathias Krause
@ 2013-06-03 5:47 ` Masami Hiramatsu
0 siblings, 0 replies; 2+ messages in thread
From: Masami Hiramatsu @ 2013-06-03 5:47 UTC (permalink / raw)
To: Mathias Krause
Cc: Ananth N Mavinakayanahalli, Anil S Keshavamurthy, linux-kernel,
David S. Miller, Andrew Morton, yrl.pp-manager.tt@hitachi.com
(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@hitachi.com>
>
> Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
> Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Mathias Krause <minipli@googlemail.com>
> ---
> 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@hitachi.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-06-03 5:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-31 21:15 [PATCH] kprobes: handle empty/invalid input to debugfs "enabled" file Mathias Krause
2013-06-03 5:47 ` Masami Hiramatsu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox