Skip to content

Commit 5d6de7d

Browse files
punitagrawalrostedt
authored andcommitted
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@devnote2 Signed-off-by: Punit Agrawal <[email protected]> Acked-by: Masami Hiramatsu <[email protected]> Signed-off-by: Masami Hiramatsu <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 8f7262c commit 5d6de7d

File tree

1 file changed

+6
-22
lines changed

1 file changed

+6
-22
lines changed

kernel/kprobes.c

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2770,30 +2770,14 @@ static ssize_t read_enabled_file_bool(struct file *file,
27702770
static ssize_t write_enabled_file_bool(struct file *file,
27712771
const char __user *user_buf, size_t count, loff_t *ppos)
27722772
{
2773-
char buf[32];
2774-
size_t buf_size;
2775-
int ret = 0;
2776-
2777-
buf_size = min(count, (sizeof(buf)-1));
2778-
if (copy_from_user(buf, user_buf, buf_size))
2779-
return -EFAULT;
2773+
bool enable;
2774+
int ret;
27802775

2781-
buf[buf_size] = '\0';
2782-
switch (buf[0]) {
2783-
case 'y':
2784-
case 'Y':
2785-
case '1':
2786-
ret = arm_all_kprobes();
2787-
break;
2788-
case 'n':
2789-
case 'N':
2790-
case '0':
2791-
ret = disarm_all_kprobes();
2792-
break;
2793-
default:
2794-
return -EINVAL;
2795-
}
2776+
ret = kstrtobool_from_user(user_buf, count, &enable);
2777+
if (ret)
2778+
return ret;
27962779

2780+
ret = enable ? arm_all_kprobes() : disarm_all_kprobes();
27972781
if (ret)
27982782
return ret;
27992783

0 commit comments

Comments
 (0)