Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp2084508lqb; Mon, 27 May 2024 07:24:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXUkczQ/2Qbe8rlyIwhdwluM1DHrUXXNeUD59V5CjLh996W5htQeDvtPRNKEwTwlXTFou5nQbzCRGdDCiCgW96mmzCK73DdaZDehgdusg== X-Google-Smtp-Source: AGHT+IGYq8ommQy75DtIdoR5CKVgZhF5NlejkAZwkNPhqblWRmHzmSSiwLZg7PLkPqNuVbULjpgW X-Received: by 2002:a05:6102:38cf:b0:48a:3fa5:b832 with SMTP id ada2fe7eead31-48a3fa5b91amr9625419137.33.1716819876871; Mon, 27 May 2024 07:24:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716819876; cv=pass; d=google.com; s=arc-20160816; b=tzPiahSlErK6RK72aN1gC7U2p3xPruZhgO5uaVUu+7BXncfLUu+uFDQyBFTgwXLFUv LO74ZBURgS03mqH3/vY1lf3bvZsU1cOBsOkMjVakEJ1QkiGyqRVvJl3JnWb9KF2IVhnN UHya7qwmAroOfrrMNq9siCaNPfm7N+Bwj+3HfC4ACtMPHkNkwuCOJqAmeGTVrMRKt1Jh O/ZbEGoeXaN9a5uXLbrVHL1FR47HpiPyxYIRN6q3prgSEiD/fMZl3WcmaFPmvFTT9pmw HZnVfrueTTeaA0+lWW9tgYRGtKeDUAl4VCSC2M7BLCKVzRv90ft4J4xg7pwC0nz1CQrH wnFQ== 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=R6vC+JuUFTHC+73YKejgYFOHklqcaBwsWrRtTI1buGY=; fh=Z3y/G4pVtxPbECZUBEmikqsEpGRALPnGlNOOg8IKdqQ=; b=OgNkl+rqVLyaK+EjQ5jF+0QWNDNnpYLQHtFEZwCFXe/yyWcs6FYMmlqKliYWlwRbrG Vs9oho5HT805ITfFDJoTyr6USOun8chQ6lr5hv8JETMTDY9d6qP0C94W9qm3GpBtJzUu +fRzt7ZZNcjfi9HycHbu3igvx8/DgCfr7yVe1va0eRDAdTeqGNVYauPGG4qWHLn/keJ/ nMhllTVnr8cGUPm9TCDpm/DhX/+DnIRN1mef+L+k+aTXnN0p/IjWPYqx9FYOFLOs0Uzv BGfZmFCcgVsVFNNQY7bFHkDhUw/B3VTaZWEyQl5w6+Q+YRygsJHTQq7Rvy0UUNhdVku6 5hkg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=h4KbzEoR; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-190844-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190844-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id ada2fe7eead31-48a3a3ccbd4si1504621137.658.2024.05.27.07.24.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 07:24:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-190844-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=h4KbzEoR; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-190844-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190844-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 956ED1C2031F for ; Mon, 27 May 2024 14:24:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D3842172793; Mon, 27 May 2024 14:14:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="h4KbzEoR" 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 EA69C171E72; Mon, 27 May 2024 14:14:33 +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=1716819274; cv=none; b=Qzs7ATzdOAB1GSd/ZR2XpkgqzMhcYsMuQv1qGb7CIuY+ud+Qb0/po/pxKuhTgOQDZP0SpurosGL/GTfM9oWB38lHs+9aFBNrILgQDII9AdfPN969JQ9RKwMitq5t1zLVU5EqKN4ML8lX4mYZMURYShBqjeQwpJ9pIPO7w0bvrbI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716819274; c=relaxed/simple; bh=SV6qtfU/+d4z44hjkPenfsRMaU8QjujnfZcfHZCustU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jyCL6uCTsUzLcb8mI521aypNssGeBW8lU3CK4MQHr4SpJLORkd2QLtEJqmpJdPJeFPi5+kLbmKqbNRLG+5xSgDXYmswK8/EKlSzgmSMavHuVBNpZHZhxEdn+OHnnHsMn7Xxg6bpUIy/B4crHk2xv3yOsoMyger1q2RyPqkXA5SY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=h4KbzEoR; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1B1CFC2BBFC; Mon, 27 May 2024 14:14:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716819273; bh=SV6qtfU/+d4z44hjkPenfsRMaU8QjujnfZcfHZCustU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h4KbzEoR7RA4bQ+41hJ94S3DpDqdGOBqrSvNo86FtAjysbO/Iu20rKtcoR/lbwRD/ t/EdtE18tFvy9hcB5nUW1leRXpMed1lp5Jc+P2TCM8SkAHNVBmkMVpLmp6Uh6LXaPb NVR36BetY1f3n+Htm421f0M2EnqamifgO17qjbKGyMaG5gucJWLLtihv7EFnsX36T6 8iNi/a+PINKJ0sUkH0AwxGLdNU7qhiwv/HpaqYLhyF2mgCefYca8iGEfkflos6Bb1e PJr9F897quc0bFBLunyW0H/9Rs8J6zdIaoFdDbFbgmIQczuDPbbuY2Nbnvq7Ag5HDZ gETA+rBFWE6kw== 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 6.8 08/30] af_packet: avoid a false positive warning in packet_setsockopt() Date: Mon, 27 May 2024 10:13:17 -0400 Message-ID: <20240527141406.3852821-8-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240527141406.3852821-1-sashal@kernel.org> References: <20240527141406.3852821-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 6.8.11 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 e6a8701a38dbe..59ca1e321db16 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -3800,28 +3800,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