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
Showing the changes to kernel (1 of 1 file). Show all
Unified · Split
| @@ -2770,30 +2770,14 @@ static ssize_t read_enabled_file_bool(struct file *file, · 2769 unmodified lines | ||
| 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; | |
| 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; | |
| 2780 | 2775 | |
| 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; | |
| 2796 | 2779 | |
| 2780 | + ret = enable ? arm_all_kprobes() : disarm_all_kprobes(); | |
| 2797 | 2781 | if (ret) |
| 2798 | 2782 | return ret; |
| 2799 | 2783 | |