Skip to content

Commit a3374c4

Browse files
edumazetdavem330
authored andcommitted
tcp: fix FIONREAD/SIOCINQ
tcp_ioctl() tries to take into account if tcp socket received a FIN to report correct number bytes in receive queue. But its flaky because if the application ate the last skb, we return 1 instead of 0. Correct way to detect that FIN was received is to test SOCK_DONE. Reported-by: Elliot Hughes <[email protected]> Signed-off-by: Eric Dumazet <[email protected]> Cc: Neal Cardwell <[email protected]> Cc: Tom Herbert <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c6846ee commit a3374c4

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

net/ipv4/tcp.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -549,14 +549,12 @@ int tcp_ioctl(struct sock *sk, int cmd, unsigned long arg)
549549
!tp->urg_data ||
550550
before(tp->urg_seq, tp->copied_seq) ||
551551
!before(tp->urg_seq, tp->rcv_nxt)) {
552-
struct sk_buff *skb;
553552

554553
answ = tp->rcv_nxt - tp->copied_seq;
555554

556-
/* Subtract 1, if FIN is in queue. */
557-
skb = skb_peek_tail(&sk->sk_receive_queue);
558-
if (answ && skb)
559-
answ -= tcp_hdr(skb)->fin;
555+
/* Subtract 1, if FIN was received */
556+
if (answ && sock_flag(sk, SOCK_DONE))
557+
answ--;
560558
} else
561559
answ = tp->urg_seq - tp->copied_seq;
562560
release_sock(sk);

0 commit comments

Comments
 (0)