Skip to content

Commit 96c677f

Browse files
keeskuba-moo
authored andcommitted
UAPI: ethtool: Avoid flex-array in struct ethtool_link_settings
struct ethtool_link_settings tends to be used as a header for other structures that have trailing bytes[1], but has a trailing flexible array itself. Using this overlapped with other structures leads to ambiguous object sizing in the compiler, so we want to avoid such situations (which have caused real bugs in the past). Detecting this can be done with -Wflex-array-member-not-at-end, which will need to be enabled globally. Using a tagged struct_group() to create a new ethtool_link_settings_hdr structure isn't possible as it seems we cannot use the tagged variant of struct_group() due to syntax issues from C++'s perspective (even within "extern C")[2]. Instead, we can just leave the offending member defined in UAPI and remove it from the kernel's view of the structure, as Linux doesn't actually use this member at all. There is also no change in size since it was already a flexible array that didn't contribute to size returned by any use of sizeof(). Reported-by: Jakub Kicinski <[email protected]> Closes: https://lore.kernel.org/lkml/[email protected]/ [2] Link: https://lore.kernel.org/lkml/0bc2809fe2a6c11dd4c8a9a10d9bd65cccdb559b.1730238285.git.gustavoars@kernel.org/ [1] Signed-off-by: Kees Cook <[email protected]> Reviewed-by: Jakub Kicinski <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent ebda123 commit 96c677f

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

include/uapi/linux/ethtool.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2526,12 +2526,19 @@ struct ethtool_link_settings {
25262526
__u8 master_slave_state;
25272527
__u8 rate_matching;
25282528
__u32 reserved[7];
2529+
#ifndef __KERNEL__
2530+
/* Linux builds with -Wflex-array-member-not-at-end but does
2531+
* not use the "link_mode_masks" member. Leave it defined for
2532+
* userspace for now, and when userspace wants to start using
2533+
* -Wfamnae, we'll need a new solution.
2534+
*/
25292535
__u32 link_mode_masks[];
25302536
/* layout of link_mode_masks fields:
25312537
* __u32 map_supported[link_mode_masks_nwords];
25322538
* __u32 map_advertising[link_mode_masks_nwords];
25332539
* __u32 map_lp_advertising[link_mode_masks_nwords];
25342540
*/
2541+
#endif
25352542
};
25362543

25372544
/**

0 commit comments

Comments
 (0)