Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1937372pxb; Thu, 16 Sep 2021 20:54:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJybPH5zMO6UegDN4mo7U/OaUnutyIcpTti32drLNabLrmIYCB6lcRnXjbC5SAcqLNj0FUNX X-Received: by 2002:a17:906:6011:: with SMTP id o17mr9661257ejj.157.1631850896749; Thu, 16 Sep 2021 20:54:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631850896; cv=none; d=google.com; s=arc-20160816; b=AG9GOjv+xsQ7lqIXiP8iDjKbeUc6p/XLejwQYX0elmUG4Rqf7LDfsIXoL1j6ULime6 JRfZDcqQj+A5axU8Xklkb7RX1NawKr5hWMlPsFJSBlZpOUMKkTWTXIF+TBZpIrrA9a0H 1nxOIumgJZ4gRX7e/iAt8PfsHjNO1fIELLGj8ZsNl21kjlLspJKd+oBb9zC59Og4+SJf a9TFRuCpwxWySBD+Tp7INVTDYRx8ifAwYIvv0zndiCtXtf49BD5wRAiAL+KjgA6oKIt6 anVXcsyz4k2mztSW6IyEnwp+cgqlFttMeNa1dTkzR/QzL79WVfFnFXkYMctAuXDCEC0Q hnaw== 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=LEGHhZiJSSw4ESyzzsF6sWm23FYp04gJGj4SR8C0aw0=; b=VIC8ynWiUOv5lDOMfT1V9+jdzp5R3n3mGKYBBbgaOjdwVBfxWGS48joOCDS3Wl8yzS GsCQ/29M3Q3dtlspy5OKPxFFAZlt+kMatnKds2fpWkPdpt42mDYKfTn3fR6Quq0Ifd6x /LRzr45EQGJoc9nm1nT/96x/8g/w2ncsmZ3NNr7f9ZULAaovBGQsIczNs6JglJ2ycSRv l8+K3lMS6h3gLNLlPgE2+R5cfqU3eQe/bHxKBttps+pe4q08dLVoDISPWVPRM5Sqdtwc Wf4i9ytOnNbyhNX/yeoZgdP3ZslD1v4bL7sTB2C1qqqqn/nOOlF19KiiB5pofih69fl7 7Y7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="X/EwhgCT"; 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 h8si4985974ejo.303.2021.09.16.20.54.32; Thu, 16 Sep 2021 20:54:56 -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="X/EwhgCT"; 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 S1353683AbhIPRef (ORCPT + 99 others); Thu, 16 Sep 2021 13:34:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:46938 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348318AbhIPRZz (ORCPT ); Thu, 16 Sep 2021 13:25:55 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C5B716124E; Thu, 16 Sep 2021 16:44:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631810674; bh=+7g9j/wBopcbXaEjMkgRdcRIhopO3dRTr4n1kkk0Bpg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X/EwhgCTIcpGxqrjadkhj0M2aHngnZC3HsAIDpiSvr/VwAczeYCqO1yae7J1epaBR QR/F3JABXKA8Eamme6ov1I5F0ZLgvisoDrLCvTOELEYTh9MN0wrcnRGfUfIcK/mGQQ JsFYj98k6Xif9vleAxBEqBmQwS37tBW+YHHyJ0O4= 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.14 226/432] flow_dissector: Fix out-of-bounds warnings Date: Thu, 16 Sep 2021 17:59:35 +0200 Message-Id: <20210916155818.501016495@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155810.813340753@linuxfoundation.org> References: <20210916155810.813340753@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 4b2415d34873..bac0184cf3de 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