Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1809902pxb; Thu, 16 Sep 2021 16:33:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyB/ohmX0UAP6sY3FU4tFaTk57oo3EPJpwAa1w/kkoduP8ov3D/udBzEMn48LZP4VT2orE2 X-Received: by 2002:a92:da85:: with SMTP id u5mr5950785iln.213.1631835206576; Thu, 16 Sep 2021 16:33:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631835206; cv=none; d=google.com; s=arc-20160816; b=IifKaDF8Hn8gnvAMZb3yhyN1apkmhk8Yd6574mpEQm9QMJ2OVTpZc3yc85XA87c7io HrWSRY3+/9Y2OQwx6v/3hpGzIptM+nTX/iR0+0kQAD25oBr6ov/MYKhN4CZfIknv81l0 yaGZfgBcYoxI09NV+53DO4jQO7JjcOhZ40FMRd8MuKwf5saUJf0hxVtqyDFft8i6nnpB ThZXyCwUp4B5h8YFbqf6ZHbcL7zAKZ9/ilylOnZydBT7TS9P/0AGddY/nHKKQzTw49KD 7Gz1UMypwP5x1f6ZExQGW98t8dAKzEU0NQEzj3IMYG9+RuEwg599lq3IaGnXOe03OQMQ e/5A== 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=8psAXtikHotdlC28sq4Fa5vAjoSvcR7dW8Y6zflcPmQ=; b=Vhyq2sRB00Oiy/W3T8JgPi1VMOL5DZuXFfKmBJ0DcLyWTO4eZpjfzBLLwBeLY65JOc B98e0upGe9UcAW8L+l7B46qWKVpD7Upv58kiyShYOgpIzeIQuE9G8Y1/JQ4nl5H50F4s kkgQ5V7Y/HuZAjpVeubWv+uV8feLc12gSVwwZ+8Aee/ZPameJZ9EQaxnI7cAYXlCuRym kZ7sHilODqFQttrWtbPNSDU2x/iSFIZve9kk5LR08/IjfiIamEcAIEpotFksRIYPje0U B4nPD2Qbu4OKE6+RZJ+ofafdQ43J31BVfq3GFQEaasi5VsxumLsb2M9z9Iw8PLBVfOKz Qijg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2nnsfCXF; 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 a2si3665808ilf.15.2021.09.16.16.33.09; Thu, 16 Sep 2021 16:33:26 -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=2nnsfCXF; 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 S1345659AbhIPQub (ORCPT + 99 others); Thu, 16 Sep 2021 12:50:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:59000 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243007AbhIPQpv (ORCPT ); Thu, 16 Sep 2021 12:45:51 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 43A2561A60; Thu, 16 Sep 2021 16:26:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631809563; bh=IHE2R/yeUI08JWqQlANPraLSTwuSa6J2j6K3Ur7RRkc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2nnsfCXFrjJF8/44Zdvy5SJ1eB+PBJYJAVcwnyuZ7/EpzzXb0JRkhunoRWMhC3ZzE fx2LiUlxbICAhiF3u0Ft5A6+97+LakuZPaumBqsTXRAJTYXFCQ8agq1P0zQLTDK2hH kHW4lZmxGqqvqS0wHkCXprHT2b6rHbH9ZKCcsUgA= 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.13 200/380] flow_dissector: Fix out-of-bounds warnings Date: Thu, 16 Sep 2021 17:59:17 +0200 Message-Id: <20210916155810.873951383@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155803.966362085@linuxfoundation.org> References: <20210916155803.966362085@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 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 3ed7c98a98e1..6076c75706d0 100644 --- a/net/core/flow_dissector.c +++ b/net/core/flow_dissector.c @@ -1056,8 +1056,10 @@ bool __skb_flow_dissect(const struct net *net, 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; } @@ -1101,8 +1103,10 @@ bool __skb_flow_dissect(const struct net *net, 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