Skip to content

Commit 820aa37

Browse files
GustavoARSilvaKalle Valo
authored andcommitted
wl3501_cs: Fix out-of-bounds warnings in wl3501_send_pkt
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
1 parent ff9f732 commit 820aa37

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
@@ -469,6 +469,7 @@ static int wl3501_send_pkt(struct wl3501_card *this, u8 *data, u16 len)
469469
struct wl3501_md_req sig = {
470470
.sig_id = WL3501_SIG_MD_REQ,
471471
};
472+
size_t sig_addr_len = sizeof(sig.addr);
472473
u8 *pdata = (char *)data;
473474
int rc = -EIO;
474475

@@ -484,9 +485,9 @@ static int wl3501_send_pkt(struct wl3501_card *this, u8 *data, u16 len)
484485
goto out;
485486
}
486487
rc = 0;
487-
memcpy(&sig.daddr[0], pdata, 12);
488-
pktlen = len - 12;
489-
pdata += 12;
488+
memcpy(&sig.addr, pdata, sig_addr_len);
489+
pktlen = len - sig_addr_len;
490+
pdata += sig_addr_len;
490491
sig.data = bf;
491492
if (((*pdata) * 256 + (*(pdata + 1))) > 1500) {
492493
u8 addr4[ETH_ALEN] = {
@@ -980,7 +981,8 @@ static inline void wl3501_md_ind_interrupt(struct net_device *dev,
980981
} else {
981982
skb->dev = dev;
982983
skb_reserve(skb, 2); /* IP headers on 16 bytes boundaries */
983-
skb_copy_to_linear_data(skb, (unsigned char *)&sig.daddr, 12);
984+
skb_copy_to_linear_data(skb, (unsigned char *)&sig.addr,
985+
sizeof(sig.addr));
984986
wl3501_receive(this, skb->data, pkt_len);
985987
skb_put(skb, pkt_len);
986988
skb->protocol = eth_type_trans(skb, dev);

0 commit comments

Comments
 (0)