public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Masami Hiramatsu <mhiramat@kernel.org>
To: Punit Agrawal <punitagrawal@gmail.com>
Cc: naveen.n.rao@linux.ibm.com, anil.s.keshavamurthy@intel.com,
	davem@davemloft.net, linux-kernel@vger.kernel.org,
	guoren@kernel.org, linux-csky@vger.kernel.org
Subject: Re: [RFC PATCH 2/5] kprobes: Use helper to parse boolean input from userspace
Date: Wed, 9 Jun 2021 23:37:59 +0900	[thread overview]
Message-ID: <20210609233759.f89ac48532832ac373bb2d02@kernel.org> (raw)
In-Reply-To: <20210609105019.3626677-3-punitagrawal@gmail.com>

On Wed,  9 Jun 2021 19:50:16 +0900
Punit Agrawal <punitagrawal@gmail.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@kernel.org>

Thank you!

> 
> Signed-off-by: Punit Agrawal <punitagrawal@gmail.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@kernel.org>

  reply	other threads:[~2021-06-09 14:38 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-09 10:50 [PATCH 0/5] kprobes: Bugfix and improvements Punit Agrawal
2021-06-09 10:50 ` [PATCH 1/5] kprobes: Do not use local variable when creating debugfs file Punit Agrawal
2021-06-09 14:35   ` Masami Hiramatsu
2021-06-10 23:31     ` Punit Agrawal
2021-06-09 10:50 ` [RFC PATCH 2/5] kprobes: Use helper to parse boolean input from userspace Punit Agrawal
2021-06-09 14:37   ` Masami Hiramatsu [this message]
2021-06-09 10:50 ` [RFC PATCH 3/5] kprobe: Simplify prepare_kprobe() by dropping redundant version Punit Agrawal
2021-06-09 14:42   ` Masami Hiramatsu
2021-06-09 10:50 ` [RFC PATCH 4/5] csky: ftrace: Drop duplicate implementation of arch_check_ftrace_location() Punit Agrawal
2021-06-09 12:33   ` Guo Ren
2021-06-09 14:29     ` Masami Hiramatsu
2021-06-09 15:47       ` Guo Ren
2021-06-10  0:07   ` Masami Hiramatsu
2021-06-09 10:50 ` [RFC PATCH 5/5] kprobes: Make arch_check_ftrace_location static Punit Agrawal
2021-06-10  0:37   ` Masami Hiramatsu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210609233759.f89ac48532832ac373bb2d02@kernel.org \
    --to=mhiramat@kernel.org \
    --cc=anil.s.keshavamurthy@intel.com \
    --cc=davem@davemloft.net \
    --cc=guoren@kernel.org \
    --cc=linux-csky@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=naveen.n.rao@linux.ibm.com \
    --cc=punitagrawal@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox