Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <punitagrawal@gmail.com>
Acked-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

authored by

Punit Agrawal and committed by
Steven Rostedt (VMware)
5d6de7d7 8f7262cd

+6 -22
+6 -22
kernel/kprobes.c
··· 2770 2770 static ssize_t write_enabled_file_bool(struct file *file, 2771 2771 const char __user *user_buf, size_t count, loff_t *ppos) 2772 2772 { 2773 - char buf[32]; 2774 - size_t buf_size; 2775 - int ret = 0; 2773 + bool enable; 2774 + int ret; 2776 2775 2777 - buf_size = min(count, (sizeof(buf)-1)); 2778 - if (copy_from_user(buf, user_buf, buf_size)) 2779 - return -EFAULT; 2776 + ret = kstrtobool_from_user(user_buf, count, &enable); 2777 + if (ret) 2778 + return ret; 2780 2779 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 - } 2796 - 2780 + ret = enable ? arm_all_kprobes() : disarm_all_kprobes(); 2797 2781 if (ret) 2798 2782 return ret; 2799 2783