2023-06-20 06:33:29

by Dmitry Antipov

[permalink] [raw]
Subject: ath12k: memcpy() source buffer overread

When compiling with gcc 13.1 and CONFIG_FORTIFY_SOURCE=y, I've noticed the following:

...
In function ‘fortify_memcpy_chk’,
inlined from ‘ath12k_peer_assoc_h_he’ at drivers/net/wireless/ath/ath12k/mac.c:1640:2,
inlined from ‘ath12k_peer_assoc_prepare’ at drivers/net/wireless/ath/ath12k/mac.c:2027:2:
./include/linux/fortify-string.h:529:25: warning: call to ‘__read_overflow2_field’ declared with
attribute warning: detected read beyond size of field (2nd parameter); maybe use struct_group()?
[-Wattribute-warning]
529 | __read_overflow2_field(q_size_field, size);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In function ‘fortify_memcpy_chk’,
inlined from ‘ath12k_peer_assoc_h_he’ at drivers/net/wireless/ath/ath12k/mac.c:1643:2,
inlined from ‘ath12k_peer_assoc_prepare’ at drivers/net/wireless/ath/ath12k/mac.c:2027:2:
./include/linux/fortify-string.h:529:25: warning: call to ‘__read_overflow2_field’ declared with
attribute warning: detected read beyond size of field (2nd parameter); maybe use struct_group()?
[-Wattribute-warning]
529 | __read_overflow2_field(q_size_field, size);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...

And this seems correct because:

/* dst: u32[2], src: u8[6], size: 8 so 2 byte source overread */
memcpy(&arg->peer_he_cap_macinfo, he_cap->he_cap_elem.mac_cap_info,
sizeof(arg->peer_he_cap_macinfo));

and:

/* dst: u32[3], src: u8[11], size: 12 so 1 byte source overread */
memcpy(&arg->peer_he_cap_phyinfo, he_cap->he_cap_elem.phy_cap_info,
sizeof(arg->peer_he_cap_phyinfo));

Dmitry


2023-08-03 13:58:29

by Kalle Valo

[permalink] [raw]
Subject: Re: ath12k: memcpy() source buffer overread

+ ath12k list

Dmitry Antipov <[email protected]> writes:

> When compiling with gcc 13.1 and CONFIG_FORTIFY_SOURCE=y, I've noticed the following:
>
> ...
> In function ‘fortify_memcpy_chk’,
> inlined from ‘ath12k_peer_assoc_h_he’ at drivers/net/wireless/ath/ath12k/mac.c:1640:2,
> inlined from ‘ath12k_peer_assoc_prepare’ at drivers/net/wireless/ath/ath12k/mac.c:2027:2:
> ./include/linux/fortify-string.h:529:25: warning: call to ‘__read_overflow2_field’ declared with
> attribute warning: detected read beyond size of field (2nd parameter); maybe use struct_group()?
> [-Wattribute-warning]
> 529 | __read_overflow2_field(q_size_field, size);
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> In function ‘fortify_memcpy_chk’,
> inlined from ‘ath12k_peer_assoc_h_he’ at drivers/net/wireless/ath/ath12k/mac.c:1643:2,
> inlined from ‘ath12k_peer_assoc_prepare’ at drivers/net/wireless/ath/ath12k/mac.c:2027:2:
> ./include/linux/fortify-string.h:529:25: warning: call to ‘__read_overflow2_field’ declared with
> attribute warning: detected read beyond size of field (2nd parameter); maybe use struct_group()?
> [-Wattribute-warning]
> 529 | __read_overflow2_field(q_size_field, size);
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ...
>
> And this seems correct because:
>
> /* dst: u32[2], src: u8[6], size: 8 so 2 byte source overread */
> memcpy(&arg->peer_he_cap_macinfo, he_cap->he_cap_elem.mac_cap_info,
> sizeof(arg->peer_he_cap_macinfo));
>
> and:
>
> /* dst: u32[3], src: u8[11], size: 12 so 1 byte source overread */
> memcpy(&arg->peer_he_cap_phyinfo, he_cap->he_cap_elem.phy_cap_info,
> sizeof(arg->peer_he_cap_phyinfo));

Arnd fixed this:

https://git.kernel.org/kvalo/ath/c/603cf6c2fcdc

--
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches