neighbour: Fix __randomize_layout crash in struct neighbour
Subsystems (2)
PATCH 1/1 neighbour: Fix __randomize_layout crash in struct neighbour
Previously, one-element and zero-length arrays were treated as true flexible arrays, even though they are actually "fake" flex arrays. The __randomize_layout would leave them untouched at the end of the struct, similarly to proper C99 flex-array members.
However, this approach changed with commit 1ee60356c2dc ("gcc-plugins:
randstruct: Only warn about true flexible arrays"). Now, only C99 flexible-array members will remain untouched at the end of the struct, while one-element and zero-length arrays will be subject to randomization.
Fix a __randomize_layout crash in struct neighbour by transforming zero-length array primary_key into a proper C99 flexible-array member.
--- include/net/neighbour.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/net/neighbour.h +1 -1
@@ -162,7 +162,7 @@ struct neighbour {struct rcu_head rcu;struct net_device *dev;netdevice_tracker dev_tracker; -u8 primary_key[0 ]; +u8 primary_key[]; } __randomize_layout;struct neigh_ops {
Signature · 1 line
2.34.1
Quoted 10 lines · Gustavo A. R. Silva
Previously, one-element and zero-length arrays were treated as true flexible arrays, even though they are actually "fake" flex arrays. The
__randomize_layoutwould leave them untouched at the end of the struct, similarly to proper C99 flex-array members.However, this approach changed with commit
1ee60356c2dc("gcc-plugins:
randstruct: Only warn about true flexible arrays"). Now, only C99 flexible-array members will remain untouched at the end of the struct, while one-element and zero-length arrays will be subject to randomization.
Quoted 6 lines
Fix a
__randomize_layoutcrash instruct neighbourby transforming zero-length arrayprimary_keyinto a proper C99 flexible-array member.Fixes 1ee60356c2dc ("gcc-plugins: randstruct: Only warn about true flexible arrays")Signed-off-by Gustavo A. R. Silva <[email protected]>
Yes, please. Do we have any other 0-sized arrays hiding out in the kernel? We need to get these all cleared...
Signature · 1 line
Kees Cook
Quoted 14 lines · Kees Cook
Quoted 13 lines · Gustavo A. R. Silva
Previously, one-element and zero-length arrays were treated as true flexible arrays, even though they are actually "fake" flex arrays. The
__randomize_layoutwould leave them untouched at the end of the struct, similarly to proper C99 flex-array members.However, this approach changed with commit
1ee60356c2dc("gcc-plugins:
randstruct: Only warn about true flexible arrays"). Now, only C99 flexible-array members will remain untouched at the end of the struct, while one-element and zero-length arrays will be subject to randomization.Fix a
__randomize_layoutcrash instruct neighbourby transforming zero-length arrayprimary_keyinto a proper C99 flexible-array member.
Quoted 6 lines
Quoted 3 lines
Fixes 1ee60356c2dc ("gcc-plugins: randstruct: Only warn about true flexible arrays")Signed-off-by Gustavo A. R. Silva <[email protected]>Yes, please. Do we have any other 0-sized arrays hiding out in the kernel? We need to get these all cleared...
I've found 27 instances of zero-length fake-flex arrays in next-20231127.
I'll send a patch series to transform all of them.
Quoted 3 lines
Reviewed-by Kees Cook <[email protected]>
Thanks!
--
Gustavo
Hi,
Quoted 25 lines · Gustavo A. R. Silva
Previously, one-element and zero-length arrays were treated as true flexible arrays, even though they are actually "fake" flex arrays. The
__randomize_layoutwould leave them untouched at the end of the struct, similarly to proper C99 flex-array members.However, this approach changed with commit
1ee60356c2dc("gcc-plugins:
randstruct: Only warn about true flexible arrays"). Now, only C99 flexible-array members will remain untouched at the end of the struct, while one-element and zero-length arrays will be subject to randomization.Fix a
__randomize_layoutcrash instruct neighbourby transforming zero-length arrayprimary_keyinto a proper C99 flexible-array member.Fixes 1ee60356c2dc ("gcc-plugins: randstruct: Only warn about true flexible arrays")Signed-off-by Gustavo A. R. Silva <[email protected]>--- include/net/neighbour.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/net/neighbour.h +0
-0
include/net/neighbour.h struct neighbour { · line 168
Quoted 8 lines
include/net/neighbour.h +1
-1@@ -162,7 +162,7 @@ struct neighbour {struct rcu_head rcu;struct net_device *dev;netdevice_tracker dev_tracker; -u8 primary_key[0 ]; +u8 primary_key[]; } __randomize_layout;struct neigh_ops {
Fixes the crash for me!
Quoted 13 lines
Quoted 13 lines
include/net/neighbour.h +1
-1@@ -162,7 +162,7 @@ struct neighbour {struct rcu_head rcu;struct net_device *dev;netdevice_tracker dev_tracker; -u8 primary_key[0 ]; +u8 primary_key[]; } __randomize_layout;
Quoted 3 lines
include/net/neighbour.h struct neighbour { · line 168
Quoted 1 line
include/net/neighbour.h +0
-0struct neigh_ops {Fixes the crash for me!
Awesome. :)
--
Gustavo
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:
Quoted 11 lines · On Sat, 25 Nov 2023 15:33:58 -0600 you wrote:
Previously, one-element and zero-length arrays were treated as true flexible arrays, even though they are actually "fake" flex arrays. The
__randomize_layoutwould leave them untouched at the end of the struct, similarly to proper C99 flex-array members.However, this approach changed with commit
1ee60356c2dc("gcc-plugins:
randstruct: Only warn about true flexible arrays"). Now, only C99 flexible-array members will remain untouched at the end of the struct, while one-element and zero-length arrays will be subject to randomization.[...]
Here is the summary with links:
- neighbour: Fix __randomize_layout crash in struct neighbour
https://git.kernel.org/netdev/net/c/45b3fae4675d
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html