Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

staging: rtl8723bs: Drop get_recvframe_data()

When building with -Warray-bounds, the following warning is emitted:

In file included from ./include/linux/string.h:253,
from ./arch/x86/include/asm/page_32.h:22,
from ./arch/x86/include/asm/page.h:14,
from ./arch/x86/include/asm/thread_info.h:12,
from ./include/linux/thread_info.h:60,
from ./arch/x86/include/asm/preempt.h:7,
from ./include/linux/preempt.h:78,
from ./include/linux/rcupdate.h:27,
from ./include/linux/rculist.h:11,
from ./include/linux/sched/signal.h:5,
from ./drivers/staging/rtl8723bs/include/drv_types.h:17,
from drivers/staging/rtl8723bs/core/rtw_recv.c:7:
In function 'memcpy',
inlined from 'wlanhdr_to_ethhdr' at drivers/staging/rtl8723bs/core/rtw_recv.c:1554:2:
./include/linux/fortify-string.h:41:33: warning: '__builtin_memcpy' offset [0, 5] is out of the bounds [0, 0] [-Warray-bounds]
41 | #define __underlying_memcpy __builtin_memcpy
| ^

This is because the compiler sees it is possible for "ptr" to be a NULL
value, and concludes that it has zero size and attempts to copy to it
would overflow. Instead, remove the get_recvframe_data() entirely, as
it's not possible for this to ever be NULL.

Additionally add missing NULL checks after recvframe_pull() (which are
present in the rtl8712 driver).

Cc: Larry Finger <Larry.Finger@lwfinger.net>
Cc: Phillip Potter <phil@philpotter.co.uk>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Michael Straube <straube.linux@gmail.com>
Cc: Fabio Aiuto <fabioaiuto83@gmail.com>
Cc: linux-staging@lists.linux.dev
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20220118193327.2822099-3-keescook@chromium.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Kees Cook and committed by
Greg Kroah-Hartman
c146ae45 6fb5d25a

+9 -16
+8 -3
drivers/staging/rtl8723bs/core/rtw_recv.c
··· 465 465 466 466 auth_alg = adapter->securitypriv.dot11AuthAlgrthm; 467 467 468 - ptr = get_recvframe_data(precv_frame); 468 + ptr = precv_frame->u.hdr.rx_data; 469 469 pfhdr = &precv_frame->u.hdr; 470 470 pattrib = &pfhdr->attrib; 471 471 psta_addr = pattrib->ta; ··· 1510 1510 __be16 be_tmp; 1511 1511 struct adapter *adapter = precvframe->u.hdr.adapter; 1512 1512 struct mlme_priv *pmlmepriv = &adapter->mlmepriv; 1513 - u8 *ptr = get_recvframe_data(precvframe) ; /* point to frame_ctrl field */ 1513 + u8 *ptr = precvframe->u.hdr.rx_data; /* point to frame_ctrl field */ 1514 1514 struct rx_pkt_attrib *pattrib = &precvframe->u.hdr.attrib; 1515 1515 1516 1516 if (pattrib->encrypt) ··· 1546 1546 eth_type = 0x8712; 1547 1547 /* append rx status for mp test packets */ 1548 1548 ptr = recvframe_pull(precvframe, (rmv_len-sizeof(struct ethhdr)+2)-24); 1549 + if (!ptr) 1550 + return _FAIL; 1549 1551 memcpy(ptr, get_rxmem(precvframe), 24); 1550 1552 ptr += 24; 1551 - } else 1553 + } else { 1552 1554 ptr = recvframe_pull(precvframe, (rmv_len-sizeof(struct ethhdr) + (bsnaphdr?2:0))); 1555 + if (!ptr) 1556 + return _FAIL; 1557 + } 1553 1558 1554 1559 memcpy(ptr, pattrib->dst, ETH_ALEN); 1555 1560 memcpy(ptr+ETH_ALEN, pattrib->src, ETH_ALEN);
+1 -2
drivers/staging/rtl8723bs/hal/rtl8723bs_recv.c
··· 81 81 struct odm_phy_info *p_phy_info = 82 82 (struct odm_phy_info *)(&pattrib->phy_info); 83 83 84 - u8 *wlanhdr; 84 + u8 *wlanhdr = precvframe->u.hdr.rx_data; 85 85 u8 *my_bssid; 86 86 u8 *rx_bssid; 87 87 u8 *rx_ra; ··· 100 100 struct sta_priv *pstapriv; 101 101 struct sta_info *psta; 102 102 103 - wlanhdr = get_recvframe_data(precvframe); 104 103 my_bssid = get_bssid(&padapter->mlmepriv); 105 104 rx_bssid = get_hdr_bssid(wlanhdr); 106 105 pkt_info.bssid_match = ((!IsFrameTypeCtrl(wlanhdr)) &&
-11
drivers/staging/rtl8723bs/include/rtw_recv.h
··· 385 385 return precvframe->u.hdr.rx_head; 386 386 } 387 387 388 - static inline u8 *get_recvframe_data(union recv_frame *precvframe) 389 - { 390 - 391 - /* alwasy return rx_data */ 392 - if (precvframe == NULL) 393 - return NULL; 394 - 395 - return precvframe->u.hdr.rx_data; 396 - 397 - } 398 - 399 388 static inline u8 *recvframe_pull(union recv_frame *precvframe, signed int sz) 400 389 { 401 390 /* rx_data += sz; move rx_data sz bytes hereafter */