netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Fix bugs in "Whether sock accept queue is full" checking
@ 2007-02-14 16:30 weidong
  2007-02-22 11:13 ` David Miller
  2007-03-02 20:51 ` David Miller
  0 siblings, 2 replies; 4+ messages in thread
From: weidong @ 2007-02-14 16:30 UTC (permalink / raw)
  To: netdev; +Cc: davem

Hi, All
	when I use linux TCP socket, and find there is a bug in function
sk_acceptq_is_full(). 

	When a new SYN comes, TCP module first checks its validation. If valid,
send SYN,ACK to the client and add the sock to the syn hash table. Next
time if received the valid ACK for SYN,ACK from the client. server will
accept this connection and increase the sk->sk_ack_backlog -- which is
done in function tcp_check_req().We check wether acceptq is full in
function tcp_v4_syn_recv_sock().

Consider an example:

 After listen(sockfd, 1) system call, sk->sk_max_ack_backlog is set to
1. As we know, sk->sk_ack_backlog is initialized to 0. Assuming accept()
system call is not invoked now.

1. 1st connection comes. invoke sk_acceptq_is_full(). sk-
>sk_ack_backlog=0 sk->sk_max_ack_backlog=1, function return 0 accept
this connection. Increase the sk->sk_ack_backlog
2. 2nd connection comes. invoke sk_acceptq_is_full(). sk-
>sk_ack_backlog=1 sk->sk_max_ack_backlog=1, function return 0 accept
this connection. Increase the sk->sk_ack_backlog
3. 3rd connection comes. invoke sk_acceptq_is_full(). sk-
>sk_ack_backlog=2 sk->sk_max_ack_backlog=1, function return 1. Refuse
this connection.

I think it has bugs. after listen system call. sk->sk_max_ack_backlog=1
but now it can accept 2 connections. The following patch can fix this
problem.

signed-off-by: Wei Dong <weid@np.css.fujitsu.com>

diff -ruN old/include/net/sock.h new/include/net/sock.h
--- old/include/net/sock.h	2007-02-03 08:38:21.000000000 -0500
+++ new/include/net/sock.h	2007-02-03 08:38:30.000000000 -0500
@@ -426,7 +426,7 @@
 
 static inline int sk_acceptq_is_full(struct sock *sk)
 {
-	return sk->sk_ack_backlog > sk->sk_max_ack_backlog;
+	return sk->sk_ack_backlog >= sk->sk_max_ack_backlog;
 }
 
 /*





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-03-02 20:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-02-14 16:30 Fix bugs in "Whether sock accept queue is full" checking weidong
2007-02-22 11:13 ` David Miller
2007-02-22 18:09   ` Vlad Yasevich
2007-03-02 20:51 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).