Re: [PATCH] net: randomize layout of struct net_device
From: Pranav Tyagi <hidden>
Date: 2025-06-06 15:05:07
Also in:
linux-kernel-mentees, lkml
From: Pranav Tyagi <hidden>
Date: 2025-06-06 15:05:07
Also in:
linux-kernel-mentees, lkml
On Mon, Jun 2, 2025 at 8:50 PM Greg KH [off-list ref] wrote:
On Mon, Jun 02, 2025 at 07:29:32PM +0530, Pranav Tyagi wrote:quoted
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 <redacted> --- 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 { +#endifAre you sure the #ifdef is needed? thanks, greg k-h
Hi Greg, No, the #ifdef is not required since __randomize_layout is defined as a no-op when CONFIG_RANDSTRUCT is disabled. I rechecked the documentation to confirm this. Thanks for pointing it out! I will remove the #ifdef and update the patch before resending. Regards Pranav Tyagi