Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp231804lqg; Fri, 1 Mar 2024 03:43:39 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXy1vRz/02wdFTXQ56VzKMcOj5BMxXh3YF/yPJgOBwlmOvW+ZqUiK8MbXMG5QebomN6zpEvqlNshDqUGyIFIafJz9LLiReVDr7iceFszw== X-Google-Smtp-Source: AGHT+IEDugbTCcSMwazeOB9sRmxvJQDrNqMgUYmtntm0zq4eW7IgY3tff0xBhUseJ0LKNHDlKHrA X-Received: by 2002:a05:6830:2093:b0:6e4:82a4:742e with SMTP id y19-20020a056830209300b006e482a4742emr1542329otq.0.1709293419734; Fri, 01 Mar 2024 03:43:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709293419; cv=pass; d=google.com; s=arc-20160816; b=Y86CXQCIAyMcMgd6a2gQR9rdOfs7zvpv+s6xexqLu5LC3aJfuyHvChHNjebDwrKFhM w7OVtymcTzHEcHSRycWGhI2BqHvQJyUPDveHkD216v6xK09pt0/HxJM2hopWxvXpurF7 pnQbeBo2dWnosJ6T6sumKL8+/arjs9oOn7bfiZEgJq3tScp6WjadZzyaK5D48w/kYuH8 1CzyHivuOObQCD6SAbaIxrp833dDX8y2stfBDTebXhmOf8wemi/z6Ns25jfA96ay/7+q nK80XcoTUGu3Kvu/oZfhTsEDoHnk1qaQXoB0qgm8YONna5fcMzSHCNTJz/6GXageVjzq nfnQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=svAhVkXkUAnb0q1X3Tz7AXDQUz2WD/dx5lg1HJKIB1M=; fh=FdxZwDGYWmqv9ve0plcgJYITHUMJMbnXzlun8dnyOI4=; b=GoJPy9W0GTEA82IqWeXZ61JPTRv/nzPK7Jn1Q0fWp9kxPTJ6HXrevNW1xal+xFIRUF teUfiX1kcvonuAWYqyfOdbR6bLCqWur798SDmDKlFqbKKLhFRXQatha3w1VzNfMFBo1r 8k4fwmoU+3tpmJSVuINGfABUsuiUrMzzm9Ax9vvVHQyro+R3XzLnaMYycAXXzJmWPNhv lUjtMC56j+GTmUXRFSWHTd57QIm8OzvDQP2OLGZRVbgdtRG5YEVBzOwNz9v62TThnDin +iI/ORyhrQNBHu7xsW6odexH2b82YiJhk+9EE4cu0iz24/CQNo27aeV7XKF3DrOfBe3w 9oEg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Gk5wWgCH; arc=pass (i=1 dkim=pass dkdomain=linuxfoundation.org); spf=pass (google.com: domain of linux-kernel+bounces-88371-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88371-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id a2-20020a63e402000000b0057d7cff25besi3406300pgi.829.2024.03.01.03.43.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 03:43:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88371-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Gk5wWgCH; arc=pass (i=1 dkim=pass dkdomain=linuxfoundation.org); spf=pass (google.com: domain of linux-kernel+bounces-88371-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88371-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 5CD33282B45 for ; Fri, 1 Mar 2024 11:42:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CDC466CDCE; Fri, 1 Mar 2024 11:41:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="Gk5wWgCH" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CF07C6A8AD; Fri, 1 Mar 2024 11:41:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709293316; cv=none; b=FtN6xE5Xrww0Q2nqCSrA4H4Nle14MaftEWr5tFuvU2hpUKzPwoXdEX5R3Wq/+7n5yQkl/tM0WJUCXpBAy8bYXbLdnomLyes4cLkCjbMTWoWS6dhz6ak1oe6AVYGkOJAGU4cfDijhEGOeTJf8Roig3oANvXhVSYqkqMBzmCuB8sE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709293316; c=relaxed/simple; bh=EYQzIq2XsHbxPP8KNQSmIBCmBUS5ay1BMmtHwbbusNM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=hP1uR7wkR7oOCpfHeHMM4+xTvWwlV4Gf7dH0Y82ury6w691dZgO2Xdtzf+B6DWA7FY33nKO7RyCofAvl0KgRFv1gSqUj8Go9houKsGdtbZzJevdtq+AfJzhLp35NzBe4u3k/lljb2Kt86OCwxAzFsBK65fVQBGPF9fbUSUr5fII= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Gk5wWgCH; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id B1844C433F1; Fri, 1 Mar 2024 11:41:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1709293315; bh=EYQzIq2XsHbxPP8KNQSmIBCmBUS5ay1BMmtHwbbusNM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Gk5wWgCH0TPmRkvJzdQpj9C5HIOw9GHZ+3Xpk/EcNAXBRZVJ5Fw3FxLONXKuj5lkB 6CIO+Dwed/IhqsJjXS98AEknok9SQGO616enLsGTrYrv8yJtKNq+xtS7xnpBPemYdQ /MLyValKXQBsFurOwXvc+NUHaSUu9MhYEFH7l1Os= Date: Fri, 1 Mar 2024 12:41:52 +0100 From: Greg KH To: Jakub Kicinski Cc: Kees Cook , "David S. Miller" , Eric Dumazet , Paolo Abeni , Andy Shevchenko , "Gustavo A. R. Silva" , netdev@vger.kernel.org, linux-hardening@vger.kernel.org, Simon Horman , Jiri Pirko , Daniel Borkmann , Coco Li , Amritha Nambiar , linux-kernel@vger.kernel.org Subject: Re: [PATCH] netdev: Use flexible array for trailing private bytes Message-ID: <2024030121-starring-party-7e34@gregkh> References: <20240229213018.work.556-kees@kernel.org> <20240229225910.79e224cf@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240229225910.79e224cf@kernel.org> On Thu, Feb 29, 2024 at 10:59:10PM -0800, Jakub Kicinski wrote: > On Thu, 29 Feb 2024 13:30:22 -0800 Kees Cook wrote: > > Introduce a new struct net_device_priv that contains struct net_device > > but also accounts for the commonly trailing bytes through the "size" and > > "data" members. > > I'm a bit unclear on the benefit. Perhaps I'm unaccustomed to "safe C". > > > As many dummy struct net_device instances exist still, > > it is non-trivial to but this flexible array inside struct net_device > > put > > Non-trivial, meaning what's the challenge? > We also do somewhat silly things with netdev lifetime, because we can't > assume netdev gets freed by netdev_free(). Cleaning up the "embedders" > would be beneficial for multiple reasons. > > > itself. But we can add a sanity check in netdev_priv() to catch any > > attempts to access the private data of a dummy struct. > > > > Adjust allocation logic to use the new full structure. > > > > Signed-off-by: Kees Cook > > > diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h > > index 118c40258d07..b476809d0bae 100644 > > --- a/include/linux/netdevice.h > > +++ b/include/linux/netdevice.h > > @@ -1815,6 +1815,8 @@ enum netdev_stat_type { > > NETDEV_PCPU_STAT_DSTATS, /* struct pcpu_dstats */ > > }; > > > > +#define NETDEV_ALIGN 32 > > Unless someone knows what this is for it should go. > Align priv to cacheline size. > > > /** > > * struct net_device - The DEVICE structure. > > * > > > @@ -2665,7 +2673,14 @@ void dev_net_set(struct net_device *dev, struct net *net) > > */ > > static inline void *netdev_priv(const struct net_device *dev) > > { > > - return (char *)dev + ALIGN(sizeof(struct net_device), NETDEV_ALIGN); > > + struct net_device_priv *priv; > > + > > + /* Dummy struct net_device have no trailing data. */ > > + if (WARN_ON_ONCE(dev->reg_state == NETREG_DUMMY)) > > + return NULL; > > This is a static inline with roughly 11,000 call sites, according to > a quick grep. Aren't WARN_ONCE() in static inlines creating a "once" > object in every compilation unit where they get used? It also, if this every trips, will reboot the box for those that run with panic-on-warn set, is that something that you all really want? thanks, greg k-h