lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <A4FF7C44-06C7-4241-B33E-1E9684A979E0@kernel.org>
Date: Tue, 16 Jul 2024 07:36:40 -0700
From: Kees Cook <kees@...nel.org>
To: Jeff Johnson <quic_jjohnson@...cinc.com>, Paolo Abeni <pabeni@...hat.com>,
 netdev@...r.kernel.org, Kees Cook <keescook@...omium.org>,
 "Paul E . McKenney" <paulmck@...nel.org>
CC: Kalle Valo <kvalo@...nel.org>, Jeff Johnson <jjohnson@...nel.org>,
 Baochen Qiang <quic_bqiang@...cinc.com>, linux-wireless@...r.kernel.org,
 ath12k@...ts.infradead.org, Jakub Kicinski <kuba@...nel.org>,
 "David S. Miller" <davem@...emloft.net>, Eric Dumazet <edumazet@...gle.com>
Subject: Re: [PATCH net] wifi: ath12k: fix build vs old compiler



On July 16, 2024 7:03:55 AM PDT, Jeff Johnson <quic_jjohnson@...cinc.com> wrote:
>On 7/16/2024 7:00 AM, Jeff Johnson wrote:
>> On 7/16/2024 4:06 AM, Paolo Abeni wrote:
>>> gcc 11.4.1-3 warns about memcpy() with overlapping pointers:
>>>
>>> drivers/net/wireless/ath/ath12k/wow.c: In function ‘ath12k_wow_convert_8023_to_80211.constprop’:
>>> ./include/linux/fortify-string.h:114:33: error: ‘__builtin_memcpy’ accessing 18446744073709551611 or more bytes at offsets 0 and 0 overlaps 9223372036854775799 bytes at offset -9223372036854775804 [-Werror=restrict]
>>>   114 | #define __underlying_memcpy     __builtin_memcpy
>>>       |                                 ^
>>> ./include/linux/fortify-string.h:637:9: note: in expansion of macro ‘__underlying_memcpy’
>>>   637 |         __underlying_##op(p, q, __fortify_size);                        \
>>>       |         ^~~~~~~~~~~~~
>>> ./include/linux/fortify-string.h:682:26: note: in expansion of macro ‘__fortify_memcpy_chk’
>>>   682 | #define memcpy(p, q, s)  __fortify_memcpy_chk(p, q, s,                  \
>>>       |                          ^~~~~~~~~~~~~~~~~~~~
>>> drivers/net/wireless/ath/ath12k/wow.c:190:25: note: in expansion of macro ‘memcpy’
>>>   190 |                         memcpy(pat, eth_pat, eth_pat_len);
>>>       |                         ^~~~~~
>>> ./include/linux/fortify-string.h:114:33: error: ‘__builtin_memcpy’ accessing 18446744073709551605 or more bytes at offsets 0 and 0 overlaps 9223372036854775787 bytes at offset -9223372036854775798 [-Werror=restrict]
>>>   114 | #define __underlying_memcpy     __builtin_memcpy
>>>       |                                 ^
>>> ./include/linux/fortify-string.h:637:9: note: in expansion of macro ‘__underlying_memcpy’
>>>   637 |         __underlying_##op(p, q, __fortify_size);                        \
>>>       |         ^~~~~~~~~~~~~
>>> ./include/linux/fortify-string.h:682:26: note: in expansion of macro ‘__fortify_memcpy_chk’
>>>   682 | #define memcpy(p, q, s)  __fortify_memcpy_chk(p, q, s,                  \
>>>       |                          ^~~~~~~~~~~~~~~~~~~~
>>> drivers/net/wireless/ath/ath12k/wow.c:232:25: note: in expansion of macro ‘memcpy’
>>>   232 |                         memcpy(pat, eth_pat, eth_pat_len);
>>>       |                         ^~~~~~
>>>
>>> The sum of size_t operands can overflow SIZE_MAX, triggering the
>>> warning.
>>> Address the issue using the suitable helper.
>>>
>>> Fixes: 4a3c212eee0e ("wifi: ath12k: add basic WoW functionalities")
>>> Signed-off-by: Paolo Abeni <pabeni@...hat.com>
>>> ---
>>> Only built tested. Sending directly to net to reduce the RTT, but no
>>> objections to go through the WiFi tree first
>>> ---
>>>  drivers/net/wireless/ath/ath12k/wow.c | 4 ++--
>>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/net/wireless/ath/ath12k/wow.c b/drivers/net/wireless/ath/ath12k/wow.c
>>> index c5cba825a84a..bead19db2c9a 100644
>>> --- a/drivers/net/wireless/ath/ath12k/wow.c
>>> +++ b/drivers/net/wireless/ath/ath12k/wow.c
>>> @@ -186,7 +186,7 @@ ath12k_wow_convert_8023_to_80211(struct ath12k *ar,
>>>  	if (eth_pkt_ofs < ETH_ALEN) {
>>>  		pkt_ofs = eth_pkt_ofs + a1_ofs;
>>>  
>>> -		if (eth_pkt_ofs + eth_pat_len < ETH_ALEN) {
>>> +		if (size_add(eth_pkt_ofs, eth_pat_len) < ETH_ALEN) {
>>>  			memcpy(pat, eth_pat, eth_pat_len);
>>>  			memcpy(bytemask, eth_bytemask, eth_pat_len);
>>>  
>>> @@ -228,7 +228,7 @@ ath12k_wow_convert_8023_to_80211(struct ath12k *ar,
>>>  	} else if (eth_pkt_ofs < prot_ofs) {
>>>  		pkt_ofs = eth_pkt_ofs - ETH_ALEN + a3_ofs;
>>>  
>>> -		if (eth_pkt_ofs + eth_pat_len < prot_ofs) {
>>> +		if (size_add(eth_pkt_ofs, eth_pat_len) < prot_ofs) {
>>>  			memcpy(pat, eth_pat, eth_pat_len);
>>>  			memcpy(bytemask, eth_bytemask, eth_pat_len);
>>>  
>> 
>> Duplicate of https://msgid.link/20240704144341.207317-1-kvalo@kernel.org ??
>
>Let me add Kees & Paul to see if they prefer your solution

Heh, yeah, that works too! Avoid the overflow via saturating addition.

Reviewed-by: Kees Cook<kees@...nel.org>

-- 
Kees Cook

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ