Commit 5d6de7d7 authored by Punit Agrawal's avatar Punit Agrawal Committed by Steven Rostedt (VMware)

kprobes: Use helper to parse boolean input from userspace

The "enabled" file provides a debugfs interface to arm / disarm
kprobes in the kernel. In order to parse the buffer containing the
values written from userspace, the callback manually parses the user
input to convert it to a boolean value.

As taking a string value from userspace and converting it to boolean
is a common operation, a helper kstrtobool_from_user() is already
available in the kernel. Update the callback to use the common helper
to parse the write buffer from userspace.

Link: https://lkml.kernel.org/r/163163032637.489837.10678039554832855327.stgit@devnote2Signed-off-by: default avatarPunit Agrawal <punitagrawal@gmail.com>
Acked-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
parent 8f7262cd
...@@ -2770,30 +2770,14 @@ static ssize_t read_enabled_file_bool(struct file *file, ...@@ -2770,30 +2770,14 @@ static ssize_t read_enabled_file_bool(struct file *file,
static ssize_t write_enabled_file_bool(struct file *file, static ssize_t write_enabled_file_bool(struct file *file,
const char __user *user_buf, size_t count, loff_t *ppos) const char __user *user_buf, size_t count, loff_t *ppos)
{ {
char buf[32]; bool enable;
size_t buf_size; int ret;
int ret = 0;
buf_size = min(count, (sizeof(buf)-1));
if (copy_from_user(buf, user_buf, buf_size))
return -EFAULT;
buf[buf_size] = '\0'; ret = kstrtobool_from_user(user_buf, count, &enable);
switch (buf[0]) { if (ret)
case 'y': return ret;
case 'Y':
case '1':
ret = arm_all_kprobes();
break;
case 'n':
case 'N':
case '0':
ret = disarm_all_kprobes();
break;
default:
return -EINVAL;
}
ret = enable ? arm_all_kprobes() : disarm_all_kprobes();
if (ret) if (ret)
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment