Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp2095085lqb; Mon, 27 May 2024 07:43:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVbuqsRFffh6Hx2fC7VvY2Ih6/k43a+u0dJwTwNqJdHBzgyfFLueRqphpqvw2QrzuvpcjcMykdHj0KWy08/4qzuCcFQjXZctKNfE0Vg2g== X-Google-Smtp-Source: AGHT+IEUSkm6uCIn5MOcG9QhoB2g7yf4R3TUFsVLGjYSk5dsczbK7v5eVhgmAIZ1Xal86PKfHKSt X-Received: by 2002:a17:907:94cb:b0:a62:eab9:4be2 with SMTP id a640c23a62f3a-a62eab94d52mr259473466b.44.1716821038560; Mon, 27 May 2024 07:43:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716821038; cv=pass; d=google.com; s=arc-20160816; b=mb0El2bklMXQl5grwAG87GQf+KDecJcCsRg83/aSZVlw7JY+QIwQlORM1RKMhtPn4/ 9PxTzpB4gLKI5oQaQZACjkozm9Wu5yzk+916v8fnHW9WAbeuFKLYlR+QhG037Hlmn1zh lYhMsa6OHa74tMmmBf4fkqi7L/j0zTv8tc22ImTXze4XrJHHrjSSL72tUA1z0DU0J2xt 7EsgP5h7ERpKjz/O6LPUYVXt0OOElACFameD+UpxBuY2ERaEsQkJk85GZfQiSimhQVrn DpTYKN5JBt+Oa1uljJuAzAOGbq3iO2TBcH9AdR0YpY1IzsKe0vyPM9G+qoIrYIoIjCtR I7jA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=CQtkj7pEFSerdnOPHQZCpbnSbaXA/kiTOIiAF3kdbYw=; fh=Z3y/G4pVtxPbECZUBEmikqsEpGRALPnGlNOOg8IKdqQ=; b=dO1V8idWpzuaIaVJ4+qLe1Se+Ol09wJxsQ9eF//8nmAVHLcyHJSWtNNFW+r6ObDsgj xZGwidbhO2t1avPpTdpPIrB2KUZtbMa63xHUclGnFhEqpMhrLaWZK2uCcx/+I0yFVOug rDkIBNibRP6dElnPORuJMpHgmWD++94ZdkcQ5anlWDzX0wHr5Xjy1F7G/1BpuaxcICs1 hEwrrK7ZmmxDFtKZIVHvjF4pbemKqfEKQIA3BzS7tl2E3Mjh7rynGoXaJe5xmMmrUk0/ EA1WXDmclmfY3eyUAZBORUI4fTUDtpaq2XPKC1ocbZfNJvJddrSZIBf1CmIYBg0RJJQF J/2w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FFiG2Jli; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-190916-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190916-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a626c804f39si396770466b.6.2024.05.27.07.43.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 07:43:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-190916-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FFiG2Jli; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-190916-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190916-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 5C7651F224A3 for ; Mon, 27 May 2024 14:42:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 396523DABE4; Mon, 27 May 2024 14:18:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FFiG2Jli" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5AD3221C18D; Mon, 27 May 2024 14:18:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716819510; cv=none; b=t8gZOMPixcOnrIO/hQb/qhsOvkzBa/s/pz0WgQgdg8th09tuLqGDpTOIwx1XNw5H7EB5si6MyoO99Mhzg0c8aUs0JwlS541SOg1vuMG8iR7FuDTc81f56YMYutxF6lRvj4UlU/dY69NNYUmJkULQN0B0s9XDNzdBXM6e3XEaIYs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716819510; c=relaxed/simple; bh=6312h6JBv+KRqdI2YQsQBbtLN6STqv3ORKTst5+kdxo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bTzNRPb3FZPP6ZfwB/0VdNROIKP+JFSUBSsNeNtYjakkJt9ns2sm9Q849/6MBI2SMACmKJt+sAQbXl9iMlkZc5EGBZsiOjbgHOLXI/FUvrw8+t95VkgLFTuJtDJKWwbxSEAzRZnsrRRZDy1IYJE6aMzrGqQPQs1Y4lm+lB7DQEw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FFiG2Jli; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E345DC4AF08; Mon, 27 May 2024 14:18:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716819510; bh=6312h6JBv+KRqdI2YQsQBbtLN6STqv3ORKTst5+kdxo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FFiG2Jliy8M3orp8QlQe/9y5kGFAvKKBKSSh7bIR7jipgd/tYk417c95RbYxb9XcY b8L/uaKSnbEySizQxh/RZLhjspRr/Aj/RlM5B0czJ87iuMM8Tls2T9DobGNuARGS7N sLQ/nXecLsz1isZn3XwHqQScXk8XhrTfoJzmHrYeb2rciDGSW7MjBWpoEVBtOpS7xo F5mQHhagOh6TVL2OIawtTdHL6r3i5LEFzI4Blcg5dIYrY6PMHZGnUfW4PUeVWGCzmy qRqke+ANjMfMJpE2bvDaf/1ReazeTjSiB+i2DV8ZRrhpGnA1T5Q2bc6yhjY8cwuIo1 1jI0i2JMm3a7Q== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Eric Dumazet , syzbot , Kees Cook , Willem de Bruijn , Willem de Bruijn , "David S . Miller" , Sasha Levin , kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org Subject: [PATCH AUTOSEL 5.15 05/13] af_packet: avoid a false positive warning in packet_setsockopt() Date: Mon, 27 May 2024 10:17:59 -0400 Message-ID: <20240527141819.3854376-5-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240527141819.3854376-1-sashal@kernel.org> References: <20240527141819.3854376-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 5.15.160 Content-Transfer-Encoding: 8bit From: Eric Dumazet [ Upstream commit 86d43e2bf93ccac88ef71cee36a23282ebd9e427 ] Although the code is correct, the following line copy_from_sockptr(&req_u.req, optval, len)); triggers this warning : memcpy: detected field-spanning write (size 28) of single field "dst" at include/linux/sockptr.h:49 (size 16) Refactor the code to be more explicit. Reported-by: syzbot Signed-off-by: Eric Dumazet Cc: Kees Cook Cc: Willem de Bruijn Reviewed-by: Kees Cook Reviewed-by: Willem de Bruijn Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/packet/af_packet.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c index cffa217fb3063..787036afa69a5 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -3762,28 +3762,30 @@ packet_setsockopt(struct socket *sock, int level, int optname, sockptr_t optval, case PACKET_TX_RING: { union tpacket_req_u req_u; - int len; + ret = -EINVAL; lock_sock(sk); switch (po->tp_version) { case TPACKET_V1: case TPACKET_V2: - len = sizeof(req_u.req); + if (optlen < sizeof(req_u.req)) + break; + ret = copy_from_sockptr(&req_u.req, optval, + sizeof(req_u.req)) ? + -EINVAL : 0; break; case TPACKET_V3: default: - len = sizeof(req_u.req3); + if (optlen < sizeof(req_u.req3)) + break; + ret = copy_from_sockptr(&req_u.req3, optval, + sizeof(req_u.req3)) ? + -EINVAL : 0; break; } - if (optlen < len) { - ret = -EINVAL; - } else { - if (copy_from_sockptr(&req_u.req, optval, len)) - ret = -EFAULT; - else - ret = packet_set_ring(sk, &req_u, 0, - optname == PACKET_TX_RING); - } + if (!ret) + ret = packet_set_ring(sk, &req_u, 0, + optname == PACKET_TX_RING); release_sock(sk); return ret; } -- 2.43.0