Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp32060pxj; Thu, 20 May 2021 03:56:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw421VunypBSBzdsmBFNGT29+r3qDPe9mD+0pK9Mk+dwXWVD419PNKO2zDiKp4NpfCSCmvn X-Received: by 2002:a17:906:aac8:: with SMTP id kt8mr3973395ejb.402.1621508192226; Thu, 20 May 2021 03:56:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621508192; cv=none; d=google.com; s=arc-20160816; b=Gx099JkfnISy97rWhhK4dtuLtAiUTJQoCZtYc/rZTs193jFpn+6s3HR9rRdFdDNT+p p+f8Nbjf2/UMdnDKxKIHPrfeQ513Tmma10JT9GHVnGwcvS6gsghGT6lnAfZjaaGpnc3b 1aJl+Gb7s2wgV/skvMZxbZ4/P5WViqIK7niEZ7Wzrp4Kl5Yg1OCZJCu9GbzTPeyHDeff WN1jD19RpPfGYt+cg1+r6qQS89UqwDthL/KA1hgYSuxMJCIPlZbrb4WOVleqaeqJlFkX xcMwSR5zBUV1jG8d195dq2Ccu+qnl3gssylPtSRquv9ApmWPiJuuGkD0DwOs4YCE2OFu GhsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=agF8YjRCJU37Ykw7RB6iQUJMl0xs4KvOLgoRIj2dBY0=; b=MC6lSBhZXCTH8UEI43z/eX7uMW+yhhza4QL4PvNRgfNbXzTOYZFv09U4XkZjp7vz8V 2eIg9kG5cNUsAZOmbbazl+AozpdUTYnADVFZjtMntcsCucoP3vp6uYN8Nz5SKymasSBe U0IaOs3GgBKSjRm/ankB/g7d0llw60CfLNw7co82oyxhbkxzqehEhl4ZRkMut6apoXw1 +nLsE+Si/6Awyo1+ocd61SFQQERdhu1IY1WVYg7Zd48r5fTEkMIpl7EXrHY6DcqpRRwP X9iIla1nuSijUmZ2qYKup2pWfwDQMQNOjsy4ZdkdptVUjBH1Wt+w4Vw0ZeHfiOAcOV9K 6zlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sCsEzaht; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hc37si2933161ejc.354.2021.05.20.03.56.07; Thu, 20 May 2021 03:56:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sCsEzaht; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239174AbhETKw1 (ORCPT + 99 others); Thu, 20 May 2021 06:52:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:39658 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235534AbhETKgb (ORCPT ); Thu, 20 May 2021 06:36:31 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1CE5861C68; Thu, 20 May 2021 09:54:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621504455; bh=R2qeQpSeEs/0CsMN27ZQBYqh3Vt4vzkUduKAVjZjSuA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sCsEzahtJpeSPnuqmqbTd3EpKyrjglPr4OiIxgjhWLQ9OjUc1B/fpXZB9zSWDAwjr quNc4/Mu9DsSpJiaFpjRrmQ+HGCq5hWA96wc2fZ2n+zbwBVEoj0YkdZeS4H/O1ZOzq 1/y0pblq5VpL5kO2lvBetaY8mGQp0mu003nsGeMU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, kernel test robot , Kees Cook , "Gustavo A. R. Silva" , Kalle Valo , Sasha Levin Subject: [PATCH 4.14 254/323] wl3501_cs: Fix out-of-bounds warnings in wl3501_send_pkt Date: Thu, 20 May 2021 11:22:26 +0200 Message-Id: <20210520092128.905895071@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092120.115153432@linuxfoundation.org> References: <20210520092120.115153432@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Gustavo A. R. Silva [ 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 Reviewed-by: Kees Cook Signed-off-by: Gustavo A. R. Silva Signed-off-by: Kalle Valo Link: https://lore.kernel.org/r/d260fe56aed7112bff2be5b4d152d03ad7b78e78.1618442265.git.gustavoars@kernel.org Signed-off-by: Sasha Levin --- 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 efdce9ae36ea..077a934ae3b5 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 da62220b9c01..0019b01145ba 100644 --- a/drivers/net/wireless/wl3501_cs.c +++ b/drivers/net/wireless/wl3501_cs.c @@ -468,6 +468,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; @@ -483,9 +484,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] = { @@ -979,7 +980,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