From patchwork Wed Mar 31 21:15:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 413322 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-21.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E658BC43461 for ; Wed, 31 Mar 2021 22:16:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B96266108D for ; Wed, 31 Mar 2021 22:16:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232356AbhCaWPs (ORCPT ); Wed, 31 Mar 2021 18:15:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:48292 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232883AbhCaWPh (ORCPT ); Wed, 31 Mar 2021 18:15:37 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E543461005; Wed, 31 Mar 2021 22:15:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617228937; bh=bHCa1+1sKMV7qL9XWxievJw5T0POVXZgXEOWZMjFrNQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=qq0nqBTU6nhZd1s+xYWtYFiQepyHuKnHMX6VWxGU9QNpQ66AfGVQPIxZujhqsZc62 VPiN3xfwQp6eWFH+mLGbiZJXCnvZ0gzzWvv+X1x1lX3MErylIsCktUrOmV7xzq/Owi uBJsmwYTjlHeuhtOF9O3EBiroQf0dyOtpNrPDjaFfImNXQuugQYQwaA0sSqeaim3eU b/EuZ4Uomxeq0G0GD6kdD0JGZnEhHfPgqLa1OFg7qLe97JV3l9+hj93Mhlo7HN3SeY YzVspawCBv37PzVF6mVwzU6wvNKGxYjGuLNiaA1cgtebJHrLF4FVW5EFUMIjdIFNN6 5V9Blb0dWWbEw== Date: Wed, 31 Mar 2021 16:15:39 -0500 From: "Gustavo A. R. Silva" To: linux-kernel@vger.kernel.org Cc: Kalle Valo , "David S. Miller" , Jakub Kicinski , linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-hardening@vger.kernel.org, "Gustavo A. R. Silva" Subject: [PATCH 1/2][next] wl3501_cs: Fix out-of-bounds warning in wl3501_send_pkt Message-ID: <596a83e3e4729bc24c0b3eda45cda2aa28998f88.1617223928.git.gustavoars@kernel.org> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Fix the following out-of-bounds warning by enclosing structure members daddr and saddr into new struct addr: 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 */ }; 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.addr, because the address of the new struct object _addr_ is used as destination, instead. Also, this helps with the ongoing efforts to enable -Warray-bounds and avoid confusing the compiler. Link: https://github.com/KSPP/linux/issues/109 Reported-by: kernel test robot Build-tested-by: kernel test robot Link: https://lore.kernel.org/lkml/60641d9b.2eNLedOGSdcSoAV2%25lkp@intel.com/ Signed-off-by: Gustavo A. R. Silva --- drivers/net/wireless/wl3501.h | 6 ++++-- drivers/net/wireless/wl3501_cs.c | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/wl3501.h b/drivers/net/wireless/wl3501.h index e98e04ee9a2c..ef9d605d8c88 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 { diff --git a/drivers/net/wireless/wl3501_cs.c b/drivers/net/wireless/wl3501_cs.c index 8ca5789c7b37..384bf84dfa51 100644 --- a/drivers/net/wireless/wl3501_cs.c +++ b/drivers/net/wireless/wl3501_cs.c @@ -484,7 +484,7 @@ static int wl3501_send_pkt(struct wl3501_card *this, u8 *data, u16 len) goto out; } rc = 0; - memcpy(&sig.daddr[0], pdata, 12); + memcpy(&sig.addr, pdata, sizeof(sig.addr)); pktlen = len - 12; pdata += 12; sig.data = bf; From patchwork Wed Mar 31 21:16:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 414112 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-21.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DCD89C43462 for ; Wed, 31 Mar 2021 22:16:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AF96F61078 for ; Wed, 31 Mar 2021 22:16:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232774AbhCaWQU (ORCPT ); Wed, 31 Mar 2021 18:16:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:48608 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232690AbhCaWQS (ORCPT ); Wed, 31 Mar 2021 18:16:18 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4E4EC61078; Wed, 31 Mar 2021 22:16:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617228978; bh=xv2nMo0980+R4VBEMhqDRwLR+Gyzx7lAAhs5zECqVf8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=EP5yEiZcPdBfm84R7Erudu4P+Ykp/t3sOH86Vqr+VESINUOLK3OjOsfbdMvs8ib1n vSbMEuECzJng0AkmVaTuFbbwjXURj5ETlCMyg89UVId+/1i1xnGQeahgQzTuNF5Kvl 64Vv6l9lBFKPHfZP77MCPS2c7cXYq7cRWVbXf0FqBifqy8pUJ3tCqvpG3FwsIg02O/ d7psiI+grrQF2qx6mNk1Ijl/mQLxR5ONRuhPH00NJWD5QAlGlBgVCYSCn2fYX84IjL Apj0P8H+B+VcxASA0RvXbk2+FmBo4rhU5zN0eD0Dx9UP2VjpGoi40ndyv8Ph2GRMaS UGUz2xA+UGeWw== Date: Wed, 31 Mar 2021 16:16:20 -0500 From: "Gustavo A. R. Silva" To: linux-kernel@vger.kernel.org Cc: Kalle Valo , "David S. Miller" , Jakub Kicinski , linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-hardening@vger.kernel.org, "Gustavo A. R. Silva" Subject: [PATCH 2/2][next] wl3501_cs: Fix out-of-bounds warning in wl3501_mgmt_join Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Fix the following out-of-bounds warning by enclosing some structure members into new struct req: 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] Refactor the code, accordingly: $ 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 { u16 beacon_period; /* 36 2 */ u16 dtim_period; /* 38 2 */ u16 cap_info; /* 40 2 */ u8 bss_type; /* 42 1 */ u8 bssid[6]; /* 43 6 */ struct iw_mgmt_essid_pset ssid; /* 49 34 */ /* --- cacheline 1 boundary (64 bytes) was 19 bytes ago --- */ struct iw_mgmt_ds_pset ds_pset; /* 83 3 */ struct iw_mgmt_cf_pset cf_pset; /* 86 8 */ struct iw_mgmt_ibss_pset ibss_pset; /* 94 4 */ struct iw_mgmt_data_rset bss_basic_rset; /* 98 10 */ } req; /* 36 72 */ /* size: 108, cachelines: 2, members: 10 */ /* last cacheline: 44 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 _req_ enclosing all those adjacent members is introduced, memcpy() doesn't overrun the length of &sig.beacon_period, because the address of the new struct object _req_ is used as the destination, instead. Also, this helps with the ongoing efforts to enable -Warray-bounds and avoid confusing the compiler. Link: https://github.com/KSPP/linux/issues/109 Reported-by: kernel test robot Build-tested-by: kernel test robot Link: https://lore.kernel.org/lkml/60641d9b.2eNLedOGSdcSoAV2%25lkp@intel.com/ Signed-off-by: Gustavo A. R. Silva --- drivers/net/wireless/wl3501.h | 22 ++++++++++++---------- drivers/net/wireless/wl3501_cs.c | 4 ++-- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/drivers/net/wireless/wl3501.h b/drivers/net/wireless/wl3501.h index ef9d605d8c88..774d8cac046d 100644 --- a/drivers/net/wireless/wl3501.h +++ b/drivers/net/wireless/wl3501.h @@ -389,16 +389,18 @@ struct wl3501_join_req { u16 probe_delay; u8 timestamp[8]; u8 local_time[8]; - u16 beacon_period; - u16 dtim_period; - u16 cap_info; - u8 bss_type; - u8 bssid[ETH_ALEN]; - struct iw_mgmt_essid_pset ssid; - struct iw_mgmt_ds_pset ds_pset; - struct iw_mgmt_cf_pset cf_pset; - struct iw_mgmt_ibss_pset ibss_pset; - struct iw_mgmt_data_rset bss_basic_rset; + struct { + u16 beacon_period; + u16 dtim_period; + u16 cap_info; + u8 bss_type; + u8 bssid[ETH_ALEN]; + struct iw_mgmt_essid_pset ssid; + struct iw_mgmt_ds_pset ds_pset; + struct iw_mgmt_cf_pset cf_pset; + struct iw_mgmt_ibss_pset ibss_pset; + struct iw_mgmt_data_rset bss_basic_rset; + } req; }; struct wl3501_join_confirm { diff --git a/drivers/net/wireless/wl3501_cs.c b/drivers/net/wireless/wl3501_cs.c index 384bf84dfa51..e4f467116bab 100644 --- a/drivers/net/wireless/wl3501_cs.c +++ b/drivers/net/wireless/wl3501_cs.c @@ -589,7 +589,7 @@ static int wl3501_mgmt_join(struct wl3501_card *this, u16 stas) struct wl3501_join_req sig = { .sig_id = WL3501_SIG_JOIN_REQ, .timeout = 10, - .ds_pset = { + .req.ds_pset = { .el = { .id = IW_MGMT_INFO_ELEMENT_DS_PARAMETER_SET, .len = 1, @@ -598,7 +598,7 @@ static int wl3501_mgmt_join(struct wl3501_card *this, u16 stas) }, }; - memcpy(&sig.beacon_period, &this->bss_set[stas].beacon_period, 72); + memcpy(&sig.req, &this->bss_set[stas].beacon_period, sizeof(sig.req)); return wl3501_esbq_exec(this, &sig, sizeof(sig)); }