Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp517694pxb; Thu, 9 Sep 2021 06:17:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxcRF4EwkNK9z1nRYKHQEsrL4d9/oyT8MoxbGs7rD2g1jWNbWbs/WQfCqNby3qzTrR7X5SF X-Received: by 2002:a05:6e02:1be2:: with SMTP id y2mr2293202ilv.293.1631193449489; Thu, 09 Sep 2021 06:17:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631193449; cv=none; d=google.com; s=arc-20160816; b=Je6/r13m4RQMDa8Xnpma+0u6Ifl/dDKqICqdR3WfCR1QhET7ZytQzN4GPNA0yujBxW cuIG/34dLpsoKNdAkpw7RUSl0kuJ9Qi0+HGhhV45IIcy9lW9icxIKpmCSXp4ysc5evjS wnMKDYJAeOTE40efjYjcGwA7cwzZGCbNnGID09TkPk0OiIeTM51YmEPV1iwYyZMUg8Cr Ouf5qVN+k4k0V/aXcA7MRMdpmIxIsbMks8uRA0P1A2caSvhk9b4k4uQPNb/xXHP2Tsrr sWtCP+Mw2zzCb7cTk2Ebb6Vy+CSDp+IMPEJLi59Azeoz1lSg0g4nSD+Mwso94xnIawLX 4ZLg== 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=May/9Gn6F8M1ofe0CNur3r2v+Dikg+aidOSG3Uurhyo=; b=ZI0Tjv63XuwcyVKOdfhca0QIUPw82Cz13CzXoIKgqFpaXU8I/2gghy6aPPMuVAR1CE dDBZWEkLQkzAm5vjrUUfznN7d8CoLSaxt197GkaEzDbKNfT3I/4Da8P9ZDzu1ORAkb5E nJuoaXga2pNYF+uuY7NrdlvAKNMH0NJ5+h6rpkMq2ieP+JU/nJK7te8n/03aWECHPXCX RFnnr14c2XO1CuJLrn2vlh4LRcdavanSJQlVO4vUo1LeKBotPGsYCTj94z7xjXbG+J9v lqLzBGUbQcVMzBtt5QVOg7kS50j3qZh5wOT27TiNaufApmU4e7UTZD/wc+pbF6NZVaOo wuow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uK9Hfo9c; 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 u2si1675659ioc.87.2021.09.09.06.17.17; Thu, 09 Sep 2021 06:17: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=@kernel.org header.s=k20201202 header.b=uK9Hfo9c; 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 S1359188AbhIINQ2 (ORCPT + 99 others); Thu, 9 Sep 2021 09:16:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:43480 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357506AbhIINBk (ORCPT ); Thu, 9 Sep 2021 09:01:40 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id CDB13611F0; Thu, 9 Sep 2021 11:59:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631188766; bh=YWql1/hGmDWuBN9K5x1CFPzECfRMeufyjqHsuuUMpLQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uK9Hfo9crw+PK4MDewm303+eHYV6gu8s2J5CjQ0Ers4TTkrLdtZYLHtURcs0IoRw2 9IvkEp/D1K8ZjcDog3bTx+/pADn2/pcQ7QoxgsofwzUz7vTeA0zFmvBioPUrDetSC5 akIa9Iow0aFtPl66U8lcN4ioC++cMCCDGAaZaTmyZz5GszKHqtL7w1x/ncN+v6Wkvv Hf0AZwL+C7uUug1x+cor8VuarAlnN6ph9PsGsNS9o2pTFnkuvXJQ1p1eLub5kMEn1J lRr53aohzFXGPNjSwHahSeNpUoFpKpPnbCC8D8mLJghg6onsjtyIYUOOWxRog/3WEy T7LxTI5fZHTQw== 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 4.14 20/59] ipv4: ip_output.c: Fix out-of-bounds warning in ip_copy_addrs() Date: Thu, 9 Sep 2021 07:58:21 -0400 Message-Id: <20210909115900.149795-20-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210909115900.149795-1-sashal@kernel.org> References: <20210909115900.149795-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 5ec185a9dcab..c9f82525bfa4 100644 --- a/net/ipv4/ip_output.c +++ b/net/ipv4/ip_output.c @@ -419,8 +419,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