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: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20171031093349.ozyzbl33vkdjmyam@hirez.programming.kicks-ass.net>
Date:   Tue, 31 Oct 2017 10:33:49 +0100
From:   Peter Zijlstra <peterz@...radead.org>
To:     Yonghong Song <yhs@...com>
Cc:     rostedt@...dmis.org, ast@...com, daniel@...earbox.net,
        kafai@...com, netdev@...r.kernel.org, kernel-team@...com
Subject: Re: [PATCH net-next] bpf: avoid rcu_dereference inside
 bpf_event_mutex lock region

On Mon, Oct 30, 2017 at 01:50:22PM -0700, Yonghong Song wrote:
> Could you check whether the below change to remove rcu_dereference_protected
> is what you wanted or not?

Yep that looks fine. Thanks!

> diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
> index b65011d..e7685c5 100644
> --- a/kernel/trace/bpf_trace.c
> +++ b/kernel/trace/bpf_trace.c
> @@ -767,20 +767,19 @@ int perf_event_attach_bpf_prog(struct perf_event *event,
>  	mutex_lock(&bpf_event_mutex);
>  
>  	if (event->prog)
> -		goto out;
> +		goto unlock;
>  
> -	old_array = rcu_dereference_protected(event->tp_event->prog_array,
> -					      lockdep_is_held(&bpf_event_mutex));
> +	old_array = event->tp_event->prog_array;
>  	ret = bpf_prog_array_copy(old_array, NULL, prog, &new_array);
>  	if (ret < 0)
> -		goto out;
> +		goto unlock;
>  
>  	/* set the new array to event->tp_event and set event->prog */
>  	event->prog = prog;
>  	rcu_assign_pointer(event->tp_event->prog_array, new_array);
>  	bpf_prog_array_free(old_array);
>  
> -out:
> +unlock:
>  	mutex_unlock(&bpf_event_mutex);
>  	return ret;
>  }
> @@ -794,11 +793,9 @@ void perf_event_detach_bpf_prog(struct perf_event *event)
>  	mutex_lock(&bpf_event_mutex);
>  
>  	if (!event->prog)
> -		goto out;
> -
> -	old_array = rcu_dereference_protected(event->tp_event->prog_array,
> -					      lockdep_is_held(&bpf_event_mutex));
> +		goto unlock;
>  
> +	old_array = event->tp_event->prog_array;
>  	ret = bpf_prog_array_copy(old_array, event->prog, NULL, &new_array);
>  	if (ret < 0) {
>  		bpf_prog_array_delete_safe(old_array, event->prog);
> @@ -810,6 +807,6 @@ void perf_event_detach_bpf_prog(struct perf_event *event)
>  	bpf_prog_put(event->prog);
>  	event->prog = NULL;
>  
> -out:
> +unlock:
>  	mutex_unlock(&bpf_event_mutex);
>  }
> -- 
> 2.9.5
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ