Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1220966pxb; Wed, 27 Oct 2021 22:47:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw0627nPd9S1IT7izP1y3UMiTHp/YcZHOVHbLxmJ6gv/G4zB1VGR+kyNn1yFT0xE44NfSdv X-Received: by 2002:a17:906:4fc8:: with SMTP id i8mr2635474ejw.342.1635400029984; Wed, 27 Oct 2021 22:47:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635400029; cv=none; d=google.com; s=arc-20160816; b=Qj5THIDwA6dFHdYAM9P/yq2PtNuMe0fTgQ+Fdc+N4eSv39zcJiCR9kYaNusCF7xHR5 7CZ+uMmI1XyszDr1rBHWw3g5IDjcuJdEQY6J3j4Teji1tCpKA8rD/HaOPMMj45BQdZ8e lDeYS6Q3wcaLk/5CUaQPbx9E/wDZ7I1OTodEUR5GCZiVV0v+m1uEKk6H4HlG52DuERFK 4NvRrowm02T6mzJEyxpZCxpt8ARB95cgR4GSo2qyR5b4urhcUxFe96PdmCcpQTSnwfMY jFsTtwZEAAYpsFPO1O7PuzXUb8wqV3VaWGSDs4HBtBWFRpqgVxmjTh1ig6NXrzbwiJj9 BjnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ddK/xIe8kDKgRUBof+nQ3VAqxmJpX8CeWo/3spP6N10=; b=FZQGCIRVzhaAipTqiC9aMKcdnd6MGNkGhKF/ygpkL6cy/mca0AKK5TVVwyG4XdSkDt a0N7l8O3KgkiEz6CE/Oh5IeA388+lJhV1x6dYk4/9GY5JqQ4xsSxPX3atF3AI7IY8CVk SexbbH2kOPJ8seavk5lfaCGU3z1NeYDYCtDWQp50iFZLrTK8eFJGcpC72IaDnKrUoVUY ov3V9koc7wUfP+G//LUvTLdVCYqW//UxX2yyskWTOKn+22GNO2MarJe290DAM31LdcaA uLj5oDV6yz2EU3FJ2/DLDxze+kHcCwGy2KOhGysf8wm+AvvTHM9Vl6iOZ6ih3HvmbHMB BKeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jqoml+dk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ce15si2798146edb.612.2021.10.27.22.46.45; Wed, 27 Oct 2021 22:47:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jqoml+dk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229775AbhJ1Fr3 (ORCPT + 99 others); Thu, 28 Oct 2021 01:47:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:43918 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229586AbhJ1Fr2 (ORCPT ); Thu, 28 Oct 2021 01:47:28 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D4B6E6103C; Thu, 28 Oct 2021 05:45:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1635399901; bh=AeCe8kc7D0XDwcosE113ZUP5h3uuuc8Wo/nX4PARYd8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=jqoml+dkw9pXIJBpmXvi8UQN3f1nTmo9DUJXYvJWgj2AjfcRF5KEv8T62njj6ZFCm UVhXt1s+qGPSpMcg0n4J0vK8jp2L7vao7Bhmw9VMaMLAGSRLqKMTvcTMTym8IkWIGl Lc6+cT9ONs/F+ioljQYgEkSpmCU5P1zWMStMDmIMHfClRZHeRu/GIMIAir5juPkEpS xc/u3eJ9VseYMkMzgeGqhmhkM966tx+6X/Toec6IOu1wyQGKpy+w2QTYVD0Bi87JvF ToObMIWEEq0QAGStOrW63zUEow3K56i0wTVQAUKpP76qOdZHosLl3WhFkln654l0eO xampLfnAmayiw== Date: Thu, 28 Oct 2021 08:44:57 +0300 From: Leon Romanovsky To: Jakub Kicinski Cc: Ziyang Xuan , davem@davemloft.net, jgg@nvidia.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org Subject: Re: [PATCH net] net: vlan: fix a UAF in vlan_dev_real_dev() Message-ID: References: <20211027121606.3300860-1-william.xuanziyang@huawei.com> <20211027184640.7955767e@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211027184640.7955767e@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 27, 2021 at 06:46:40PM -0700, Jakub Kicinski wrote: > On Wed, 27 Oct 2021 20:16:06 +0800 Ziyang Xuan wrote: > > The real_dev of a vlan net_device may be freed after > > unregister_vlan_dev(). Access the real_dev continually by > > vlan_dev_real_dev() will trigger the UAF problem for the > > real_dev like following: > > > > ================================================================== > > BUG: KASAN: use-after-free in vlan_dev_real_dev+0xf9/0x120 > > Call Trace: > > kasan_report.cold+0x83/0xdf > > vlan_dev_real_dev+0xf9/0x120 > > is_eth_port_of_netdev_filter.part.0+0xb1/0x2c0 > > is_eth_port_of_netdev_filter+0x28/0x40 > > ib_enum_roce_netdev+0x1a3/0x300 > > ib_enum_all_roce_netdevs+0xc7/0x140 > > netdevice_event_work_handler+0x9d/0x210 > > ... > > > > Freed by task 9288: > > kasan_save_stack+0x1b/0x40 > > kasan_set_track+0x1c/0x30 > > kasan_set_free_info+0x20/0x30 > > __kasan_slab_free+0xfc/0x130 > > slab_free_freelist_hook+0xdd/0x240 > > kfree+0xe4/0x690 > > kvfree+0x42/0x50 > > device_release+0x9f/0x240 > > kobject_put+0x1c8/0x530 > > put_device+0x1b/0x30 > > free_netdev+0x370/0x540 > > ppp_destroy_interface+0x313/0x3d0 > > ... > > > > Set vlan->real_dev to NULL after dev_put(real_dev) in > > unregister_vlan_dev(). Check real_dev is not NULL before > > access it in vlan_dev_real_dev(). > > > > Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") > > Reported-by: syzbot+e4df4e1389e28972e955@syzkaller.appspotmail.com > > Signed-off-by: Ziyang Xuan > > --- > > net/8021q/vlan.c | 1 + > > net/8021q/vlan_core.c | 2 +- > > 2 files changed, 2 insertions(+), 1 deletion(-) > > > > diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c > > index 55275ef9a31a..1106da84e725 100644 > > --- a/net/8021q/vlan.c > > +++ b/net/8021q/vlan.c > > @@ -126,6 +126,7 @@ void unregister_vlan_dev(struct net_device *dev, struct list_head *head) > > > > /* Get rid of the vlan's reference to real_dev */ > > dev_put(real_dev); > > + vlan->real_dev = NULL; > > } > > > > int vlan_check_real_dev(struct net_device *real_dev, > > diff --git a/net/8021q/vlan_core.c b/net/8021q/vlan_core.c > > index 59bc13b5f14f..343f34479d8b 100644 > > --- a/net/8021q/vlan_core.c > > +++ b/net/8021q/vlan_core.c > > @@ -103,7 +103,7 @@ struct net_device *vlan_dev_real_dev(const struct net_device *dev) > > { > > struct net_device *ret = vlan_dev_priv(dev)->real_dev; > > > > - while (is_vlan_dev(ret)) > > + while (ret && is_vlan_dev(ret)) > > ret = vlan_dev_priv(ret)->real_dev; > > > > return ret; > > But will make all the callers of vlan_dev_real_dev() feel like they > should NULL-check the result, which is not necessary. > > RDMA must be calling this helper on a vlan which was already > unregistered, can we fix RDMA instead? He tried to fix RDMA first, but we came to conclusion that we real solution is in netdev land. https://lore.kernel.org/linux-rdma/20211025163941.GA393143@nvidia.com/T/#m44abbf1ea5e4b5237610c1b389c3340d92a03b8d Thanks