Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1616607pxb; Thu, 28 Oct 2021 07:04:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlaCvzr1W8O6bGeJfliVhLCVu64VFzL90iJmhfTYJYfHbyxq6UspYC59Vcy3IWJpJSGEja X-Received: by 2002:a63:b706:: with SMTP id t6mr3364713pgf.11.1635429844022; Thu, 28 Oct 2021 07:04:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635429844; cv=none; d=google.com; s=arc-20160816; b=DzwLZkFC9XorhOpIAmokovv9KZZxtzMHIoBn3weAZB+B1pysPTacKjoKc+I7SDJT1/ 6x8S1u3jxY+ACR3XqIwT17W93EAyKOYarzWmNzqED7Q2l9z5/p9VFAXab3SSGBMsciil CSd5Bmxyy9vgpLcK7b+suthA/I158BJxbakGWpXVWrzF4iv9taEkzOK9aJoXovkYACno HhOJ+9IvUbpjUc/RDo69TWd1dCWeZA3OgVcDyxhCx2t7gdkNYZhtr/KLD3uoTwf/dbUx ho0+YxlBxIBvH+s44QDatugrlvKaI953WX2SstJRy5GsM5NlNsm84oiJ6/pMs8PEU5bN djYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=S0td/B6jJ44uczbu4zj4ECy0TcU8vmJPE5+cgTOMUms=; b=mXeHc91zjkbNU57bwjsTlXNRjOX1bs0+OEVJFiaqonCF5URpGXZoTa4nSAw7bgH0CF /nimYS+Az1fQtkKlaCEX9mOzrqfwKOXIw1za0+MjRBDaSNsCyuhJDXBtsqmVXih137rR wv0wcCx33QCnoTDpt9TcSF4c/qQmyMTFn4ihs4BL/Z7pdpkOuiqbm1ICADi6blSmqb80 lSu043xxsXlSnAk0BtBamYUxcBze6kiN6n7iS5yk0FNSqEewqZiR1jYaNxPybGIwq40n MJyNHApChi6ATKJgl7WhmUmmfUFTbRfsuaaWJkIogjSQjLM+wVsjr+0ITg874LRvZmbh PbVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uyXe9ZVL; 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 q20si4077009pls.53.2021.10.28.07.03.44; Thu, 28 Oct 2021 07:04:04 -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=uyXe9ZVL; 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 S231307AbhJ1OD3 (ORCPT + 99 others); Thu, 28 Oct 2021 10:03:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:47392 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230442AbhJ1ODS (ORCPT ); Thu, 28 Oct 2021 10:03:18 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id BF74B610F8; Thu, 28 Oct 2021 14:00:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1635429652; bh=befpioNaBoCsU26abS9DdkNYMXPxAUWRWsMO1jqOJXo=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=uyXe9ZVLedivH5p6YcQejSc5sgHFh0v2znTJYBaLZ9tRQ7gYrOmgcBoTu2d/pmzo3 lFwSeDHXDmA5q3wcAM+GoZQUGsfVje8RFD3pQq/7O6WEIYcgXG+e98Eyi+a9X64EAu F0VJ4PzcuPa4Pl1zzH3ysT7DsKS7yoFcYBhWSxTNC4i6vW5AbQf9vXrZP7yizsRt1F kgPaGdcx+Ci0B/1rd05hnxx5+IMaCQuM21NfMnEhibyKeBFG1eRS3CqcJFBTrTB4I2 DsNgrUs/w3x7T4K2vpaMuZWxFPy7XPdrrGXRq8o5YaGBuWm3zST5DozCuyWJprU/N4 wIwcobLz84KXQ== Date: Thu, 28 Oct 2021 07:00:50 -0700 From: Jakub Kicinski To: Jason Gunthorpe Cc: Ziyang Xuan , davem@davemloft.net, 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: <20211028070050.6ca7893b@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> In-Reply-To: <20211028114503.GM2744544@nvidia.com> References: <20211027121606.3300860-1-william.xuanziyang@huawei.com> <20211027184640.7955767e@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> <20211028114503.GM2744544@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 28 Oct 2021 08:45:03 -0300 Jason Gunthorpe wrote: > > But will make all the callers of vlan_dev_real_dev() feel like they > > should NULL-check the result, which is not necessary. > > Isn't it better to reliably return NULL instead of a silent UAF in > this edge case? I don't know what the best practice is for maintaining sanity of unregistered objects. If there really is a requirement for the real_dev pointer to be sane we may want to move the put_device(real_dev) to vlan_dev_free(). There should not be any risk of circular dependency but I'm not 100% sure. > > RDMA must be calling this helper on a vlan which was already > > unregistered, can we fix RDMA instead? > > RDMA holds a get on the netdev which prevents unregistration, however > unregister_vlan_dev() does: > > unregister_netdevice_queue(dev, head); > dev_put(real_dev); > > Which corrupts the still registered vlan device while it is sitting in > the queue waiting to unregister. So, it is not true that a registered > vlan device always has working vlan_dev_real_dev(). That's not my reading, unless we have a different definition of "registered". The RDMA code in question runs from a workqueue, at the time the UNREGISTER notification is generated all objects are still alive and no UAF can happen. Past UNREGISTER extra care is needed when accessing the object. Note that unregister_vlan_dev() may queue the unregistration, without running it. If it clears real_dev the UNREGISTER notification will no longer be able to access real_dev, which used to be completely legal.