Received: by 2002:a05:7208:13ce:b0:7f:395a:35b6 with SMTP id r14csp160829rbe; Wed, 28 Feb 2024 16:02:23 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXDOaS/ReLRLsqMUfnILmNbzkGS4YVz6VQbncidtOGEMDFZyALWrwtP3CnjVcGKuuxZKncK5W7GqV9xtFxf5t6ehZgonzLvoC0zPS0WpA== X-Google-Smtp-Source: AGHT+IFai4EqHoVtcwZlbAI7EUONNmb0YRqsazPYxKBU3tiwHn0mJUcnXq5aFRSPOr1PxEB8Cmpl X-Received: by 2002:a05:6358:568e:b0:17b:c720:4dca with SMTP id o14-20020a056358568e00b0017bc7204dcamr854095rwf.9.1709164943346; Wed, 28 Feb 2024 16:02:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709164943; cv=pass; d=google.com; s=arc-20160816; b=I7hvY4+aNzcNReBtkPY0/seYCbQaMSbsUOVYpmHgRc4xs6DxYwD6kfnFzyAUeHxFT4 qTXLN516aC/v68MKkQ8MpuGMd0t3KJKxgtRH8WPlWlKOpsGbAdKMZutRSIj/U896N0op oWZ9noD657YoVm95LhSe4ad0Yso44tg3Vlt8WDkMWSirIcrkyINav70lRKskNn6Ogenb A1vuMMpbiqMrlTSiGRbJZddaFIQKxL7sBBG2Qb5uCb0rumtZQ57t1b6CRHpwXRCUTIed Ip/vOeuu9+6jZT3PCHznbAs2kytdYM/p3zM3y/b+tiv4qaQnavGI1pPE5u2yWEOY7L/x e2JA== 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=iEBIJm8L8y8D/KMJdxSN242jmeihBdO84S0mND9uaps=; fh=84zLxss6jB+egsdbsJuLFolbWx4/SWAjpzqclUiPLPI=; b=eXwwfrQ2wh7swa+51V6ZshDcCKrjt3iBmyzzBc8d3Xnwq4kHsiKJpwphUUVVP0DimS XEIkBT3bvzRDqFORtJwN39Rn5OD/Uq3LxCI6qE2OFpN5iDaesFCeHGOTG30vAQAnf8xi nRCbzHEg9mBa9wBGHEeP34XF55asHJ7656mgaW0u8VfIk7tiuWHWgqTfpOqR3c0TkGvZ rTL/iKFxTvE6in5fgGwtwVxO4Ih930xPUWZLSQTFVoBUj6qfBj/nUzk5FXUeFgqTqSKq 9HXa00qTEa1dOdUsD9bxIjZxwu1h3dCZWMFeMjJQxjcT4nL8JypozjouzGRIwqFhG5+s 2y5Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Y3RfdnXT; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-85862-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85862-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id b21-20020ac85bd5000000b0042e7cdd139esi282760qtb.585.2024.02.28.16.02.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 16:02:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-85862-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Y3RfdnXT; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-85862-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85862-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id A17C31C22529 for ; Thu, 29 Feb 2024 00:02:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5B7881CD23; Thu, 29 Feb 2024 00:01:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Y3RfdnXT" Received: from mail-oi1-f179.google.com (mail-oi1-f179.google.com [209.85.167.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C6EECA28 for ; Thu, 29 Feb 2024 00:01:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709164913; cv=none; b=dNPOmlozGdi11bpfFOHJrfF1kpdirt3836jOBdbMvnNCURwLgEV3iKPJbiVMpQ9cYx7K4tEzvS7cGdjx2Fu/4ROhOCEQ/ilhS1GwETdKkr+MKobryG8Wxn1vX95NF6wdMoI93MFUpo7nddWTsoF+qqoe0c/lQsfHS0CY40/wEo4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709164913; c=relaxed/simple; bh=qxsoqrA85W0ZABODeQ55zexBoMTqe+0G6tTR4C4edFg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Z87aOskke2QqYd9BiXav3Hw9Js5eS93GOW/0LBl5e/XyWaTuSnRe5kc8J3pz+Wz0CorFT3LIkOeA9YB2XetT9TstBGmI8B4BURSmRmKocwGKY7mEKLs5FqSLcnz3yW6p+DrU0RQhDhfqO/yYcNHLzsZrtGU1YQees3PHWuEoNLo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=Y3RfdnXT; arc=none smtp.client-ip=209.85.167.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-oi1-f179.google.com with SMTP id 5614622812f47-3c19b79535aso229653b6e.0 for ; Wed, 28 Feb 2024 16:01:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1709164911; x=1709769711; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=iEBIJm8L8y8D/KMJdxSN242jmeihBdO84S0mND9uaps=; b=Y3RfdnXTWmbJLlQXNnkjy+ZF0gXZKzA0KjRs2qwdBt21m8GvVCMIXgNMBURHBwjeKJ IyVQt+Po3ndN5q7/hWcZF56J5FgF+RMhrM8DzLqJmi0EnLfSTqemYneQq1kvGQU9wY3x Apg7VWhU2fM47BtJyjtDA9BGDyI3ypa2yFpm8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709164911; x=1709769711; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=iEBIJm8L8y8D/KMJdxSN242jmeihBdO84S0mND9uaps=; b=MPZQu8Lg1JZ+2J7z7oLC92rrSs3Y5bKn8eSHVaqUryAM4nAtES12DVRgXDMyrQgVn1 wx9f1X8m/g5oIz/tLtKeB08A0B0WHp1HHbNLR/6DneBRgGBc6rqBM1GuUa/5EkB6YBLS s6PR3bVAAdM92pzn9KZDlT4rFkIJIQ3uR43wspf4K4qid70xGG4xeuJz8+d8F93m+ylj eka2wteTKArwhFA9Opd1bFWDXiozNLtnmKRV0/pLDivPo4B9a1sslleu9nsPPaqYS+lz VjfKPi1bP2QIZDBHrqmagMc9fMMbOBOwrT4jicy14CdFjWIDwqSgLaV0cWLMnp9KaXGj c2sg== X-Forwarded-Encrypted: i=1; AJvYcCUOlox0Yal3bqjb7Bjv4zTeqqecF34Un5gqhuDZYCiEZH8E/j7j0l1DBMKT7H/86wWADn53L1DzsbSeCt3jjGmEDkyaAfx1+uGq/7jA X-Gm-Message-State: AOJu0YwgFwirQIFV4+9OEVDQf9YhaB+wiFIgSQzIWNg2Y8e/D7m+tao1 HVhsHJpwHmSClfinAlfN74AaDz1rfUbUkOelV9prQODWNwA/koaMsuDSUkgVOw== X-Received: by 2002:a05:6808:19a4:b0:3c1:af9f:a866 with SMTP id bj36-20020a05680819a400b003c1af9fa866mr607658oib.45.1709164910890; Wed, 28 Feb 2024 16:01:50 -0800 (PST) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id a24-20020a631a18000000b005dc491ccdcesm60329pga.14.2024.02.28.16.01.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 16:01:50 -0800 (PST) Date: Wed, 28 Feb 2024 16:01:49 -0800 From: Kees Cook To: Jakub Kicinski Cc: Andy Shevchenko , Vinod Koul , Linus Walleij , Jonathan Cameron , Mark Brown , linux-arm-kernel@lists.infradead.org, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, linux-spi@vger.kernel.org, netdev@vger.kernel.org, linux-hardening@vger.kernel.org, Jonathan Cameron , Lars-Peter Clausen , "David S. Miller" , Eric Dumazet , Paolo Abeni , "Gustavo A. R. Silva" Subject: Re: [PATCH v4 7/8] net-device: Use new helpers from overflow.h in netdevice APIs Message-ID: <202402281554.C1CEEF744@keescook> References: <20240228204919.3680786-1-andriy.shevchenko@linux.intel.com> <20240228204919.3680786-8-andriy.shevchenko@linux.intel.com> <202402281341.AC67EB6E35@keescook> <20240228144148.5c227487@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: <20240228144148.5c227487@kernel.org> On Wed, Feb 28, 2024 at 02:41:48PM -0800, Jakub Kicinski wrote: > On Wed, 28 Feb 2024 13:46:10 -0800 Kees Cook wrote: > > I really don't like hiding these trailing allocations from the compiler. > > Why can't something like this be done (totally untested): > > > > > > diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h > > index 118c40258d07..dae6df4fb177 100644 > > --- a/include/linux/netdevice.h > > +++ b/include/linux/netdevice.h > > @@ -2475,6 +2475,8 @@ struct net_device { > > /** @page_pools: page pools created for this netdevice */ > > struct hlist_head page_pools; > > #endif > > + u32 priv_size; > > + u8 priv_data[] __counted_by(priv_size) __aligned(NETDEV_ALIGN); > > I like, FWIW, please submit! :) So, I found several cases where struct net_device is included in the middle of another structure, which makes my proposal more awkward. But I also don't understand why it's in the _middle_. Shouldn't it always be at the beginning (with priv stuff following it?) Quick search and examined manually: git grep 'struct net_device [a-z0-9_]*;' struct rtw89_dev struct ath10k etc. Some even have two included (?) But I still like the idea -- Gustavo has been solving these cases with having two structs, e.g.: struct net_device { ...unchanged... }; struct net_device_alloc { struct net_device dev; u32 priv_size; u8 priv_data[] __counted_by(priv_size) __aligned(NETDEV_ALIGN); }; And internals can use struct net_device_alloc... -Kees -- Kees Cook