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:   Sun, 22 Sep 2019 08:37:30 -0400
From:   "Michael S. Tsirkin" <mst@...hat.com>
To:     Matthew Cover <werekraken@...il.com>
Cc:     davem@...emloft.net, ast@...nel.org, daniel@...earbox.net,
        kafai@...com, songliubraving@...com, yhs@...com,
        jasowang@...hat.com, edumazet@...gle.com, sdf@...gle.com,
        matthew.cover@...ckpath.com, mail@...urcelik.de, pabeni@...hat.com,
        nicolas.dichtel@...nd.com, wangli39@...du.com,
        lifei.shirley@...edance.com, tglx@...utronix.de,
        netdev@...r.kernel.org, linux-kernel@...r.kernel.org,
        bpf@...r.kernel.org
Subject: Re: [PATCH net-next] tuntap: Fallback to automq on
 TUNSETSTEERINGEBPF prog negative return

On Fri, Sep 20, 2019 at 11:58:43AM -0700, Matthew Cover wrote:
> Treat a negative return from a TUNSETSTEERINGEBPF bpf prog as a signal
> to fallback to tun_automq_select_queue() for tx queue selection.
> 
> Compilation of this exact patch was tested.
> 
> For functional testing 3 additional printk()s were added.
> 
> Functional testing results (on 2 txq tap device):
> 
>   [Fri Sep 20 18:33:27 2019] ========== tun no prog ==========
>   [Fri Sep 20 18:33:27 2019] tuntap: tun_ebpf_select_queue() returned '-1'
>   [Fri Sep 20 18:33:27 2019] tuntap: tun_automq_select_queue() ran
>   [Fri Sep 20 18:33:27 2019] ========== tun prog -1 ==========
>   [Fri Sep 20 18:33:27 2019] tuntap: bpf_prog_run_clear_cb() returned '-1'
>   [Fri Sep 20 18:33:27 2019] tuntap: tun_ebpf_select_queue() returned '-1'
>   [Fri Sep 20 18:33:27 2019] tuntap: tun_automq_select_queue() ran
>   [Fri Sep 20 18:33:27 2019] ========== tun prog 0 ==========
>   [Fri Sep 20 18:33:27 2019] tuntap: bpf_prog_run_clear_cb() returned '0'
>   [Fri Sep 20 18:33:27 2019] tuntap: tun_ebpf_select_queue() returned '0'
>   [Fri Sep 20 18:33:27 2019] ========== tun prog 1 ==========
>   [Fri Sep 20 18:33:27 2019] tuntap: bpf_prog_run_clear_cb() returned '1'
>   [Fri Sep 20 18:33:27 2019] tuntap: tun_ebpf_select_queue() returned '1'
>   [Fri Sep 20 18:33:27 2019] ========== tun prog 2 ==========
>   [Fri Sep 20 18:33:27 2019] tuntap: bpf_prog_run_clear_cb() returned '2'
>   [Fri Sep 20 18:33:27 2019] tuntap: tun_ebpf_select_queue() returned '0'
> 
> Signed-off-by: Matthew Cover <matthew.cover@...ckpath.com>


Could you add a bit more motivation data here?
1. why is this a good idea
2. how do we know existing userspace does not rely on existing behaviour
3. why doesn't userspace need a way to figure out whether it runs on a kernel with and
   without this patch


thanks,
MST

> ---
>  drivers/net/tun.c | 20 +++++++++++---------
>  1 file changed, 11 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/net/tun.c b/drivers/net/tun.c
> index aab0be4..173d159 100644
> --- a/drivers/net/tun.c
> +++ b/drivers/net/tun.c
> @@ -583,35 +583,37 @@ static u16 tun_automq_select_queue(struct tun_struct *tun, struct sk_buff *skb)
>  	return txq;
>  }
>  
> -static u16 tun_ebpf_select_queue(struct tun_struct *tun, struct sk_buff *skb)
> +static int tun_ebpf_select_queue(struct tun_struct *tun, struct sk_buff *skb)
>  {
>  	struct tun_prog *prog;
>  	u32 numqueues;
> -	u16 ret = 0;
> +	int ret = -1;
>  
>  	numqueues = READ_ONCE(tun->numqueues);
>  	if (!numqueues)
>  		return 0;
>  
> +	rcu_read_lock();
>  	prog = rcu_dereference(tun->steering_prog);
>  	if (prog)
>  		ret = bpf_prog_run_clear_cb(prog->prog, skb);
> +	rcu_read_unlock();
>  
> -	return ret % numqueues;
> +	if (ret >= 0)
> +		ret %= numqueues;
> +
> +	return ret;
>  }
>  
>  static u16 tun_select_queue(struct net_device *dev, struct sk_buff *skb,
>  			    struct net_device *sb_dev)
>  {
>  	struct tun_struct *tun = netdev_priv(dev);
> -	u16 ret;
> +	int ret;
>  
> -	rcu_read_lock();
> -	if (rcu_dereference(tun->steering_prog))
> -		ret = tun_ebpf_select_queue(tun, skb);
> -	else
> +	ret = tun_ebpf_select_queue(tun, skb);
> +	if (ret < 0)
>  		ret = tun_automq_select_queue(tun, skb);
> -	rcu_read_unlock();
>  
>  	return ret;
>  }
> -- 
> 1.8.3.1

Powered by blists - more mailing lists