Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2349558pxb; Mon, 20 Sep 2021 19:43:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxA+Ecc6cmpGamhs9n4NcZtIozJkrkWIXau3J314MO0uQkKDSXPNfgSQJLvs5/hLIVL+liy X-Received: by 2002:a6b:ef0d:: with SMTP id k13mr17163193ioh.54.1632192209141; Mon, 20 Sep 2021 19:43:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632192209; cv=none; d=google.com; s=arc-20160816; b=uC1aJVtGkuVDXdmzU2MeD6s8UFCkJpIp5tmb8kuUQE98GbPMdPqaOoUEnJoUsA7Rqy OZgsuL9QlllM6zfZI/D2lHblJqlreAchryr2gwLaxCR5CYivgMMnBtLxtP7owHSKTYaS JEuLFm6AVbBCEORIOIs5wXHMCyIOUoyhUlhnXWuH7uaMPoa92E77Eai17NzOC8YUkAkz 7eFWB48j9TsKiTBkmNEFAZA/bY9MmAzJa1STJYBUqXhuuUa734wdEEgHYAd8d306yrKr EtSjHHWGRKZbK4DSE/qiVBjGBmR9UQ3eubJkgnnwbZT8vekI/6xIGi3v2WDXzwDhVYv9 5HdA== 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=BRlH5V8Ddcdh5NvNFUqbA7wfjvHVR+EcvrMvF+44smg=; b=wDV33b9fdXdx/GcS3lsmk9HVj8XlhtlSV2rvRnPWreAk6DqNgvZTMqcKlB5g/3ncRB c35jedXfzRwcniUBN+Av7lo86dV7H5miXlKvPJKQTfZBI/dj3O0lEfCLuZGLY/xCqvng U2tQQPCxLTmjc2rOJ6+QqLqV0ftTr/y033oddsfd7Lqx1EkMbYhurdMiDo1IyT0H4awj zSRD9qkWQ/+apVuJmapQcN7DYHYo7c8OUQKWQrQcQ7CdGtLcRJUPSiWEaTBgv4+7DEed mwe5N9Tdojqu3h7GYE9fC/OL9Icr1KoDliVXJVSzhIbTIkkO9Vw/Uutsb0vcAO1DjZO8 3+1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jX3ManYO; 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 l7si2244220ioh.59.2021.09.20.19.42.41; Mon, 20 Sep 2021 19:43:29 -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=jX3ManYO; 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 S1377766AbhITSUv (ORCPT + 99 others); Mon, 20 Sep 2021 14:20:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:60636 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1358736AbhITSHk (ORCPT ); Mon, 20 Sep 2021 14:07:40 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6B35E61A3D; Mon, 20 Sep 2021 17:18:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632158316; bh=GVFucPR26yAw+JUrThPGKkOPV7aSB9zEaDLqb+2VNio=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jX3ManYOBsmBGQAZh23OmUq1BtrNdi+MmUokE4H/9m22H1Wk7hPJ4ci7IyrQvGZ3x FpDqmmAtEFdq5j8TVTUvogHcaPzL8wn0g7kYu5+8kbbL5wiK3PUoqlyuDB1ou+pX9c 37fEhJ8r00ySFlfZqdBvo15DH/Kvoxiy89UaiMvU= 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.4 101/260] ipv4: ip_output.c: Fix out-of-bounds warning in ip_copy_addrs() Date: Mon, 20 Sep 2021 18:41:59 +0200 Message-Id: <20210920163934.564505447@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163931.123590023@linuxfoundation.org> References: <20210920163931.123590023@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 f52bc9c22e5b..0ec529d77a56 100644 --- a/net/ipv4/ip_output.c +++ b/net/ipv4/ip_output.c @@ -446,8 +446,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