Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1535657pxb; Thu, 16 Sep 2021 09:25:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzvdQdFsxjfFFTb1Dh6BD7kTpLk+KDMHVslcnwh2BqtI/5WDPPvjv1zdu/GVW62ALOFegYR X-Received: by 2002:a17:906:4f97:: with SMTP id o23mr6990322eju.418.1631809548144; Thu, 16 Sep 2021 09:25:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631809548; cv=none; d=google.com; s=arc-20160816; b=QzoWC+xzByAu4tKwTumVnSpp9M1wYiTjJAqGOD6KaN5oFRsHQ6c5KQf95M4Lz3/3r4 wNpJqaCwF3ZpYus1vxEcK9q78NVkCHdYClE6TP7Y34FVMw8CNQqtdj5nu+HrTYaK6uS7 zo0DWDbZlmgdC8MsTtLfxo4KUOrw9MWw7LTOZ/ran+nC6QNh2WyzFwIIGOInYVsZ7vav xfwxtA7VDwtzjJFFTki6TgqLHCHeom56CrfGQoMX157TeEBIK7DmLKLtoi7w52jc6OUg YQUk0qAFOHki/nYxLR9A1FFiyKjPffBD08l6SR2yCRTaZDMQreuCO2Gf2f33l5HPJXg1 sPNw== 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=XgD/vAPasN3ki3bu1h+zygDiD3OT+oivv5pp2O7vQ64=; b=ppQhOZJ8JYipNuIv0WkmGiVQWPynfsG6nsUp2jVd/p9AAugdn5CBPRFsGE1JMm5zvv 5wSy8BujulMC/MEglKBZUEfOxkCUO7K47/hkts5E7lJysg+RWwyfiZ1tbUm3y5PHvYt0 MSYx4HYatbFEDtnDrhxPq2X4oeIfOJqWtno1AcNHMkOJCL06i1aixHK31cfirsxkMkaB FY7nJyKsQs//WozbxoWXvHeXi4JQpLijDeyyvHY0Tr5+UEeKDHNFvI/tZ6zllhLG6WeV 0gxqR84WBFaide7UBUkCQBPpXHxdRR2Q/aPIwF16Jv95PWGS5pktCaYFHCu4gJxWttnk IgVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="w8S/XYgV"; 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 g18si4231589edj.388.2021.09.16.09.25.22; Thu, 16 Sep 2021 09:25:48 -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="w8S/XYgV"; 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 S241611AbhIPQWZ (ORCPT + 99 others); Thu, 16 Sep 2021 12:22:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:54626 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239453AbhIPQN5 (ORCPT ); Thu, 16 Sep 2021 12:13:57 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 57DE26139F; Thu, 16 Sep 2021 16:10:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631808611; bh=jRM4G74qxl/5f3EZ4ew0VWEyoVqikXwLCFGgQBL/qkI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=w8S/XYgVYl6bGUPUti9PsX0mkJ1NcaKnN3vTgPVT+v0eoOr63QdH6Uvnop3AvRicQ 0FXvhl6hgJfkoq3egao1wdhZAOYHqWn0uPWzdNG8x+lOxAIJg+Hy2XdF9nGUwXXg0S PGK+Kwckpl1FYM1f0rYnTsB03Xx9D5X1J4+KaetA= 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.10 158/306] flow_dissector: Fix out-of-bounds warnings Date: Thu, 16 Sep 2021 17:58:23 +0200 Message-Id: <20210916155759.473333681@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155753.903069397@linuxfoundation.org> References: <20210916155753.903069397@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 c52e5ea654e9..813c709c61cf 100644 --- a/net/core/flow_dissector.c +++ b/net/core/flow_dissector.c @@ -1047,8 +1047,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; } @@ -1092,8 +1094,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