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 BAB1516F84E; Wed, 3 Jul 2024 11:04:12 +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=1720004652; cv=none; b=h/rXSQ2KrYMsHWzScsqv/Aj81RUs4qc6kiyrGbxQ1sZ8YM8wmdW2DsEaGgEVYaTbCxiCXy3WnRipkh6IluVJvyovvUkXf3WQDTjge9xZLl2Q5dbpFZ4MMjrynsnJihWBHgSMvDVna68Ov2WMQdyYUSi+3ITEjnOSXdf/p5HdEGw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720004652; c=relaxed/simple; bh=4TWs7rM4k8rBFK4pIRiyWaUphUZ+u6YS46ihpVZa+PQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XGSbFY1NL6VmyvZTZfcZ5mazVGzaQBXwXH9An2Gf38AXQyVjaHGgCzPPLSZZQFlZiPvEA7hQxAule7V/aeWUsnSEkefVLKU5q92xTUswIEPGHNf0BdB1J9tipp8VmVoLWawm81fopGeTF9mWbUYuU6b3V/F1/p3UtCbsc8gIRm0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=asHp5eOt; 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="asHp5eOt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 405AFC32781; Wed, 3 Jul 2024 11:04:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1720004652; bh=4TWs7rM4k8rBFK4pIRiyWaUphUZ+u6YS46ihpVZa+PQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=asHp5eOtK6CtmBiUsbeH4d431jUPIWdOgxR2o1sErvf1HEf2B+ShnyZynbOqGel0x HSnTSbeH2hXqO2/tHtlBlDm7vmbpuQjnHwlcGgi5FEzIl+sOoR0YNbryNnx0XZUQYe oxso4nEY6SDT69P3lGqrFwPklJTpK5joQ8Oy9ecU= 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 5.10 113/290] af_packet: avoid a false positive warning in packet_setsockopt() Date: Wed, 3 Jul 2024 12:38:14 +0200 Message-ID: <20240703102908.461450162@linuxfoundation.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240703102904.170852981@linuxfoundation.org> References: <20240703102904.170852981@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 5.10-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 8e52f09493053..9bec88fe35058 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -3761,28 +3761,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