lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Sat, 28 Oct 2017 17:46:53 +0900
From:   Masami Hiramatsu <mhiramat@...nel.org>
To:     Zhou Chengming <zhouchengming1@...wei.com>
Cc:     <ananth@...ux.vnet.ibm.com>, <anil.s.keshavamurthy@...el.com>,
        <davem@...emloft.net>, <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v3 1/2] kprobes: avoid the kprobe being re-registered

On Fri, 27 Oct 2017 17:23:14 +0800
Zhou Chengming <zhouchengming1@...wei.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@...nel.org>
> Signed-off-by: Zhou Chengming <zhouchengming1@...wei.com>

Looks good to me :)

Acked-by: Masami Hiramatsu <mhiramat@...nel.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@...nel.org>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ