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 F235D2C159F; Tue, 22 Jul 2025 13:59:18 +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=1753192759; cv=none; b=WKZeUqt4dLP3+BrvZM+WK9RzL/tYupWpcNBE7M3zoZjN53B/Oa9fdSlQj4uMUnWqjRn/NMOdkw8JunmL0GbxFYBimQ+KP+3/ZMkk0DOESqioaHiEr4j/u8dgQHiSQW/uCsb6tydBlqP5OqX0LGDbWdlNiqROa5BknxpzPxsEdqo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753192759; c=relaxed/simple; bh=KAXqZvUCYUJdWB3ekDQhgUPcOphP3xY5tgcJDk3Mcyk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NmAKHYpjQm4jeLDSyyRfKOtP7ghv2uj/q1mgKSX3MWLvWhdF3ippOLPAN9eRx6oteGeQ8m7J+O43s/CXKfdHrs0E7u6enkcxIb804GL75ZIBpPB9zcOgTY1xR3U9OFLhGUj2GTOGaBNal6WRTtJkK4dDjUEWWgmBXGLcLAvCCtI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=nZgewniu; 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="nZgewniu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 65F54C4CEF5; Tue, 22 Jul 2025 13:59:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1753192758; bh=KAXqZvUCYUJdWB3ekDQhgUPcOphP3xY5tgcJDk3Mcyk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nZgewniuBgUCdP/k0ORc6TWKfBMs0PeSAqLGEs2wAF9D3vYYLxGy1IuoBUDJE+6BY 68fhKGWJncCwty3fuXikImB0Elkge9dSG8HDd2d3djM23AKTynaJidwQiWMcPVNssW d3bJfYoEeI+k7uHjMtLavN2cJxpWytXeP8myFkR4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, stable@kernel.org, Eric Dumazet , Yun Lu , Willem de Bruijn , "David S. Miller" Subject: [PATCH 6.12 048/158] af_packet: fix the SO_SNDTIMEO constraint not effective on tpacked_snd() Date: Tue, 22 Jul 2025 15:43:52 +0200 Message-ID: <20250722134342.528400819@linuxfoundation.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250722134340.596340262@linuxfoundation.org> References: <20250722134340.596340262@linuxfoundation.org> User-Agent: quilt/0.68 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.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yun Lu commit c1ba3c0cbdb5e53a8ec5d708e99cd4c497028a13 upstream. Due to the changes in commit 581073f626e3 ("af_packet: do not call packet_read_pending() from tpacket_destruct_skb()"), every time tpacket_destruct_skb() is executed, the skb_completion is marked as completed. When wait_for_completion_interruptible_timeout() returns completed, the pending_refcnt has not yet been reduced to zero. Therefore, when ph is NULL, the wait function may need to be called multiple times until packet_read_pending() finally returns zero. We should call sock_sndtimeo() only once, otherwise the SO_SNDTIMEO constraint could be way off. Fixes: 581073f626e3 ("af_packet: do not call packet_read_pending() from tpacket_destruct_skb()") Cc: stable@kernel.org Suggested-by: Eric Dumazet Signed-off-by: Yun Lu Reviewed-by: Eric Dumazet Reviewed-by: Willem de Bruijn Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/packet/af_packet.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -2784,7 +2784,7 @@ static int tpacket_snd(struct packet_soc int len_sum = 0; int status = TP_STATUS_AVAILABLE; int hlen, tlen, copylen = 0; - long timeo = 0; + long timeo; mutex_lock(&po->pg_vec_lock); @@ -2838,6 +2838,7 @@ static int tpacket_snd(struct packet_soc if ((size_max > dev->mtu + reserve + VLAN_HLEN) && !vnet_hdr_sz) size_max = dev->mtu + reserve + VLAN_HLEN; + timeo = sock_sndtimeo(&po->sk, msg->msg_flags & MSG_DONTWAIT); reinit_completion(&po->skb_completion); do { @@ -2845,7 +2846,6 @@ static int tpacket_snd(struct packet_soc TP_STATUS_SEND_REQUEST); if (unlikely(ph == NULL)) { if (need_wait && skb) { - timeo = sock_sndtimeo(&po->sk, msg->msg_flags & MSG_DONTWAIT); timeo = wait_for_completion_interruptible_timeout(&po->skb_completion, timeo); if (timeo <= 0) { err = !timeo ? -ETIMEDOUT : -ERESTARTSYS;