From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ot1-f54.google.com (mail-ot1-f54.google.com [209.85.210.54]) (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 1DA0213C9C3 for ; Thu, 29 Feb 2024 19:08:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709233741; cv=none; b=mJ/cRuTx543FXpy9+dhrSmz0IgjN3YlTQNwPHsQTtOdfz0PDQfKGV3FgjUQD/YtW0qoHdd3usVWqVALXjZeiAsw8W3y0Col2QguizzedvJ48mUJFGZohQGwrldE+cZlPg63JWwELEfdCG3kI2jSPCZ+7kAZBf1VMPbDovO/y7Bs= 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.54 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="WPFTpjyi" Received: by mail-ot1-f54.google.com with SMTP id 46e09a7af769-6e480fe439aso666259a34.0 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=Cm94EIoBI7WEyv522sSG2qMUiSzT3pJLGfswVpR5gLtz9a/KmrNAdJKAqej2Hp0uAl x5xL8yCMl84ijw8f1fic5XzIJ27uy9KeydGpy7dLjkrdJRFclIimpAiKh8Z+5FcClY03 ks6hRXrF9TUh4x8l9qmYJ+blVq3M1QbPehEM0HI9iXgZc2pCiLzMA2ZrNdaF901lZhlo ym5Ua4qQGuIaEUTKvuHe2XcW5epbVJmHqEWM+MWvprSMUIkzX19O4wAa00otFlmXGU89 6AAjP2rX+2LyxUV/9wmxlMeqnPOZYOdmo6sTJ2/ioLR9jmTYyY+3h4CFQ+ku5FxpF85U dzYQ== X-Forwarded-Encrypted: i=1; AJvYcCX/q6wKgOK4DZQdNwLDgHEBapoDgL2Y4q6FFW/tsZAtOppUDpD0+aoKCMHjenF1o4lYR0jZbRvsrcYVO7YoS5ZK7zhb48VE X-Gm-Message-State: AOJu0YyHczdHGuRsjZmwwm3idtENPpiQVd8Oco8kgyS/5pzuHcF2zPzR kOno5dkqFrgsJCGft81bqmoSWwOhycjIrITqeKplC7Qrr8XqDRucsGvaaiJ10A== X-Google-Smtp-Source: AGHT+IHgyC7clemZIshyNx4SoJ7Udvxw9GwegtcRM1FBJfrzoLTLgcJeKmWLE72ksvmhiwetvndvRw== 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: netdev@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