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]
Message-ID: <20191016162357.b2kdf6cflw3c5gzb@kafai-mbp.dhcp.thefacebook.com>
Date:   Wed, 16 Oct 2019 16:24:08 +0000
From:   Martin Lau <kafai@...com>
To:     Toke Høiland-Jørgensen <toke@...hat.com>
CC:     "daniel@...earbox.net" <daniel@...earbox.net>,
        Alexei Starovoitov <ast@...com>,
        "bpf@...r.kernel.org" <bpf@...r.kernel.org>,
        "netdev@...r.kernel.org" <netdev@...r.kernel.org>,
        Tetsuo Handa <penguin-kernel@...ove.SAKURA.ne.jp>
Subject: Re: [PATCH bpf] xdp: Handle device unregister for devmap_hash map
 type

On Wed, Oct 16, 2019 at 03:28:02PM +0200, Toke Høiland-Jørgensen wrote:
> It seems I forgot to add handling of devmap_hash type maps to the device
> unregister hook for devmaps. This omission causes devices to not be
> properly released, which causes hangs.
> 
> Fix this by adding the missing handler.
> 
> Fixes: 6f9d451ab1a3 ("xdp: Add devmap_hash map type for looking up devices by hashed index")
> Reported-by: Tetsuo Handa <penguin-kernel@...ove.SAKURA.ne.jp>
> Signed-off-by: Toke Høiland-Jørgensen <toke@...hat.com>
> ---
>  kernel/bpf/devmap.c | 34 ++++++++++++++++++++++++++++++++++
>  1 file changed, 34 insertions(+)
> 
> diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c
> index d27f3b60ff6d..deb9416341e9 100644
> --- a/kernel/bpf/devmap.c
> +++ b/kernel/bpf/devmap.c
> @@ -719,6 +719,35 @@ const struct bpf_map_ops dev_map_hash_ops = {
>  	.map_check_btf = map_check_no_btf,
>  };
>  
> +static void dev_map_hash_remove_netdev(struct bpf_dtab *dtab,
> +				       struct net_device *netdev)
> +{
> +	int i;
> +
> +	for (i = 0; i < dtab->n_buckets; i++) {
> +		struct bpf_dtab_netdev *dev, *odev;
> +		struct hlist_head *head;
> +
> +		head = dev_map_index_hash(dtab, i);
> +		dev = hlist_entry_safe(rcu_dereference_raw(hlist_first_rcu(head)),
> +				       struct bpf_dtab_netdev,
> +				       index_hlist);
> +
> +		while (dev) {
> +			odev = (netdev == dev->dev) ? dev : NULL;
> +			dev = hlist_entry_safe(rcu_dereference_raw(hlist_next_rcu(&dev->index_hlist)),
> +					       struct bpf_dtab_netdev,
> +					       index_hlist);
> +
> +			if (odev) {
> +				hlist_del_rcu(&odev->index_hlist);
Would it race with the dev_map_hash's update/delete side?

> +				call_rcu(&odev->rcu,
> +					 __dev_map_entry_free);
> +			}
> +		}
> +	}
> +}
> +
>  static int dev_map_notification(struct notifier_block *notifier,
>  				ulong event, void *ptr)
>  {
> @@ -735,6 +764,11 @@ static int dev_map_notification(struct notifier_block *notifier,
>  		 */
>  		rcu_read_lock();
>  		list_for_each_entry_rcu(dtab, &dev_map_list, list) {
> +			if (dtab->map.map_type == BPF_MAP_TYPE_DEVMAP_HASH) {
> +				dev_map_hash_remove_netdev(dtab, netdev);
> +				continue;
> +			}
> +
>  			for (i = 0; i < dtab->map.max_entries; i++) {
>  				struct bpf_dtab_netdev *dev, *odev;
>  
> -- 
> 2.23.0
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ