Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp446794pxb; Thu, 9 Sep 2021 04:48:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzEWGG1InufxFwAG7M6FH5vJysCfFmDEvYQv5BE+yhxqNET2dV3GYDrkTijCZCJhYTJUY9j X-Received: by 2002:a17:907:2d8b:: with SMTP id gt11mr2945753ejc.432.1631188094867; Thu, 09 Sep 2021 04:48:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631188094; cv=none; d=google.com; s=arc-20160816; b=P1HqkPVtVq6EvhwgazJ4f3tvSZp7d9MxCrc9qCaB+IJwD8je51rKpcMplezBujknds tcS5nxA+qh6UhnCvhwsVJwft3IGylAtPcb4+DIuDIcE+YiexWpESUHctcSjrPE5ho9dS A2JwN7/Rc5+BjPYAnWr1agtSyc3gI2dxoXfLKv6FCrqrwTeVUKdRHhEqSFL1269Ct+b/ yGqpZ26Oj1+SBd3KaVRAoqNLcmJt5x2I+ttg2qj/8gXPWGoJUCmTJsvGO2hzNvIUf2D5 um++OGV9KUT6/knAZjOfDarq0u4JIHbPSziQd2itkIcZfEOKb4/DxCspzEYwRCOFtrO/ 1KQw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=cxEWgixWLbAzPq3EDGWFU+nokMMxzqKuTsNUBXOm5B0=; b=CO/GELhQ3UeeeMKjHhs1ObzO+Dqf2Po2pHUS5BlCH0mvAFt+xRexYHf2o+eh6oX75w 5V8EtfLrKIvUeqZA5vtfGH1fHvpmqOcAiTVsKMveQ4ckxyrLLz//AoqCAM0U3U+xW6tK Z+TmSm3xNqaemF7hCvINrVLOPOgS70whLm80HLPjsBr444vvsE39VFJf2gS4fKdmvImg rONqfuvYgckWfCRdRuPZqmndCgS7QTr+lke9aXy9q+SFm7wnF0qcKqPdh4TE/joYBYBx CLPTWs99a9qOZwKElKaBLBHTPNqEL6cdiAi6ti8BYJMZ9D9dfZYthZA3TLbjghsXZdcY zhng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=g+HeQH0E; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d25si1605132edx.354.2021.09.09.04.47.50; Thu, 09 Sep 2021 04:48:14 -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=@kernel.org header.s=k20201202 header.b=g+HeQH0E; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235555AbhIILrf (ORCPT + 99 others); Thu, 9 Sep 2021 07:47:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:46708 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237796AbhIILow (ORCPT ); Thu, 9 Sep 2021 07:44:52 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9FDEB61212; Thu, 9 Sep 2021 11:42:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631187760; bh=FIgcBaf1x/mj2ueC9NL0wLHh1TCLgr9fKcH5mALS70Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g+HeQH0E+Xvda8uYKnGe0eEabbb4k0eIt6B0rbJU7DBemVgHFUywm2lITERzfYCoe vlAs5Jdn1RI7Hng9timr0q5EalafLYncoOHHna3zeKVp2Nwi08l7B1wM84pY4w/B3u 1WoLMwDowKqOOG3Fgc3aLDloAW0gec5QlFL/JTByBGQTK+qgcehjnm3yZ2/W27nmGb nxAT9nSGUJjY7fre19jd3c2eS8SCLIQF9wsbXu2cYlFn27G9psdDmL0A+Wsdhu+90D LKFcchsre6kznFwt79HQr+J1s9YT01W5VAfN0tH9UHEr1bwTjrrgXhfdh4gvUScMPm TSeaeFfMpFChA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: "Gustavo A. R. Silva" , kernel test robot , "David S . Miller" , Sasha Levin , netdev@vger.kernel.org Subject: [PATCH AUTOSEL 5.14 073/252] ipv4: ip_output.c: Fix out-of-bounds warning in ip_copy_addrs() Date: Thu, 9 Sep 2021 07:38:07 -0400 Message-Id: <20210909114106.141462-73-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210909114106.141462-1-sashal@kernel.org> References: <20210909114106.141462-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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 8d8a8da3ae7e..a202dcec0dc2 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