Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp513828pxb; Thu, 9 Sep 2021 06:13:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+GMzPizeSlkVTD54/R/JkopH9BHGZZLB1KIQkScyA1nc8fpFCt9z8AvghY5bv7IVTfyF0 X-Received: by 2002:a02:630f:: with SMTP id j15mr2795953jac.62.1631193182974; Thu, 09 Sep 2021 06:13:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631193182; cv=none; d=google.com; s=arc-20160816; b=X97p8fMKbeIsZKnMk0MRzSKqf6deS0Up2jtZA1FqwBZGU0aNBZR+OjL5eZFeouF/Qk dDHW4OgFUME+gJYrrNwauS2RoRrtAhMnRSAicbf4h23wCv8WNQoy5IEFap6ml+rRt/ms 9rDtqzVg76nzRYrj/fUgsXgUMe1t/IH9xPxe2yM8FLtHQTa8Y0naYqqp0Q+bzo+LSoCg SA5Y2nWb+gV7WHEThq0CWOMNkBevTBKoAprwIK9Uk3xvL5lcAaqIYd/s8ua/kE+YiFvl ib1HXFmIW6Luw3/moEzfECnyswLTAm30+iwQzUrsbf3yJ0gCeUrqIMgj59Xs+VOp/8cD 9NHw== 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=r3TZ5SOrQbNzeGixoBqhlqdmFk2hKCLa5mgKAONM9mw=; b=qSBsu1Dg2fUwOB2hR+0KdnIY/X7CgMHOnHe23kXQ6rRT2PAiQ7x5ifA7FAvsEbKrB3 Aojt0iVIDWYE2U/H7q2eCGrKnWaIzL4BG9Y3sj2ZBAyCszBJG1SR/3Ms+qeFv3JB3E/s gkmvGVxKVE530HCshSZ1vyIAo7PDliPrDfS2/jWgFtGjRk7F1YBzpbgCUUOCEEqwOXpr 8Y4fVn9gzD+uYufCymMG8C8ZuRgWGJ8OuJ5te2anRgHvyBPmSmXwI6QsdeN5Ec5TiGMC H+XObUr/2PjzBzay/FV9SHhr6q27x+eh0DN75EDtS6mbjwlN9DKOEYcFpLgWYGkgGBqp dFLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qfswjxXi; 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 i6si1825587ilq.174.2021.09.09.06.12.51; Thu, 09 Sep 2021 06:13:02 -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=qfswjxXi; 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 S1355673AbhIINNI (ORCPT + 99 others); Thu, 9 Sep 2021 09:13:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:43554 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357526AbhIINBk (ORCPT ); Thu, 9 Sep 2021 09:01:40 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0BA3F63282; Thu, 9 Sep 2021 11:59:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631188767; bh=8yhV7/DVB34fP3mHRMBHlWHXu04xOPpIqQTpTu3Fcpo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qfswjxXiDwdIGCSyxan9AgsOLLfEt1bHDaCRNSxDygTerUnhYgLlIYMNe43VZUjc1 EiFgt717cMyTuf5j+ep0UVIy/shZtGrRmZ9JKq0dhOMJhPjv9o8tnn7nYXmfEDbRsU zc8v03uX5vTw4KeJptgrn2UF/7VtQNgxTozo99XUnqNUUn3UIBVOD2I3LQLHqiHaox lPrzwqn15J5YMqutixLU6oSbup8uB1hLiFJgW8cPPqBjeXya9GXNKFvxfVwWclXAHq GtBXTDza9ldh5jUgQiXIm+EPFAPdFcRr0KGTpHA41e00susrvvzpf5WYUZR9SbSME8 FkcwvqJ9sZi2g== 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 21/59] flow_dissector: Fix out-of-bounds warnings Date: Thu, 9 Sep 2021 07:58:22 -0400 Message-Id: <20210909115900.149795-21-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 323e0cb473e2a8706ff162b6b4f4fa16023c9ba7 ] Fix the following out-of-bounds warnings: net/core/flow_dissector.c: In function '__skb_flow_dissect': >> net/core/flow_dissector.c:1104:4: warning: 'memcpy' offset [24, 39] from the object at '' is out of the bounds of referenced subobject 'saddr' with type 'struct in6_addr' at offset 8 [-Warray-bounds] 1104 | memcpy(&key_addrs->v6addrs, &iph->saddr, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1105 | sizeof(key_addrs->v6addrs)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from include/linux/ipv6.h:5, from net/core/flow_dissector.c:6: include/uapi/linux/ipv6.h:133:18: note: subobject 'saddr' declared here 133 | struct in6_addr saddr; | ^~~~~ >> net/core/flow_dissector.c:1059:4: warning: 'memcpy' offset [16, 19] from the object at '' is out of the bounds of referenced subobject 'saddr' with type 'unsigned int' at offset 12 [-Warray-bounds] 1059 | memcpy(&key_addrs->v4addrs, &iph->saddr, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1060 | sizeof(key_addrs->v4addrs)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from include/linux/ip.h:17, from net/core/flow_dissector.c:5: include/uapi/linux/ip.h:103:9: note: subobject 'saddr' declared here 103 | __be32 saddr; | ^~~~~ 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(). So, the compiler legitimately complains about it. As these are just a couple of members, fix this by copying each one of them in separate calls to 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/core/flow_dissector.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c index 071de3013364..b4dddb685fc2 100644 --- a/net/core/flow_dissector.c +++ b/net/core/flow_dissector.c @@ -514,8 +514,10 @@ bool __skb_flow_dissect(const struct sk_buff *skb, FLOW_DISSECTOR_KEY_IPV4_ADDRS, target_container); - memcpy(&key_addrs->v4addrs, &iph->saddr, - sizeof(key_addrs->v4addrs)); + memcpy(&key_addrs->v4addrs.src, &iph->saddr, + sizeof(key_addrs->v4addrs.src)); + memcpy(&key_addrs->v4addrs.dst, &iph->daddr, + sizeof(key_addrs->v4addrs.dst)); key_control->addr_type = FLOW_DISSECTOR_KEY_IPV4_ADDRS; } @@ -564,8 +566,10 @@ bool __skb_flow_dissect(const struct sk_buff *skb, FLOW_DISSECTOR_KEY_IPV6_ADDRS, target_container); - memcpy(&key_addrs->v6addrs, &iph->saddr, - sizeof(key_addrs->v6addrs)); + memcpy(&key_addrs->v6addrs.src, &iph->saddr, + sizeof(key_addrs->v6addrs.src)); + memcpy(&key_addrs->v6addrs.dst, &iph->daddr, + sizeof(key_addrs->v6addrs.dst)); key_control->addr_type = FLOW_DISSECTOR_KEY_IPV6_ADDRS; } -- 2.30.2