Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1533980pxb; Thu, 16 Sep 2021 09:23:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwSWbMkC/C2xeludmxSdZ9SknM1ZDVO7x/LkQCagMTBm/Lar6wSzkgOapYOHMrzmsf/1IDq X-Received: by 2002:a17:906:d04b:: with SMTP id bo11mr7060436ejb.513.1631809421915; Thu, 16 Sep 2021 09:23:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631809421; cv=none; d=google.com; s=arc-20160816; b=oidQk9Vfs6PSQU7clQjwVZvdh4N2oR++/45dV2vJToVx707JUtWVTWBdIdimI1al3C WhYN2T0YY2MV6mW2yDcJitjQYHfK6DH+fK82BHYndNdh1HfsITRv2hBDw13F5a7NB5aN kIh9qgF/mk4wDFAwVzxsCNXY65OK+PXIFuNqkdBVK+R1ziRBQfx9hTIfnDntURAW1gXg d9N2m5ugarZ0I7oai19vEtqx3Gm/8ZALVkDhSblVdSCqVLShjRHPgxF3xcJgjk384jTj 2hAGNSEZ14oFvRiaed0nJ95VYNRA22Wan5jOiVDYh1IHQMB1kXkB+5jZiiT7yZMKo4dU fZlg== 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=OGlVwWH36rDDqwKemrTaABa6KGHWijoCp2hyUaarmbo=; b=lAMuLIUCvcS8VM5bdlgb1g6ic092TeTa3VsC+zKFUUZcd/htSTfTAx8TdSiLeVLMyF y+x70a17kaJXIiS8GA0azg27ZKXlvxYH5VckyBvrzczB+vLOf2mxyhh1zxrncoWutTZM iBDczKa3FN+T2rSJAcvzECH+f1baG9fqA2ZyNFVd4vAGJDCZKsSaEk6YL4jzz6Lj+vPA /VWdGKuTb3HNJ0IEqykUPPzfEECKCWJgpO9sl4+KsHFYR7FPo+NRjLdoD9/y5ZLpEuj4 kiamV002g6il09PwKUpo1fEx48PqXIbob9h1aBQ4CBevaYZ2X2ZLjx/VAfISI7ASsRdN bKpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=RuIMK7u7; 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 bi20si3812002ejb.575.2021.09.16.09.23.13; Thu, 16 Sep 2021 09:23:41 -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=RuIMK7u7; 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 S241853AbhIPQW3 (ORCPT + 99 others); Thu, 16 Sep 2021 12:22:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:54616 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235327AbhIPQN5 (ORCPT ); Thu, 16 Sep 2021 12:13:57 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id AA0EE60F5B; Thu, 16 Sep 2021 16:10:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631808609; bh=CmWsMTm9CnTkLCdh0k4xkgK/s50oQAkk757Fk/b1Xxg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RuIMK7u7k+IUTEeq81uangpZfaF53PrV4XfTB8RKUJgvM/bd22ePfOylgc2f/6MzZ S4kKMjrajh35vfyDoT6juLaPwR9MHwtF5TCJX31dT/BlP3T1n3kTRbQ+ZNmjrq9JTF 0ZPA2YtG+Tfw20RzkQzXV/3aSxON1Xj1r8pQ3iOs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, kernel test robot , "Gustavo A. R. Silva" , "David S. Miller" , Sasha Levin Subject: [PATCH 5.10 157/306] ipv4: ip_output.c: Fix out-of-bounds warning in ip_copy_addrs() Date: Thu, 16 Sep 2021 17:58:22 +0200 Message-Id: <20210916155759.439962102@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155753.903069397@linuxfoundation.org> References: <20210916155753.903069397@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 6321c7acb82872ef6576c520b0e178eaad3a25c0 ] Fix the following out-of-bounds warning: In function 'ip_copy_addrs', inlined from '__ip_queue_xmit' at net/ipv4/ip_output.c:517:2: net/ipv4/ip_output.c:449:2: warning: 'memcpy' offset [40, 43] from the object at 'fl' is out of the bounds of referenced subobject 'saddr' with type 'unsigned int' at offset 36 [-Warray-bounds] 449 | memcpy(&iph->saddr, &fl4->saddr, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 450 | sizeof(fl4->saddr) + sizeof(fl4->daddr)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The problem is that the original code is trying to copy data into a couple of struct members adjacent to each other in a single call to memcpy(). This causes a legitimate compiler warning because memcpy() overruns the length of &iph->saddr and &fl4->saddr. As these are just a couple of struct members, fix this by using direct assignments, instead of memcpy(). 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 Link: https://lore.kernel.org/lkml/d5ae2e65-1f18-2577-246f-bada7eee6ccd@intel.com/ Signed-off-by: Gustavo A. R. Silva Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/ipv4/ip_output.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c index 560d5dc43562..10d4cde31c6b 100644 --- a/net/ipv4/ip_output.c +++ b/net/ipv4/ip_output.c @@ -445,8 +445,9 @@ static void ip_copy_addrs(struct iphdr *iph, const struct flowi4 *fl4) { BUILD_BUG_ON(offsetof(typeof(*fl4), daddr) != offsetof(typeof(*fl4), saddr) + sizeof(fl4->saddr)); - memcpy(&iph->saddr, &fl4->saddr, - sizeof(fl4->saddr) + sizeof(fl4->daddr)); + + iph->saddr = fl4->saddr; + iph->daddr = fl4->daddr; } /* Note: skb->sk can be different from sk, in case of tunnels */ -- 2.30.2