History

staging: rtl8723bs: Allocate full pwep structure

The pwep allocation was always being allocated smaller than the true structure size. Avoid this by always allocating the full structure. Found with GCC 12 and -Warray-bounds: ../drivers/staging/rtl8723bs/os_dep/ioctl_linux.c: In function 'rtw_set_encryption': ../drivers/staging/rtl8723bs/os_dep/ioctl_linux.c:591:29: warning: array subscript 'struct ndis_802_11_wep[0]' is partly outside array bounds of 'void[25]' [-Warray-bounds] 591 | pwep->length = wep_total_len; | ^~

Kees Cook committed 4 years ago

Commit 67ea0a21 parent de0952f1 file · +4 −2Browse files

Unified · Split

drivers/staging/rtl8723bs/os_dep/ioctl_linux.c+4−2
@@ -90,7 +90,8 @@ static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param, · 89 unmodified lines
90 if (wep_key_len > 0) {90 if (wep_key_len > 0) {
91 wep_key_len = wep_key_len <= 5 ? 5 : 13;91 wep_key_len = wep_key_len <= 5 ? 5 : 13;
92 wep_total_len = wep_key_len + FIELD_OFFSET(struct ndis_802_11_wep, key_material);92 wep_total_len = wep_key_len + FIELD_OFFSET(struct ndis_802_11_wep, key_material);
93 pwep = kzalloc(wep_total_len, GFP_KERNEL);93 /* Allocate a full structure to avoid potentially running off the end. */
94 pwep = kzalloc(sizeof(*pwep), GFP_KERNEL);
94 if (!pwep) {95 if (!pwep) {
95 ret = -ENOMEM;96 ret = -ENOMEM;
96 goto exit;97 goto exit;
@@ -582,7 +583,8 @@ static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param, · 485 unmodified lines
582 if (wep_key_len > 0) {583 if (wep_key_len > 0) {
583 wep_key_len = wep_key_len <= 5 ? 5 : 13;584 wep_key_len = wep_key_len <= 5 ? 5 : 13;
584 wep_total_len = wep_key_len + FIELD_OFFSET(struct ndis_802_11_wep, key_material);585 wep_total_len = wep_key_len + FIELD_OFFSET(struct ndis_802_11_wep, key_material);
585 pwep = kzalloc(wep_total_len, GFP_KERNEL);586 /* Allocate a full structure to avoid potentially running off the end. */
587 pwep = kzalloc(sizeof(*pwep), GFP_KERNEL);
586 if (!pwep)588 if (!pwep)
587 goto exit;589 goto exit;
588 590

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t