wifi: mac80211: add __packed to union members of struct ieee80211_rx_status
PATCH 1/1 wifi: mac80211: add __packed to union members of struct ieee80211_rx_status
The arm-linux-gnueabi-gcc compiler, align the field followed by union members, causing size of struct ieee80211_rx_status over skb->cb (48 bytes). By investigation, the union member starts at offset 32, and the offset of next field rate_idx is 36 instead of expected 33, and the total size is (unexpected) 52.
When compiling rtw88 driver, it throws:
In file included from /work/linux-src/linux-stable/include/linux/string.h:386,
from /work/linux-src/linux-stable/include/linux/bitmap.h:13,
from /work/linux-src/linux-stable/include/linux/cpumask.h:11,
from /work/linux-src/linux-stable/include/linux/smp.h:13,
from /work/linux-src/linux-stable/include/linux/lockdep.h:14,
from /work/linux-src/linux-stable/include/linux/mutex.h:17,
from /work/linux-src/linux-stable/include/linux/kernfs.h:11,
from /work/linux-src/linux-stable/include/linux/sysfs.h:16,
from /work/linux-src/linux-stable/include/linux/kobject.h:20,
from /work/linux-src/linux-stable/include/linux/dmi.h:6,
from pci.c:5:
In function 'fortify_memcpy_chk',
inlined from 'rtw_pci_rx_napi.constprop' at pci.c:1095:4:
/work/linux-src/linux-stable/include/linux/fortify-string.h:569:25: warning: call to '__write_overflow_field' declared with attribute warning: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Wattribute-warning]
569 | __write_overflow_field(p_size_field, size);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~After this patch, the size of struct ieee80211_rx_status is 48.
---
Because of size assertion of rtw88's efuse map [1], I found arm-linux-gnueabi-gcc compiler throws this warning, but x86 gcc is absolutely silent and expected without this patch.
--- include/net/mac80211.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
include/net/mac80211.h +6 -4
@@ -1747,18 +1747,18 @@ struct ieee80211_rx_status { u8 he_ru:3; u8 he_gi:2; u8 he_dcm:1; - }; + } __packed;struct {u8 ru:4 ;u8 gi:2 ; - } eht; + } __packed eht;struct {u8 ru:4 ;u8 gi:2 ;u8 elr:1 ;u8 im:1 ; - } uhr; - }; + } __packed uhr; + } __packed;u8 rate_idx;u8 nss;u8 rx_flags;
@@ -1771,6 +1771,8 @@ struct ieee80211_rx_status { u8 link_valid:1, link_id:4; }; +static_assert(sizeof(struct ieee80211_rx_status) <= sizeof_field(struct sk_buff, cb)); +static inline u32 ieee80211_rx_status_to_khz (struct ieee80211_rx_status *rx_status) {
Signature · 1 line
2.25.1
Quoted 30 lines · Ping-Ke Shih
The arm-linux-gnueabi-gcc compiler, align the field followed by union members, causing size of struct
ieee80211_rx_statusoverskb->cb(48 bytes). By investigation, the union member starts at offset 32, and the offset of next fieldrate_idxis 36 instead of expected 33, and the total size is (unexpected) 52.When compiling rtw88 driver, it throws:
In file included from /work/linux-src/linux-stable/include/linux/string.h:386,
from /work/linux-src/linux-stable/include/linux/bitmap.h:13, from /work/linux-src/linux-stable/include/linux/cpumask.h:11, from /work/linux-src/linux-stable/include/linux/smp.h:13, from /work/linux-src/linux-stable/include/linux/lockdep.h:14, from /work/linux-src/linux-stable/include/linux/mutex.h:17, from /work/linux-src/linux-stable/include/linux/kernfs.h:11, from /work/linux-src/linux-stable/include/linux/sysfs.h:16, from /work/linux-src/linux-stable/include/linux/kobject.h:20, from /work/linux-src/linux-stable/include/linux/dmi.h:6, from pci.c:5: In function 'fortify_memcpy_chk', inlined from 'rtw_pci_rx_napi.constprop' at pci.c:1095:4: /work/linux-src/linux-stable/include/linux/fortify-string.h:569:25: warning: call to '__write_overflow_field' declared with attribute warning: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Wattribute-warning] 569 | __write_overflow_field(p_size_field, size); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~After this patch, the size of struct
ieee80211_rx_statusis 48.Signed-off-by Ping-Ke Shih <[email protected]>
Quoted 8 lines
---
Because of size assertion of rtw88's efuse map [1], I found arm-linux-gnueabi-gcc compiler throws this warning, but x86 gcc is absolutely silent and expected without this patch.[1]
https://lore.kernel.org/linux-wireless/[email protected]/T/#m43fdf8a1c2b8cff92c1ef50faab7993522647162
I'd note that discussion thread [2] of original kernel test robot. Arnd pointed out the cause is CONFIG_AEABI is not set, and he said nobody should be using ARM OABI any more.
Maybe, we can ignore the CPU and skip this patch.
Johannes Berg
maintainerQuoted 4 lines · Ping-Ke Shih
Quoted 4 lines
Because of size assertion of rtw88's efuse map [1], I found arm-linux-gnueabi-gcc compiler throws this warning, but x86 gcc is absolutely silent and expected without this patch.
Yeah, depends on ABI padding rules.
Quoted 7 lines
Quoted 3 lines
[1]
https://lore.kernel.org/linux-wireless/[email protected]/T/#m43fdf8a1c2b8cff92c1ef50faab7993522647162I'd note that discussion thread [2] of original kernel test robot. Arnd pointed out the cause is
CONFIG_AEABIis not set, and he said nobody should be using ARM OABI any more.
Ah, right.
Quoted 1 line
Maybe, we can ignore the CPU and skip this patch.
Given that nobody complained in many years about not being able to use wifi on those machines, I'd be inclined to just do that, yeah. But thanks for digging into it!
johannes