Skip to content

Commit ededc73

Browse files
GustavoARSilvagregkh
authored andcommitted
wl3501_cs: Fix out-of-bounds warnings in wl3501_mgmt_join
[ Upstream commit bb43e57 ] Fix the following out-of-bounds warnings by adding a new structure wl3501_req instead of duplicating the same members in structure wl3501_join_req and wl3501_scan_confirm: arch/x86/include/asm/string_32.h:182:25: warning: '__builtin_memcpy' offset [39, 108] from the object at 'sig' is out of the bounds of referenced subobject 'beacon_period' with type 'short unsigned int' at offset 36 [-Warray-bounds] arch/x86/include/asm/string_32.h:182:25: warning: '__builtin_memcpy' offset [25, 95] from the object at 'sig' is out of the bounds of referenced subobject 'beacon_period' with type 'short unsigned int' at offset 22 [-Warray-bounds] Refactor the code, accordingly: $ pahole -C wl3501_req drivers/net/wireless/wl3501_cs.o struct wl3501_req { u16 beacon_period; /* 0 2 */ u16 dtim_period; /* 2 2 */ u16 cap_info; /* 4 2 */ u8 bss_type; /* 6 1 */ u8 bssid[6]; /* 7 6 */ struct iw_mgmt_essid_pset ssid; /* 13 34 */ struct iw_mgmt_ds_pset ds_pset; /* 47 3 */ struct iw_mgmt_cf_pset cf_pset; /* 50 8 */ struct iw_mgmt_ibss_pset ibss_pset; /* 58 4 */ struct iw_mgmt_data_rset bss_basic_rset; /* 62 10 */ /* size: 72, cachelines: 2, members: 10 */ /* last cacheline: 8 bytes */ }; $ pahole -C wl3501_join_req drivers/net/wireless/wl3501_cs.o struct wl3501_join_req { u16 next_blk; /* 0 2 */ u8 sig_id; /* 2 1 */ u8 reserved; /* 3 1 */ struct iw_mgmt_data_rset operational_rset; /* 4 10 */ u16 reserved2; /* 14 2 */ u16 timeout; /* 16 2 */ u16 probe_delay; /* 18 2 */ u8 timestamp[8]; /* 20 8 */ u8 local_time[8]; /* 28 8 */ struct wl3501_req req; /* 36 72 */ /* size: 108, cachelines: 2, members: 10 */ /* last cacheline: 44 bytes */ }; $ pahole -C wl3501_scan_confirm drivers/net/wireless/wl3501_cs.o struct wl3501_scan_confirm { u16 next_blk; /* 0 2 */ u8 sig_id; /* 2 1 */ u8 reserved; /* 3 1 */ u16 status; /* 4 2 */ char timestamp[8]; /* 6 8 */ char localtime[8]; /* 14 8 */ struct wl3501_req req; /* 22 72 */ /* --- cacheline 1 boundary (64 bytes) was 30 bytes ago --- */ u8 rssi; /* 94 1 */ /* size: 96, cachelines: 2, members: 8 */ /* padding: 1 */ /* last cacheline: 32 bytes */ }; The problem is that the original code is trying to copy data into a bunch of struct members adjacent to each other in a single call to memcpy(). Now that a new struct wl3501_req enclosing all those adjacent members is introduced, memcpy() doesn't overrun the length of &sig.beacon_period and &this->bss_set[i].beacon_period, because the address of the new struct object _req_ is used as the destination, instead. This helps with the ongoing efforts to globally enable -Warray-bounds and get us closer to being able to tighten the FORTIFY_SOURCE routines on memcpy(). Link: KSPP/linux#109 Reported-by: kernel test robot <lkp@intel.com> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> Reviewed-by: Kees Cook <keescook@chromium.org> Signed-off-by: Kalle Valo <kvalo@codeaurora.org> Link: https://lore.kernel.org/r/1fbaf516da763b50edac47d792a9145aa4482e29.1618442265.git.gustavoars@kernel.org Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 83a7ed5 commit ededc73

2 files changed

Lines changed: 38 additions & 41 deletions

File tree

‎drivers/net/wireless/wl3501.h‎

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -379,16 +379,7 @@ struct wl3501_get_confirm {
379379
u8 mib_value[100];
380380
};
381381

382-
struct wl3501_join_req {
383-
u16 next_blk;
384-
u8 sig_id;
385-
u8 reserved;
386-
struct iw_mgmt_data_rset operational_rset;
387-
u16 reserved2;
388-
u16 timeout;
389-
u16 probe_delay;
390-
u8 timestamp[8];
391-
u8 local_time[8];
382+
struct wl3501_req {
392383
u16 beacon_period;
393384
u16 dtim_period;
394385
u16 cap_info;
@@ -401,6 +392,19 @@ struct wl3501_join_req {
401392
struct iw_mgmt_data_rset bss_basic_rset;
402393
};
403394

395+
struct wl3501_join_req {
396+
u16 next_blk;
397+
u8 sig_id;
398+
u8 reserved;
399+
struct iw_mgmt_data_rset operational_rset;
400+
u16 reserved2;
401+
u16 timeout;
402+
u16 probe_delay;
403+
u8 timestamp[8];
404+
u8 local_time[8];
405+
struct wl3501_req req;
406+
};
407+
404408
struct wl3501_join_confirm {
405409
u16 next_blk;
406410
u8 sig_id;
@@ -443,16 +447,7 @@ struct wl3501_scan_confirm {
443447
u16 status;
444448
char timestamp[8];
445449
char localtime[8];
446-
u16 beacon_period;
447-
u16 dtim_period;
448-
u16 cap_info;
449-
u8 bss_type;
450-
u8 bssid[ETH_ALEN];
451-
struct iw_mgmt_essid_pset ssid;
452-
struct iw_mgmt_ds_pset ds_pset;
453-
struct iw_mgmt_cf_pset cf_pset;
454-
struct iw_mgmt_ibss_pset ibss_pset;
455-
struct iw_mgmt_data_rset bss_basic_rset;
450+
struct wl3501_req req;
456451
u8 rssi;
457452
};
458453

‎drivers/net/wireless/wl3501_cs.c‎

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ static int wl3501_mgmt_join(struct wl3501_card *this, u16 stas)
592592
struct wl3501_join_req sig = {
593593
.sig_id = WL3501_SIG_JOIN_REQ,
594594
.timeout = 10,
595-
.ds_pset = {
595+
.req.ds_pset = {
596596
.el = {
597597
.id = IW_MGMT_INFO_ELEMENT_DS_PARAMETER_SET,
598598
.len = 1,
@@ -601,7 +601,7 @@ static int wl3501_mgmt_join(struct wl3501_card *this, u16 stas)
601601
},
602602
};
603603

604-
memcpy(&sig.beacon_period, &this->bss_set[stas].beacon_period, 72);
604+
memcpy(&sig.req, &this->bss_set[stas].req, sizeof(sig.req));
605605
return wl3501_esbq_exec(this, &sig, sizeof(sig));
606606
}
607607

@@ -669,35 +669,37 @@ static void wl3501_mgmt_scan_confirm(struct wl3501_card *this, u16 addr)
669669
if (sig.status == WL3501_STATUS_SUCCESS) {
670670
pr_debug("success");
671671
if ((this->net_type == IW_MODE_INFRA &&
672-
(sig.cap_info & WL3501_MGMT_CAPABILITY_ESS)) ||
672+
(sig.req.cap_info & WL3501_MGMT_CAPABILITY_ESS)) ||
673673
(this->net_type == IW_MODE_ADHOC &&
674-
(sig.cap_info & WL3501_MGMT_CAPABILITY_IBSS)) ||
674+
(sig.req.cap_info & WL3501_MGMT_CAPABILITY_IBSS)) ||
675675
this->net_type == IW_MODE_AUTO) {
676676
if (!this->essid.el.len)
677677
matchflag = 1;
678678
else if (this->essid.el.len == 3 &&
679679
!memcmp(this->essid.essid, "ANY", 3))
680680
matchflag = 1;
681-
else if (this->essid.el.len != sig.ssid.el.len)
681+
else if (this->essid.el.len != sig.req.ssid.el.len)
682682
matchflag = 0;
683-
else if (memcmp(this->essid.essid, sig.ssid.essid,
683+
else if (memcmp(this->essid.essid, sig.req.ssid.essid,
684684
this->essid.el.len))
685685
matchflag = 0;
686686
else
687687
matchflag = 1;
688688
if (matchflag) {
689689
for (i = 0; i < this->bss_cnt; i++) {
690-
if (ether_addr_equal_unaligned(this->bss_set[i].bssid, sig.bssid)) {
690+
if (ether_addr_equal_unaligned(this->bss_set[i].req.bssid,
691+
sig.req.bssid)) {
691692
matchflag = 0;
692693
break;
693694
}
694695
}
695696
}
696697
if (matchflag && (i < 20)) {
697-
memcpy(&this->bss_set[i].beacon_period,
698-
&sig.beacon_period, 73);
698+
memcpy(&this->bss_set[i].req,
699+
&sig.req, sizeof(sig.req));
699700
this->bss_cnt++;
700701
this->rssi = sig.rssi;
702+
this->bss_set[i].rssi = sig.rssi;
701703
}
702704
}
703705
} else if (sig.status == WL3501_STATUS_TIMEOUT) {
@@ -889,19 +891,19 @@ static void wl3501_mgmt_join_confirm(struct net_device *dev, u16 addr)
889891
if (this->join_sta_bss < this->bss_cnt) {
890892
const int i = this->join_sta_bss;
891893
memcpy(this->bssid,
892-
this->bss_set[i].bssid, ETH_ALEN);
893-
this->chan = this->bss_set[i].ds_pset.chan;
894+
this->bss_set[i].req.bssid, ETH_ALEN);
895+
this->chan = this->bss_set[i].req.ds_pset.chan;
894896
iw_copy_mgmt_info_element(&this->keep_essid.el,
895-
&this->bss_set[i].ssid.el);
897+
&this->bss_set[i].req.ssid.el);
896898
wl3501_mgmt_auth(this);
897899
}
898900
} else {
899901
const int i = this->join_sta_bss;
900902

901-
memcpy(&this->bssid, &this->bss_set[i].bssid, ETH_ALEN);
902-
this->chan = this->bss_set[i].ds_pset.chan;
903+
memcpy(&this->bssid, &this->bss_set[i].req.bssid, ETH_ALEN);
904+
this->chan = this->bss_set[i].req.ds_pset.chan;
903905
iw_copy_mgmt_info_element(&this->keep_essid.el,
904-
&this->bss_set[i].ssid.el);
906+
&this->bss_set[i].req.ssid.el);
905907
wl3501_online(dev);
906908
}
907909
} else {
@@ -1575,30 +1577,30 @@ static int wl3501_get_scan(struct net_device *dev, struct iw_request_info *info,
15751577
for (i = 0; i < this->bss_cnt; ++i) {
15761578
iwe.cmd = SIOCGIWAP;
15771579
iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1578-
memcpy(iwe.u.ap_addr.sa_data, this->bss_set[i].bssid, ETH_ALEN);
1580+
memcpy(iwe.u.ap_addr.sa_data, this->bss_set[i].req.bssid, ETH_ALEN);
15791581
current_ev = iwe_stream_add_event(info, current_ev,
15801582
extra + IW_SCAN_MAX_DATA,
15811583
&iwe, IW_EV_ADDR_LEN);
15821584
iwe.cmd = SIOCGIWESSID;
15831585
iwe.u.data.flags = 1;
1584-
iwe.u.data.length = this->bss_set[i].ssid.el.len;
1586+
iwe.u.data.length = this->bss_set[i].req.ssid.el.len;
15851587
current_ev = iwe_stream_add_point(info, current_ev,
15861588
extra + IW_SCAN_MAX_DATA,
15871589
&iwe,
1588-
this->bss_set[i].ssid.essid);
1590+
this->bss_set[i].req.ssid.essid);
15891591
iwe.cmd = SIOCGIWMODE;
1590-
iwe.u.mode = this->bss_set[i].bss_type;
1592+
iwe.u.mode = this->bss_set[i].req.bss_type;
15911593
current_ev = iwe_stream_add_event(info, current_ev,
15921594
extra + IW_SCAN_MAX_DATA,
15931595
&iwe, IW_EV_UINT_LEN);
15941596
iwe.cmd = SIOCGIWFREQ;
1595-
iwe.u.freq.m = this->bss_set[i].ds_pset.chan;
1597+
iwe.u.freq.m = this->bss_set[i].req.ds_pset.chan;
15961598
iwe.u.freq.e = 0;
15971599
current_ev = iwe_stream_add_event(info, current_ev,
15981600
extra + IW_SCAN_MAX_DATA,
15991601
&iwe, IW_EV_FREQ_LEN);
16001602
iwe.cmd = SIOCGIWENCODE;
1601-
if (this->bss_set[i].cap_info & WL3501_MGMT_CAPABILITY_PRIVACY)
1603+
if (this->bss_set[i].req.cap_info & WL3501_MGMT_CAPABILITY_PRIVACY)
16021604
iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
16031605
else
16041606
iwe.u.data.flags = IW_ENCODE_DISABLED;

0 commit comments

Comments
 (0)