Received: by 2002:a05:6520:4d:b0:139:a872:a4c9 with SMTP id i13csp2566323lkm; Mon, 20 Sep 2021 18:53:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz3EUONGjoLnN13Y7QjAofyQhS2O/wSltIlbA5ckYz5NaFCQUBEH3g4KYX9BOkf+SOWFEy/ X-Received: by 2002:a5d:9bd3:: with SMTP id d19mr21272860ion.202.1632189190970; Mon, 20 Sep 2021 18:53:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632189190; cv=none; d=google.com; s=arc-20160816; b=JX4ApNxNmntUj3JgqrfhcmLb1ImWuSMOd1OIRlbphk9hPpqNLmEPXN7ZCfJrjII4TE ocFG7ngypx4fhJGlHBV9nx07C4cWV4xdNrIsF9KhFdhDIAeyH4lTWMUXzCT9C5+egteN Eea/vRRedERiAsEozD2LOLQoleiCFsZEGhWR5qiPpQaqDH/9aa1uX/ofIIESVz6E62wr 20y1BvND6fKEf6d53BtJDjsgj+CAsyKUjrcM7qiLdrac/Jdg+wWAiMPfg/Y5Nt+GXBh7 Ea42oF2/C1dAhkBZJjuxj7w7m9qxJClE5D/Rr378goScohooFKug5ahxTA6nlEq14q2z XdYQ== 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=VTxM5py9toGyD8fCdNSZnyBXM6QjOtwQVBoj/8rLVYE=; b=cK26lMfxgBUy8aCWzq5GNCQXV7gc/HPndegQPsoZwQj8F4XnbnKAtZJlpbf30sNpKf 8yf6EM1kXy/oB0J5AnOYclYzLhPvZBqsjmQEzQMkkRWuVvstqyJl58YlXLpRWSvU5nQE pNfGiSBEApA19+gUbNkAHUdlv/k9dUfn0JkfTdYEh9XMTrDi+X0xG0WxAcjeNu+IuqoZ tpuzRno5OG9LCX+5s0LJ5OdZsGC9k/KDNzdJou8z8zrLwgZ9g93VoFtjleaDUCLbyD6t ypgi35quijsvTxnL5okW3gbHBZsyElQUjQ8H5xOAMdNCO5IsE9nhatK+gSc3kFbAHlNd i/Mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=SNH7DUON; 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 w3si9473731ilg.44.2021.09.20.18.53.00; Mon, 20 Sep 2021 18:53:10 -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=SNH7DUON; 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 S1376608AbhITSN2 (ORCPT + 99 others); Mon, 20 Sep 2021 14:13:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:33250 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1358796AbhITSIA (ORCPT ); Mon, 20 Sep 2021 14:08:00 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B7FDD61A3F; Mon, 20 Sep 2021 17:18:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632158321; bh=FdW8nJXIGgat2ntg19fcpH4kFetY/ojysidmGAJDBlc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SNH7DUONxghkRawlC1LcisBYuw2Mjgzl5vmMcjxCZ4GtKLVNzDpPPeL88eZ6FOM2s rbLXU79TjCHdTxNT/guCfWsMRmNCxRpZ6qtG5UmMPFANclMMdI+Zjs/uMAesBm9Kha GdSaS6T0Abeu+/CFXNQA+O8YKiF89vMjrPv8I3o8= 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 102/260] flow_dissector: Fix out-of-bounds warnings Date: Mon, 20 Sep 2021 18:42:00 +0200 Message-Id: <20210920163934.596456864@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 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 96957a7c732f..b740a74f06f2 100644 --- a/net/core/flow_dissector.c +++ b/net/core/flow_dissector.c @@ -1025,8 +1025,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; } @@ -1070,8 +1072,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