Received: by 2002:ab2:3b09:0:b0:1ed:14ea:9113 with SMTP id b9csp95809lqc; Thu, 29 Feb 2024 11:17:06 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUubgfLuh+1dQeIxP9bGXvv+GfHkwTfPsR3+k9YYxxYvxRLPn/ybShI7yjIqowW8iIIFLTcBcLCmIeIdbrLmRj68LNXCIyhCoyGTl4wPw== X-Google-Smtp-Source: AGHT+IFT4LbQgTqRFIhEf8Dn7xn/Ylq56Ajgq5khRsu4ncL5uge7yf+lDpWrPd/Lj6c0oA1fqGCT X-Received: by 2002:a17:902:ced0:b0:1d9:8f6e:86e8 with SMTP id d16-20020a170902ced000b001d98f6e86e8mr3767888plg.69.1709234226500; Thu, 29 Feb 2024 11:17:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709234226; cv=pass; d=google.com; s=arc-20160816; b=Ui2r8FfJSvQ0GzkLyJEd/5OAAS61+5+a32zhO9FV5i7/mdgIo0cVB6x0paP45KETaf J1q3rzzoF7cwE2MmHOFv19JKrFTsO1gtOsSEtX19jbPZIAwz/QGCsyMiXBNx9LZGXa1B c0nKMZUzsB81r8JteKcV/DfX91f+J8bzSmA0dBaU/UYBdy0y5c3NfVmRoqbGX7m8Se/N p9DBs8hpBgMaYZYns9yFTBDLMvfi+JFkzThpUeZHORrIlD/R1gjOrsgcDEtN/2KZDBuB z3tDMZYRURr6/dZW629luf81QGjlx76hURThnTdJ3iB5+jA1M6OxeK2J9mrRfH0xv1M4 Y6xA== 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=UPNx03vL5gJBUsLY5izQNSc5f5aQFQJTo3mFc1Gcb0A=; fh=DowqtZ8FbE+7U1p5d7ExMDPU7Q3wEwztK4C6MhZAlWs=; b=kutHWh0Pm9H3/I39PW5a9tp72CJZP7APIL1E+qo4JKbzAJGwwUWtrt1gZM3phLNh5M gt/zyWB1/rRvFXL+n6hjJoiU7x7bRTu/GZnNVHzBa7AlLMf04FaB2C38JEI0hv2nkkgJ Of+BwAKsqUw0AQgevg18Pyts1Xw8mqeqA3eJA2KnmAv40RKVOnv7+DY6gb3O3SAPWEze Urxx2XHz4qlHIv4Ros0yND5W4lXd9lRBriCaZGCtoYK1JThzUZJRZz7vCrFNGZ0LsIST cn0h9aNVQKDCdWIXBp4Mcexlz/gDfGsIOvVYYQDoVT8tb/xq34Y4E+bBrvs2YYvJteKr kS3Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=WPFTpjyi; 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-87327-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87327-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id m18-20020a170902f65200b001db5d0901e0si1974363plg.98.2024.02.29.11.17.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 11:17:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-87327-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=WPFTpjyi; 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-87327-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87327-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 68D0C289112 for ; Thu, 29 Feb 2024 19:09:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8F438134437; Thu, 29 Feb 2024 19:09:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="WPFTpjyi" Received: from mail-ot1-f46.google.com (mail-ot1-f46.google.com [209.85.210.46]) (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 19BD213C9C2 for ; Thu, 29 Feb 2024 19:08:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709233741; cv=none; b=ILW9BwCxZATAvDBEmQuvPuHKuBo+d8SrlvD4LqT5rKYXECChZdCg34ShroXpbZYIzwsRo/uELXLgFsaHcndLTixeig9NP3sqm7XmJcMvTUXNzAcFX1FJBY1SVU2eSTDu2GKedQiwJe1mCWUetG4YW2hGOl+U+X+aI7MphwmW3d0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709233741; c=relaxed/simple; bh=XhYVxNr3yIQGYfPBq8eZl7fW5SFxmb1whNnII5+VYe8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=iNWKc/rH3F1/5XvU2EZrdmMQJ6PInESpz90VTC27Z/jiCOY7mdI6oiR7mwZ8T+zu1S1xQtfZJ/XigRqfZHA9oHnyenXYR7nsOsRaMoGEA1mEqAnajy1LVQUHID8L9ASVWMgkC3HghJguy4693v6tzinudnji6T1RUtvU4hTUw2g= 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=WPFTpjyi; arc=none smtp.client-ip=209.85.210.46 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-ot1-f46.google.com with SMTP id 46e09a7af769-6e48153c13aso667854a34.3 for ; Thu, 29 Feb 2024 11:08:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1709233739; x=1709838539; 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=UPNx03vL5gJBUsLY5izQNSc5f5aQFQJTo3mFc1Gcb0A=; b=WPFTpjyiRDs+msv4Rcc4/qQvq3jlA5SfObvFs8J1jxZ+hsqoA8y2mmS/xj0bHHmGxt 4RQ+Vbpb7J99vt2blfAzhImkl3cMVSnvDq/urcg/XftJn0Pc/UZqL0z2YxSQtfwPOIwG q5FuNu5UmCxQohquaFF0QadN7TK8tF6YHwPZ8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709233739; x=1709838539; 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=UPNx03vL5gJBUsLY5izQNSc5f5aQFQJTo3mFc1Gcb0A=; b=ZFVsQfyO+QNhpzMLTkfSUFHk9HcY9+NvhREr0b1wDjAKmyht4H/nh9T0uC01RCHNRN RlEYhz8xN3Psj2IEss4ZZqR/XSJSPJiDm5TnmW5UbHam3ctUw5m9Tg8oO+V8RMg6Vtxu eZE/Ln9w6tG6kg0M4jj3GPyIqJv9h1TlV6YMpRVOluSZKdWGCiSt6/+wkQnNwq8qE4dV XkaKFOWAEqThovnHbpFmiFuWEQ4oomaxdSpoWkHBJoJe/F1Wnyf1bp59mctq8kmx4Ypu 4+O4dVW2X18vsewOFEvAMuZlibUXvYHmsK2gtGvvD2sU1M3Ku4lrvWTX81/AdlE6CDJI WnNg== X-Forwarded-Encrypted: i=1; AJvYcCX5pzfz34Euxt/Y/avJ5FIWZw1kXOnz/YGEWNI0JB1SK1WJBWLsRnEDzVuynqc9EsUZRUpQEF1dV+8hsMmszsqrjPyqOHO8t/Oziq4V X-Gm-Message-State: AOJu0Yzew2pxp6f08qgHPk3Yak6Ud5ZlihVwBPi7s/fxAnDCewzOuHiZ W3YFUs/M3cONW4XTqXsuoaKl1ZSw267R3BpsSa/r0zLdJuCsCs/AG8iihbVo5g== X-Received: by 2002:a9d:618c:0:b0:6e4:9e38:37a7 with SMTP id g12-20020a9d618c000000b006e49e3837a7mr2725366otk.23.1709233739242; Thu, 29 Feb 2024 11:08:59 -0800 (PST) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id c4-20020aa78804000000b006e05c801748sm1613455pfo.199.2024.02.29.11.08.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 11:08:58 -0800 (PST) Date: Thu, 29 Feb 2024 11:08:58 -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: <202402291059.491B5E03@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> <202402281554.C1CEEF744@keescook> <20240228165609.06f5254a@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: <20240228165609.06f5254a@kernel.org> On Wed, Feb 28, 2024 at 04:56:09PM -0800, Jakub Kicinski wrote: > On Wed, 28 Feb 2024 16:01:49 -0800 Kees Cook wrote: > > 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. > > Ugh, yes, the (ab)use of NAPI. > > > Some even have two included (?) > > And some seem to be cargo-culted from out-of-tree code and are unused :S Ah, which can I remove? > That's... less pretty. I'd rather push the ugly into the questionable > users. Make them either allocate the netdev dynamically and store > a pointer, or move the netdev to the end of the struct. > > But yeah, that's a bit of a cleanup :( So far, it's not too bad. I'm doing some test builds now. As a further aside, this code: struct net_device *dev; ... struct net_device *p; ... /* ensure 32-byte alignment of whole construct */ alloc_size += NETDEV_ALIGN - 1; p = kvzalloc(alloc_size, GFP_KERNEL_ACCOUNT | __GFP_RETRY_MAYFAIL); ... dev = PTR_ALIGN(p, NETDEV_ALIGN); Really screams for a dynamic-sized (bucketed) kmem_cache_alloc API. Alignment constraints can be described in a regular kmem_cache allocator (rather than this open-coded version). I've been intending to build that for struct msg_msg for a while now, and here's another user. :) -Kees -- Kees Cook