Skip to content

Commit c1ba3c0

Browse files
Yun Ludavem330
authored andcommitted
af_packet: fix the SO_SNDTIMEO constraint not effective on tpacked_snd()
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: [email protected] Suggested-by: Eric Dumazet <[email protected]> Signed-off-by: Yun Lu <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Reviewed-by: Willem de Bruijn <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 5e28d5a commit c1ba3c0

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
@@ -2785,7 +2785,7 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg)
27852785
int len_sum = 0;
27862786
int status = TP_STATUS_AVAILABLE;
27872787
int hlen, tlen, copylen = 0;
2788-
long timeo = 0;
2788+
long timeo;
27892789

27902790
mutex_lock(&po->pg_vec_lock);
27912791

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

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

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

0 commit comments

Comments
 (0)