mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Masami Hiramatsu <mhiramat@kernel.org>
To: Zhou Chengming <zhouchengming1@huawei.com>
Cc: <ananth@linux.vnet.ibm.com>, <anil.s.keshavamurthy@intel.com>,
	<davem@davemloft.net>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v3 1/2] kprobes: avoid the kprobe being re-registered
Date: Sat, 28 Oct 2017 17:46:53 +0900	[thread overview]
Message-ID: <20171028174653.eb03d7f20107d266f4d46c46@kernel.org> (raw)
In-Reply-To: <1509096195-21734-1-git-send-email-zhouchengming1@huawei.com>

On Fri, 27 Oct 2017 17:23:14 +0800
Zhou Chengming <zhouchengming1@huawei.com> wrote:

> Changes:
> - We should put the modifies of the kprobe after the re-reg check.
> - And then the address_safe check.
> 
> Old code use check_kprobe_rereg() to check if the kprobe has been
> registered already, but check_kprobe_rereg() will release the
> kprobe_mutex then, so maybe two paths will pass the check and
> register the same kprobe. This patch put the check inside the mutex.
> 
> Suggested-by: Masami Hiramatsu <mhiramat@kernel.org>
> Signed-off-by: Zhou Chengming <zhouchengming1@huawei.com>

Looks good to me :)

Acked-by: Masami Hiramatsu <mhiramat@kernel.org>

Thanks!

> ---
>  kernel/kprobes.c | 27 ++++++++-------------------
>  1 file changed, 8 insertions(+), 19 deletions(-)
> 
> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> index a1606a4..1eeedac 100644
> --- a/kernel/kprobes.c
> +++ b/kernel/kprobes.c
> @@ -1443,19 +1443,6 @@ static struct kprobe *__get_valid_kprobe(struct kprobe *p)
>  	return ap;
>  }
>  
> -/* Return error if the kprobe is being re-registered */
> -static inline int check_kprobe_rereg(struct kprobe *p)
> -{
> -	int ret = 0;
> -
> -	mutex_lock(&kprobe_mutex);
> -	if (__get_valid_kprobe(p))
> -		ret = -EINVAL;
> -	mutex_unlock(&kprobe_mutex);
> -
> -	return ret;
> -}
> -
>  int __weak arch_check_ftrace_location(struct kprobe *p)
>  {
>  	unsigned long ftrace_addr;
> @@ -1536,9 +1523,13 @@ int register_kprobe(struct kprobe *p)
>  		return PTR_ERR(addr);
>  	p->addr = addr;
>  
> -	ret = check_kprobe_rereg(p);
> -	if (ret)
> -		return ret;
> +	mutex_lock(&kprobe_mutex);
> +
> +	/* Return error if the kprobe is being re-registered */
> +	if (__get_valid_kprobe(p)) {
> +		ret = -EINVAL;
> +		goto out;
> +	}
>  
>  	/* User can pass only KPROBE_FLAG_DISABLED to register_kprobe */
>  	p->flags &= KPROBE_FLAG_DISABLED;
> @@ -1547,9 +1538,7 @@ int register_kprobe(struct kprobe *p)
>  
>  	ret = check_kprobe_address_safe(p, &probed_mod);
>  	if (ret)
> -		return ret;
> -
> -	mutex_lock(&kprobe_mutex);
> +		goto out;
>  
>  	old_p = get_kprobe(p->addr);
>  	if (old_p) {
> -- 
> 1.8.3.1
> 


-- 
Masami Hiramatsu <mhiramat@kernel.org>

      parent reply	other threads:[~2017-10-28  8:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-27  9:23 Zhou Chengming
2017-10-27  9:23 ` [PATCH v3 2/2] kprobes: initialize probed_mod to NULL Zhou Chengming
2017-10-28  8:47   ` Masami Hiramatsu
2017-10-28  8:46 ` Masami Hiramatsu [this message]

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=20171028174653.eb03d7f20107d266f4d46c46@kernel.org \
    --to=mhiramat@kernel.org \
    --cc=ananth@linux.vnet.ibm.com \
    --cc=anil.s.keshavamurthy@intel.com \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=zhouchengming1@huawei.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

Powered by JetHome