linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>,
	kernel test robot <lkp@intel.com>,
	Kees Cook <keescook@chromium.org>,
	Kalle Valo <kvalo@codeaurora.org>,
	Sasha Levin <sashal@kernel.org>,
	linux-wireless@vger.kernel.org, netdev@vger.kernel.org
Subject: [PATCH AUTOSEL 5.10 71/85] wl3501_cs: Fix out-of-bounds warnings in wl3501_send_pkt
Date: Wed,  5 May 2021 12:36:34 -0400	[thread overview]
Message-ID: <20210505163648.3462507-71-sashal@kernel.org> (raw)
In-Reply-To: <20210505163648.3462507-1-sashal@kernel.org>

From: "Gustavo A. R. Silva" <gustavoars@kernel.org>

[ Upstream commit 820aa37638a252b57967bdf4038a514b1ab85d45 ]

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: https://github.com/KSPP/linux/issues/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>
---
 drivers/net/wireless/wl3501.h    | 12 ++++++++----
 drivers/net/wireless/wl3501_cs.c | 10 ++++++----
 2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/drivers/net/wireless/wl3501.h b/drivers/net/wireless/wl3501.h
index b446cb369557..31ebef3e7ed4 100644
--- a/drivers/net/wireless/wl3501.h
+++ b/drivers/net/wireless/wl3501.h
@@ -471,8 +471,10 @@ struct wl3501_md_req {
 	u16	size;
 	u8	pri;
 	u8	service_class;
-	u8	daddr[ETH_ALEN];
-	u8	saddr[ETH_ALEN];
+	struct {
+		u8	daddr[ETH_ALEN];
+		u8	saddr[ETH_ALEN];
+	} addr;
 };
 
 struct wl3501_md_ind {
@@ -484,8 +486,10 @@ struct wl3501_md_ind {
 	u8	reception;
 	u8	pri;
 	u8	service_class;
-	u8	daddr[ETH_ALEN];
-	u8	saddr[ETH_ALEN];
+	struct {
+		u8	daddr[ETH_ALEN];
+		u8	saddr[ETH_ALEN];
+	} addr;
 };
 
 struct wl3501_md_confirm {
diff --git a/drivers/net/wireless/wl3501_cs.c b/drivers/net/wireless/wl3501_cs.c
index 026e88b80bfc..c3c859c4b2c7 100644
--- a/drivers/net/wireless/wl3501_cs.c
+++ b/drivers/net/wireless/wl3501_cs.c
@@ -471,6 +471,7 @@ static int wl3501_send_pkt(struct wl3501_card *this, u8 *data, u16 len)
 	struct wl3501_md_req sig = {
 		.sig_id = WL3501_SIG_MD_REQ,
 	};
+	size_t sig_addr_len = sizeof(sig.addr);
 	u8 *pdata = (char *)data;
 	int rc = -EIO;
 
@@ -486,9 +487,9 @@ static int wl3501_send_pkt(struct wl3501_card *this, u8 *data, u16 len)
 			goto out;
 		}
 		rc = 0;
-		memcpy(&sig.daddr[0], pdata, 12);
-		pktlen = len - 12;
-		pdata += 12;
+		memcpy(&sig.addr, pdata, sig_addr_len);
+		pktlen = len - sig_addr_len;
+		pdata += sig_addr_len;
 		sig.data = bf;
 		if (((*pdata) * 256 + (*(pdata + 1))) > 1500) {
 			u8 addr4[ETH_ALEN] = {
@@ -982,7 +983,8 @@ static inline void wl3501_md_ind_interrupt(struct net_device *dev,
 	} else {
 		skb->dev = dev;
 		skb_reserve(skb, 2); /* IP headers on 16 bytes boundaries */
-		skb_copy_to_linear_data(skb, (unsigned char *)&sig.daddr, 12);
+		skb_copy_to_linear_data(skb, (unsigned char *)&sig.addr,
+					sizeof(sig.addr));
 		wl3501_receive(this, skb->data, pkt_len);
 		skb_put(skb, pkt_len);
 		skb->protocol	= eth_type_trans(skb, dev);
-- 
2.30.2


  parent reply	other threads:[~2021-05-05 17:01 UTC|newest]

Thread overview: 85+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-05 16:35 [PATCH AUTOSEL 5.10 01/85] ath11k: fix thermal temperature read Sasha Levin
2021-05-05 16:35 ` [PATCH AUTOSEL 5.10 02/85] fs: dlm: fix debugfs dump Sasha Levin
2021-05-05 16:35 ` [PATCH AUTOSEL 5.10 03/85] fs: dlm: add errno handling to check callback Sasha Levin
2021-05-05 16:35 ` [PATCH AUTOSEL 5.10 04/85] fs: dlm: check on minimum msglen size Sasha Levin
2021-05-05 16:35 ` [PATCH AUTOSEL 5.10 05/85] fs: dlm: flush swork on shutdown Sasha Levin
2021-05-05 16:35 ` [PATCH AUTOSEL 5.10 06/85] tipc: convert dest node's address to network order Sasha Levin
2021-05-05 16:35 ` [PATCH AUTOSEL 5.10 07/85] ASoC: Intel: bytcr_rt5640: Enable jack-detect support on Asus T100TAF Sasha Levin
2021-05-05 16:35 ` [PATCH AUTOSEL 5.10 08/85] net/mlx5e: Use net_prefetchw instead of prefetchw in MPWQE TX datapath Sasha Levin
2021-05-05 16:35 ` [PATCH AUTOSEL 5.10 09/85] net: stmmac: Set FIFO sizes for ipq806x Sasha Levin
2021-05-05 16:35 ` [PATCH AUTOSEL 5.10 10/85] ASoC: rsnd: core: Check convert rate in rsnd_hw_params Sasha Levin
2021-05-05 16:35 ` [PATCH AUTOSEL 5.10 11/85] Documentation: networking: switchdev: fix command for static FDB entries Sasha Levin
2021-05-05 16:35 ` [PATCH AUTOSEL 5.10 12/85] Bluetooth: Fix incorrect status handling in LE PHY UPDATE event Sasha Levin
2021-05-05 16:35 ` [PATCH AUTOSEL 5.10 13/85] i2c: bail out early when RDWR parameters are wrong Sasha Levin
2021-05-05 16:35 ` [PATCH AUTOSEL 5.10 14/85] ALSA: hdsp: don't disable if not enabled Sasha Levin
2021-05-05 16:35 ` [PATCH AUTOSEL 5.10 15/85] ALSA: hdspm: " Sasha Levin
2021-05-05 16:35 ` [PATCH AUTOSEL 5.10 16/85] ALSA: rme9652: " Sasha Levin
2021-05-05 16:35 ` [PATCH AUTOSEL 5.10 17/85] ALSA: bebob: enable to deliver MIDI messages for multiple ports Sasha Levin
2021-05-05 16:35 ` [PATCH AUTOSEL 5.10 18/85] Bluetooth: Set CONF_NOT_COMPLETE as l2cap_chan default Sasha Levin
2021-05-05 16:35 ` [PATCH AUTOSEL 5.10 19/85] Bluetooth: verify AMP hci_chan before amp_destroy Sasha Levin
2021-05-05 16:35 ` [PATCH AUTOSEL 5.10 20/85] Bluetooth: initialize skb_queue_head at l2cap_chan_create() Sasha Levin
2021-05-05 16:35 ` [PATCH AUTOSEL 5.10 21/85] net/sched: cls_flower: use ntohs for struct flow_dissector_key_ports Sasha Levin
2021-05-05 16:35 ` [PATCH AUTOSEL 5.10 22/85] net: bridge: when suppression is enabled exclude RARP packets Sasha Levin
2021-05-05 16:35 ` [PATCH AUTOSEL 5.10 23/85] Bluetooth: check for zapped sk before connecting Sasha Levin
2021-05-05 16:35 ` [PATCH AUTOSEL 5.10 24/85] selftests/powerpc: Fix L1D flushing tests for Power10 Sasha Levin
2021-05-05 16:35 ` [PATCH AUTOSEL 5.10 25/85] powerpc/32: Statically initialise first emergency context Sasha Levin
2021-05-05 16:35 ` [PATCH AUTOSEL 5.10 26/85] net: hns3: remediate a potential overflow risk of bd_num_list Sasha Levin
2021-05-05 16:35 ` [PATCH AUTOSEL 5.10 27/85] net: hns3: add handling for xmit skb with recursive fraglist Sasha Levin
2021-05-05 16:35 ` [PATCH AUTOSEL 5.10 28/85] ip6_vti: proper dev_{hold|put} in ndo_[un]init methods Sasha Levin
2021-05-05 16:35 ` [PATCH AUTOSEL 5.10 29/85] ASoC: Intel: bytcr_rt5640: Add quirk for the Chuwi Hi8 tablet Sasha Levin
2021-05-05 16:35 ` [PATCH AUTOSEL 5.10 30/85] ice: handle increasing Tx or Rx ring sizes Sasha Levin
2021-05-05 16:35 ` [PATCH AUTOSEL 5.10 31/85] net: usb: ax88179_178a: initialize local variables before use Sasha Levin
2021-05-05 16:35 ` [PATCH AUTOSEL 5.10 32/85] Bluetooth: btusb: Enable quirk boolean flag for Mediatek Chip Sasha Levin
2021-05-05 16:35 ` [PATCH AUTOSEL 5.10 33/85] ASoC: rt5670: Add a quirk for the Dell Venue 10 Pro 5055 Sasha Levin
2021-05-05 16:35 ` [PATCH AUTOSEL 5.10 34/85] i2c: Add I2C_AQ_NO_REP_START adapter quirk Sasha Levin
2021-05-05 16:35 ` [PATCH AUTOSEL 5.10 35/85] MIPS: Loongson64: Use _CACHE_UNCACHED instead of _CACHE_UNCACHED_ACCELERATED Sasha Levin
2021-05-05 16:35 ` [PATCH AUTOSEL 5.10 36/85] coresight: Do not scan for graph if none is present Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 37/85] IB/hfi1: Correct oversized ring allocation Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 38/85] mac80211: clear the beacon's CRC after channel switch Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 39/85] pinctrl: samsung: use 'int' for register masks in Exynos Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 40/85] rtw88: 8822c: add LC calibration for RTL8822C Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 41/85] mt76: mt7615: support loading EEPROM for MT7613BE Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 42/85] mt76: mt76x0: disable GTK offloading Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 43/85] mt76: mt7915: fix txpower init for TSSI off chips Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 44/85] fuse: invalidate attrs when page writeback completes Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 45/85] virtiofs: fix userns Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 46/85] cuse: prevent clone Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 47/85] iwlwifi: pcie: make cfg vs. trans_cfg more robust Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 48/85] powerpc/mm: Add cond_resched() while removing hpte mappings Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 49/85] ASoC: rsnd: call rsnd_ssi_master_clk_start() from rsnd_ssi_init() Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 50/85] Revert "iommu/amd: Fix performance counter initialization" Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 51/85] iommu/amd: Remove performance counter pre-initialization test Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 52/85] drm/amd/display: Force vsync flip when reconfiguring MPCC Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 53/85] selftests: Set CC to clang in lib.mk if LLVM is set Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 54/85] kconfig: nconf: stop endless search loops Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 55/85] ALSA: hda/realtek: Add quirk for Lenovo Ideapad S740 Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 56/85] ASoC: Intel: sof_sdw: add quirk for new ADL-P Rvp Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 57/85] ALSA: hda/hdmi: fix race in handling acomp ELD notification at resume Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 58/85] sctp: Fix out-of-bounds warning in sctp_process_asconf_param() Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 59/85] flow_dissector: Fix out-of-bounds warning in __skb_flow_bpf_to_target() Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 60/85] powerpc/smp: Set numa node before updating mask Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 61/85] ASoC: rt286: Generalize support for ALC3263 codec Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 62/85] ethtool: ioctl: Fix out-of-bounds warning in store_link_ksettings_for_user() Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 63/85] net: sched: tapr: prevent cycle_time == 0 in parse_taprio_schedule Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 64/85] samples/bpf: Fix broken tracex1 due to kprobe argument change Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 65/85] powerpc/pseries: Stop calling printk in rtas_stop_self() Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 66/85] drm/amd/display: fixed divide by zero kernel crash during dsc enablement Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 67/85] drm/amd/display: add handling for hdcp2 rx id list validation Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 68/85] drm/amdgpu: Add mem sync flag for IB allocated by SA Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 69/85] mt76: mt7615: fix entering driver-own state on mt7663 Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 70/85] crypto: ccp: Free SEV device if SEV init fails Sasha Levin
2021-05-05 16:36 ` Sasha Levin [this message]
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 72/85] wl3501_cs: Fix out-of-bounds warnings in wl3501_mgmt_join Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 73/85] qtnfmac: Fix possible buffer overflow in qtnf_event_handle_external_auth Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 74/85] powerpc/iommu: Annotate nested lock for lockdep Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 75/85] iavf: remove duplicate free resources calls Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 76/85] net: ethernet: mtk_eth_soc: fix RX VLAN offload Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 77/85] selftests: mlxsw: Increase the tolerance of backlog buildup Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 78/85] selftests: mlxsw: Fix mausezahn invocation in ERSPAN scale test Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 79/85] kbuild: generate Module.symvers only when vmlinux exists Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 80/85] bnxt_en: Add PCI IDs for Hyper-V VF devices Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 81/85] ia64: module: fix symbolizer crash on fdescr Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 82/85] watchdog: rename __touch_watchdog() to a better descriptive name Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 83/85] watchdog: explicitly update timestamp when reporting softlockup Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 84/85] watchdog/softlockup: remove logic that tried to prevent repeated reports Sasha Levin
2021-05-05 16:36 ` [PATCH AUTOSEL 5.10 85/85] watchdog: fix barriers when printing backtraces from all CPUs Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210505163648.3462507-71-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=gustavoars@kernel.org \
    --cc=keescook@chromium.org \
    --cc=kvalo@codeaurora.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).