From: Kees Cook <kees@kernel.org>
To: Pranav Tyagi <pranav.tyagi03@gmail.com>,
andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, horms@kernel.org,
keescook@chromium.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, skhan@linuxfoundation.org,
linux-kernel-mentees@lists.linux.dev
Subject: Re: [PATCH] net: randomize layout of struct net_device
Date: Mon, 02 Jun 2025 07:07:23 -0700 [thread overview]
Message-ID: <EEF63CCD-BEED-4471-BF07-586452F4E0BE@kernel.org> (raw)
In-Reply-To: <20250602135932.464194-1-pranav.tyagi03@gmail.com>
On June 2, 2025 6:59:32 AM PDT, Pranav Tyagi <pranav.tyagi03@gmail.com> wrote:
>Add __randomize_layout to struct net_device to support structure layout
>randomization if CONFIG_RANDSTRUCT is enabled else the macro expands to
>do nothing. This enhances kernel protection by making it harder to
>predict the memory layout of this structure.
>
>Link: https://github.com/KSPP/linux/issues/188
>Signed-off-by: Pranav Tyagi <pranav.tyagi03@gmail.com>
>---
> include/linux/netdevice.h | 4 ++++
> 1 file changed, 4 insertions(+)
>
>diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
>index 7ea022750e4e..0caff664ef3a 100644
>--- a/include/linux/netdevice.h
>+++ b/include/linux/netdevice.h
>@@ -2077,7 +2077,11 @@ enum netdev_reg_state {
> * moves out.
> */
>
>+#ifdef CONFIG_RANDSTRUCT
>+struct __randomize_layout net_device {
>+#else
> struct net_device {
>+#endif
There no need for the ifdef. Also these traditionally go at the end, between } and ;. See other examples in the tree.
-Kees
> /* Cacheline organization can be found documented in
> * Documentation/networking/net_cachelines/net_device.rst.
> * Please update the document when adding new fields.
--
Kees Cook
next prev parent reply other threads:[~2025-06-02 14:07 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-02 13:59 [PATCH] net: randomize layout of struct net_device Pranav Tyagi
2025-06-02 14:07 ` Kees Cook [this message]
2025-06-02 14:22 ` Pranav Tyagi
2025-06-02 14:43 ` Pranav Tyagi
2025-06-02 14:07 ` Greg KH
2025-06-06 15:04 ` Pranav Tyagi
2025-06-02 14:46 ` Andrew Lunn
2025-06-02 18:03 ` Kees Cook
2025-06-02 19:06 ` Andrew Lunn
2025-06-06 14:55 ` Pranav Tyagi
2025-06-06 15:42 ` Eric Dumazet
2025-06-06 19:46 ` Kees Cook
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=EEF63CCD-BEED-4471-BF07-586452F4E0BE@kernel.org \
--to=kees@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=keescook@chromium.org \
--cc=kuba@kernel.org \
--cc=linux-kernel-mentees@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pranav.tyagi03@gmail.com \
--cc=skhan@linuxfoundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox