From mboxrd@z Thu Jan 1 00:00:00 1970 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 7B2FE146A67; Tue, 25 Jun 2024 09:57:06 +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=1719309426; cv=none; b=vGoRCwAEMt85fY15KbRRez7av1emPxLiXmcZhugy9Kwk/kgQA/5OCxeesgwScsmXmMV8AgOEEfso0BCZj4qkODQuE6yeWAqQfRHuM+gWFnIor3LEAzcp96rdu1hFTjVXPdkuZiEEFHubqACHBRg/XQe4tKamtSxOX8PArkai+XE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719309426; c=relaxed/simple; bh=jO90zSJvPvBivdqab+YnKeRMmf4RIeLIJzzmPbIQ+ms=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TBx5GBtbayo3/JMh/TrNRd4Maz4efo6x/yhabP8cfJmP+GXKhBeJ0hIvrEwxCLL0rmUgAPIEUL/9bZL/2+PxXW9Zg3E13KiytxDop2eSRCLmhu/qaArDhLuok4ffJ10u/0/LwlM2w/65sQWD7hu1tlUfs3BwfyqGGVrDkxt611Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=KxdwJyL1; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="KxdwJyL1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 037D2C32781; Tue, 25 Jun 2024 09:57:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1719309426; bh=jO90zSJvPvBivdqab+YnKeRMmf4RIeLIJzzmPbIQ+ms=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KxdwJyL1ry/YMC4e8+oirneuDsC3bLbOEshu9l2alwQ9w+N4kjVg5d1zrV2fjyLVn 1XNgub14CAhFDkHC2TLNGXt7xH4RYWzHMRwvKLNVImaQxF6Rq0NbcB89MPQXgSATXe qLlj8QCWUORh0fy3w7UE/QgL+icHmQjanwIuY58U= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, syzbot , Eric Dumazet , Kees Cook , Willem de Bruijn , Willem de Bruijn , "David S. Miller" , Sasha Levin Subject: [PATCH 6.1 012/131] af_packet: avoid a false positive warning in packet_setsockopt() Date: Tue, 25 Jun 2024 11:32:47 +0200 Message-ID: <20240625085526.409562235@linuxfoundation.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240625085525.931079317@linuxfoundation.org> References: <20240625085525.931079317@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ 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 8888c09931ce3..c48cb7664c552 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -3791,28 +3791,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