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] [thread-next>] [day] [month] [year] [list]
Date:	Wed, 10 Sep 2014 19:28:01 -0700
From:	Eric Dumazet <eric.dumazet@...il.com>
To:	John Fastabend <john.fastabend@...il.com>
Cc:	xiyou.wangcong@...il.com, davem@...emloft.net, jhs@...atatu.com,
	netdev@...r.kernel.org, paulmck@...ux.vnet.ibm.com,
	brouer@...hat.com
Subject: Re: [net-next PATCH v4 12/16] net: sched: rcu'ify cls_bpf

On Wed, 2014-09-10 at 08:51 -0700, John Fastabend wrote:
> This patch makes the cls_bpf classifier RCU safe. The tcf_lock
> was being used to protect a list of cls_bpf_prog now this list
> is RCU safe and updates occur with rcu_replace.
> 
> Signed-off-by: John Fastabend <john.r.fastabend@...el.com>

...

> @@ -256,18 +254,19 @@ static int cls_bpf_change(struct net *net, struct sk_buff *in_skb,
>  	if (ret < 0)
>  		return ret;
>  
> -	if (prog != NULL) {
> -		if (handle && prog->handle != handle)
> -			return -EINVAL;
> -		return cls_bpf_modify_existing(net, tp, prog, base, tb,
> -					       tca[TCA_RATE], ovr);
> -	}
> -
>  	prog = kzalloc(sizeof(*prog), GFP_KERNEL);
> -	if (prog == NULL)
> +	if (!prog)
>  		return -ENOBUFS;
>  
>  	tcf_exts_init(&prog->exts, TCA_BPF_ACT, TCA_BPF_POLICE);
> +
> +	if (oldprog) {
> +		if (handle && oldprog->handle != handle) {
> +			ret = -EINVAL;
> +			goto errout;
> +		}
> +	}
> +
>  	if (handle == 0)
>  		prog->handle = cls_bpf_grab_new_handle(tp, head);
>  	else
> @@ -281,15 +280,17 @@ static int cls_bpf_change(struct net *net, struct sk_buff *in_skb,
>  	if (ret < 0)
>  		goto errout;
>  
> -	tcf_tree_lock(tp);
> -	list_add(&prog->link, &head->plist);
> -	tcf_tree_unlock(tp);
> +	if (oldprog) {
> +		list_replace_rcu(&prog->link, &oldprog->link);
> +		call_rcu(&oldprog->rcu, __cls_bpf_delete_prog);
> +	} else {
> +		list_add_rcu(&prog->link, &head->plist);
> +	}
>  
>  	*arg = (unsigned long) prog;
> -
>  	return 0;
>  errout:
> -	if (*arg == 0UL && prog)
> +	if (prog)
>  		kfree(prog);
>  

nit, you can directly call kfree(prog) even if prog == NULL



--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ