Skip to content

Commit fa0796c

Browse files
Yun Lugregkh
authored andcommitted
af_packet: fix the SO_SNDTIMEO constraint not effective on tpacked_snd()
commit c1ba3c0 upstream. Due to the changes in commit 581073f ("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: 581073f ("af_packet: do not call packet_read_pending() from tpacket_destruct_skb()") Cc: stable@kernel.org Suggested-by: Eric Dumazet <edumazet@google.com> Signed-off-by: Yun Lu <luyun@kylinos.cn> Reviewed-by: Eric Dumazet <edumazet@google.com> Reviewed-by: Willem de Bruijn <willemb@google.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 0e9c4b3 commit fa0796c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

net/packet/af_packet.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2784,7 +2784,7 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg)
27842784
int len_sum = 0;
27852785
int status = TP_STATUS_AVAILABLE;
27862786
int hlen, tlen, copylen = 0;
2787-
long timeo = 0;
2787+
long timeo;
27882788

27892789
mutex_lock(&po->pg_vec_lock);
27902790

@@ -2838,14 +2838,14 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg)
28382838
if ((size_max > dev->mtu + reserve + VLAN_HLEN) && !vnet_hdr_sz)
28392839
size_max = dev->mtu + reserve + VLAN_HLEN;
28402840

2841+
timeo = sock_sndtimeo(&po->sk, msg->msg_flags & MSG_DONTWAIT);
28412842
reinit_completion(&po->skb_completion);
28422843

28432844
do {
28442845
ph = packet_current_frame(po, &po->tx_ring,
28452846
TP_STATUS_SEND_REQUEST);
28462847
if (unlikely(ph == NULL)) {
28472848
if (need_wait && skb) {
2848-
timeo = sock_sndtimeo(&po->sk, msg->msg_flags & MSG_DONTWAIT);
28492849
timeo = wait_for_completion_interruptible_timeout(&po->skb_completion, timeo);
28502850
if (timeo <= 0) {
28512851
err = !timeo ? -ETIMEDOUT : -ERESTARTSYS;

0 commit comments

Comments
 (0)