Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp446962pxb; Thu, 9 Sep 2021 04:48:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8hsAQ2py/TF2zjpw6ZkLgFMFjCpeuMVjJ4wJbp8dUjfcZ2LP1/tgzG57BVkqNMr0E7APC X-Received: by 2002:a6b:ba42:: with SMTP id k63mr2271248iof.37.1631188110882; Thu, 09 Sep 2021 04:48:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631188110; cv=none; d=google.com; s=arc-20160816; b=WNGYB9hL1J2e/SXEjRlzsG+48bNMoUifs+NQw9ZjV5EBYmxRq3n53O5e/lO1l5q8Nk XcwUvqATSDhxG9aY3kh8PbrWvJChhxJCszcSdVzAF6JVixqPQDPDOER8I8H8ZpKheoy/ qBAVtX6Y+TSoU2bx11rRsTlNlAC9HOuFAkABxLhqBaOI5PrbSHZqyKypSjeAX136s8eY NEdJIHVYI17e04Zr1oKEsD9lPb+19suINocTEBiFvA+BN1wnhWYAaUzWbknX3lxHRoLK DIbApSf0pz0DqLn09Ihl1hKhR6P9QD+iXhv3TbYF7iWjLFb/nsh9DfKOfCMrq7s1SIZR Egbg== 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=3aoXUaDQzO01Y+8tB4w7JbnyDGd0ghJlUnBXqgBzLhM=; b=TDDvC4npFf5cgu5IZLG29z++kPrs0lqA33KoCCv1kxZMhPY9Lx/OtaMOSJiy1sGEe5 gRVJs7fRQzhrjQpSEYTW6wbJ5mlw/O1kwY+L7ZBWvxYea0Lf+SQPPDSRSl7+Iso/6fZ5 J0VZLhEbTd4TO1KzFcP0Ue49/ChDZiDgEJu4P0jBgS0Q0DjOlvjCDPLhnTPUsPwaGdnS KMHDj6AKktr79nlMG5vztN7K6bDi0ZsbRVP/8VzBJtFiK1Dj/iJPSzp0x+yq4qADL8Be 0SCAfIUnwNkLAZ2qbZcfYgyv/zyjPm4ljSjJQDmb9DUvYcKxjWt7/e60vRawBX/zdMkG U0hA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XN1hs21g; 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 v19si1659876jat.80.2021.09.09.04.48.19; Thu, 09 Sep 2021 04:48:30 -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=XN1hs21g; 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 S240321AbhIILrr (ORCPT + 99 others); Thu, 9 Sep 2021 07:47:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:46772 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236867AbhIILo6 (ORCPT ); Thu, 9 Sep 2021 07:44:58 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D4FF8611F0; Thu, 9 Sep 2021 11:42:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631187761; bh=iVLoKJxm0ZZN1DlK176cfMQaiZy3f+QO7MBnhCfjZBc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XN1hs21gGHDXRZ5S7WgwVAU6bykg02mOKQIeIHWGd2j/DDljBpjt0yLP//m4qMv8f y/BaUZK95nn1zYXRo95x5iXEy8zCxRjov6NzDF2WJUJm66J3/zjOwxYeVVcDVfay4s SqgLg3beyow0rOi779uT+YSZ9jqFaTjr8hJYdHKOzprEMQu43qbwho7DfRdl9Ir591 4o39sbhlrD6JyiiVT1aQrg+u2hIJuA6wyjx13UDmoNCprev2Q1KpksbhRgrF2S1TTS FCL+js4NsxqAmq15EBSF2PbD2YSkacsomEskqWU13GvRLyWOX2mrfC5a7/+RSW0DNO WubjGfECNMGpw== 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 5.14 074/252] flow_dissector: Fix out-of-bounds warnings Date: Thu, 9 Sep 2021 07:38:08 -0400 Message-Id: <20210909114106.141462-74-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210909114106.141462-1-sashal@kernel.org> References: <20210909114106.141462-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 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