[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210609233759.f89ac48532832ac373bb2d02@kernel.org>
Date: Wed, 9 Jun 2021 23:37:59 +0900
From: Masami Hiramatsu <mhiramat@...nel.org>
To: Punit Agrawal <punitagrawal@...il.com>
Cc: naveen.n.rao@...ux.ibm.com, anil.s.keshavamurthy@...el.com,
davem@...emloft.net, linux-kernel@...r.kernel.org,
guoren@...nel.org, linux-csky@...r.kernel.org
Subject: Re: [RFC PATCH 2/5] kprobes: Use helper to parse boolean input from
userspace
On Wed, 9 Jun 2021 19:50:16 +0900
Punit Agrawal <punitagrawal@...il.com> wrote:
> 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.
Looks good to me.
Acked-by: Masami Hiramatsu <mhiramat@...nel.org>
Thank you!
>
> Signed-off-by: Punit Agrawal <punitagrawal@...il.com>
> ---
> kernel/kprobes.c | 28 ++++++----------------------
> 1 file changed, 6 insertions(+), 22 deletions(-)
>
> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> index fdb1ea2e963b..1a11d3c411bf 100644
> --- a/kernel/kprobes.c
> +++ b/kernel/kprobes.c
> @@ -2777,30 +2777,14 @@ static ssize_t read_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)
> {
> - char buf[32];
> - size_t buf_size;
> - int ret = 0;
> -
> - buf_size = min(count, (sizeof(buf)-1));
> - if (copy_from_user(buf, user_buf, buf_size))
> - return -EFAULT;
> + bool enable;
> + int ret;
>
> - buf[buf_size] = '\0';
> - switch (buf[0]) {
> - case 'y':
> - case 'Y':
> - case '1':
> - ret = arm_all_kprobes();
> - break;
> - case 'n':
> - case 'N':
> - case '0':
> - ret = disarm_all_kprobes();
> - break;
> - default:
> - return -EINVAL;
> - }
> + ret = kstrtobool_from_user(user_buf, count, &enable);
> + if (ret)
> + return ret;
>
> + ret = enable ? arm_all_kprobes() : disarm_all_kprobes();
> if (ret)
> return ret;
>
> --
> 2.30.2
>
--
Masami Hiramatsu <mhiramat@...nel.org>
Powered by blists - more mailing lists