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 E4CA32EA462; Tue, 22 Jul 2025 13:54:28 +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=1753192469; cv=none; b=EVceEcU3JQTrpcw3JBfiwWS+gbUsUJhgwCDE9P60wj9eCwZAf4ZHUvc905uZhrIIvE912Tq0F87Slj4NZnREl8jJltMnela/Mo3GbPEVufdiGWMd11iA3GlV8xbkEN2ovH6TpvuMJ/PoVUGsQQ9SxL2AdbMWMtperQACiJh5OGw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753192469; c=relaxed/simple; bh=LhJZt1HBATc2CyHpNOEPtOeML/8EexyrGZ66CVnX7z4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AckBgLDcwSWcDOxerQhN1JE1XvScQ7KBME/Uw6/U0WHo2FjxGgKryXmUUBaqlmxu12yBqih1vMdSP819aKoEHJGqrlKvrNXQfDus1mZt/8+6dzKS0G5/apYicSMCYnSdwsnlkuSbDu/6UB5VVoVImORtHsG4jQ5DPoH6+3Wr6WI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=P9WZB0/k; 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="P9WZB0/k" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4ACCBC4CEEB; Tue, 22 Jul 2025 13:54:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1753192468; bh=LhJZt1HBATc2CyHpNOEPtOeML/8EexyrGZ66CVnX7z4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P9WZB0/knaNcVhh2NhSuAAZzOaIdJjC1QVIl6ipjI9R4vdzZD1RjmHqGnEpyysVxJ aEnImQ7O4hDzc1hzdE0aT4uHkjzJfrWN44J5Kxj94LgLjSnAZ1GcWp2uuaq7BHC8VD XWePBMivLD20nd7xLfZWK2Sbvq0cy5+rfT4G6LUE= 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.6 031/111] af_packet: fix the SO_SNDTIMEO constraint not effective on tpacked_snd() Date: Tue, 22 Jul 2025 15:44:06 +0200 Message-ID: <20250722134334.564317083@linuxfoundation.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250722134333.375479548@linuxfoundation.org> References: <20250722134333.375479548@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.6-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 @@ -2791,7 +2791,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); @@ -2845,6 +2845,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 { @@ -2852,7 +2853,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;