Skip to content

Commit 83a7ed5

Browse files
GustavoARSilvagregkh
authored andcommitted
wl3501_cs: Fix out-of-bounds warnings in wl3501_send_pkt
[ Upstream commit 820aa37 ] Fix the following out-of-bounds warnings by enclosing structure members daddr and saddr into new struct addr, in structures wl3501_md_req and wl3501_md_ind: arch/x86/include/asm/string_32.h:182:25: warning: '__builtin_memcpy' offset [18, 23] from the object at 'sig' is out of the bounds of referenced subobject 'daddr' with type 'u8[6]' {aka 'unsigned char[6]'} at offset 11 [-Warray-bounds] arch/x86/include/asm/string_32.h:182:25: warning: '__builtin_memcpy' offset [18, 23] from the object at 'sig' is out of the bounds of referenced subobject 'daddr' with type 'u8[6]' {aka 'unsigned char[6]'} at offset 11 [-Warray-bounds] Refactor the code, accordingly: $ pahole -C wl3501_md_req drivers/net/wireless/wl3501_cs.o struct wl3501_md_req { u16 next_blk; /* 0 2 */ u8 sig_id; /* 2 1 */ u8 routing; /* 3 1 */ u16 data; /* 4 2 */ u16 size; /* 6 2 */ u8 pri; /* 8 1 */ u8 service_class; /* 9 1 */ struct { u8 daddr[6]; /* 10 6 */ u8 saddr[6]; /* 16 6 */ } addr; /* 10 12 */ /* size: 22, cachelines: 1, members: 8 */ /* last cacheline: 22 bytes */ }; $ pahole -C wl3501_md_ind drivers/net/wireless/wl3501_cs.o struct wl3501_md_ind { u16 next_blk; /* 0 2 */ u8 sig_id; /* 2 1 */ u8 routing; /* 3 1 */ u16 data; /* 4 2 */ u16 size; /* 6 2 */ u8 reception; /* 8 1 */ u8 pri; /* 9 1 */ u8 service_class; /* 10 1 */ struct { u8 daddr[6]; /* 11 6 */ u8 saddr[6]; /* 17 6 */ } addr; /* 11 12 */ /* size: 24, cachelines: 1, members: 9 */ /* padding: 1 */ /* last cacheline: 24 bytes */ }; The problem is that the original code is trying to copy data into a couple of arrays adjacent to each other in a single call to memcpy(). Now that a new struct _addr_ enclosing those two adjacent arrays is introduced, memcpy() doesn't overrun the length of &sig.daddr[0] and &sig.daddr, because the address of the new struct object _addr_ is used, 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> Reviewed-by: Kees Cook <keescook@chromium.org> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> Signed-off-by: Kalle Valo <kvalo@codeaurora.org> Link: https://lore.kernel.org/r/d260fe56aed7112bff2be5b4d152d03ad7b78e78.1618442265.git.gustavoars@kernel.org Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent f3a5dee commit 83a7ed5

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

‎drivers/net/wireless/wl3501.h‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,10 @@ struct wl3501_md_req {
471471
u16 size;
472472
u8 pri;
473473
u8 service_class;
474-
u8 daddr[ETH_ALEN];
475-
u8 saddr[ETH_ALEN];
474+
struct {
475+
u8 daddr[ETH_ALEN];
476+
u8 saddr[ETH_ALEN];
477+
} addr;
476478
};
477479

478480
struct wl3501_md_ind {
@@ -484,8 +486,10 @@ struct wl3501_md_ind {
484486
u8 reception;
485487
u8 pri;
486488
u8 service_class;
487-
u8 daddr[ETH_ALEN];
488-
u8 saddr[ETH_ALEN];
489+
struct {
490+
u8 daddr[ETH_ALEN];
491+
u8 saddr[ETH_ALEN];
492+
} addr;
489493
};
490494

491495
struct wl3501_md_confirm {

‎drivers/net/wireless/wl3501_cs.c‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ static int wl3501_send_pkt(struct wl3501_card *this, u8 *data, u16 len)
471471
struct wl3501_md_req sig = {
472472
.sig_id = WL3501_SIG_MD_REQ,
473473
};
474+
size_t sig_addr_len = sizeof(sig.addr);
474475
u8 *pdata = (char *)data;
475476
int rc = -EIO;
476477

@@ -486,9 +487,9 @@ static int wl3501_send_pkt(struct wl3501_card *this, u8 *data, u16 len)
486487
goto out;
487488
}
488489
rc = 0;
489-
memcpy(&sig.daddr[0], pdata, 12);
490-
pktlen = len - 12;
491-
pdata += 12;
490+
memcpy(&sig.addr, pdata, sig_addr_len);
491+
pktlen = len - sig_addr_len;
492+
pdata += sig_addr_len;
492493
sig.data = bf;
493494
if (((*pdata) * 256 + (*(pdata + 1))) > 1500) {
494495
u8 addr4[ETH_ALEN] = {
@@ -982,7 +983,8 @@ static inline void wl3501_md_ind_interrupt(struct net_device *dev,
982983
} else {
983984
skb->dev = dev;
984985
skb_reserve(skb, 2); /* IP headers on 16 bytes boundaries */
985-
skb_copy_to_linear_data(skb, (unsigned char *)&sig.daddr, 12);
986+
skb_copy_to_linear_data(skb, (unsigned char *)&sig.addr,
987+
sizeof(sig.addr));
986988
wl3501_receive(this, skb->data, pkt_len);
987989
skb_put(skb, pkt_len);
988990
skb->protocol = eth_type_trans(skb, dev);

0 commit comments

Comments
 (0)