netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: randomize layout of struct net_device
@ 2025-06-02 13:59 Pranav Tyagi
  2025-06-02 14:07 ` Kees Cook
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Pranav Tyagi @ 2025-06-02 13:59 UTC (permalink / raw)
  To: andrew+netdev, davem, edumazet, kuba, pabeni, horms, keescook,
	netdev, linux-kernel, skhan, linux-kernel-mentees
  Cc: Pranav Tyagi

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
 	/* Cacheline organization can be found documented in
 	 * Documentation/networking/net_cachelines/net_device.rst.
 	 * Please update the document when adding new fields.
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2025-06-06 19:46 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-02 13:59 [PATCH] net: randomize layout of struct net_device Pranav Tyagi
2025-06-02 14:07 ` Kees Cook
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).