bugs in TCP code - keep-alive

Oren Laadan (orenl@cs.huji.ac.il)
Wed, 28 Oct 1998 22:56:00 +0200 (IST)


Hi,

Following are two bugs in TCP code, with suggested fixes:
(kernel 2.1.126)

Bug#1
-----
Calling accept() on a socket whose keep-alive option has been previously
set "on", causes the new socket to have sk->keepopen == 1, without
incrementing the reference count of the timer that is used for the
keepalive.

The problem is in net/ipv4/tcp.c, in tcp_accept(), here's a diff to
fix it:

======================================================================
*** net/ipv4/tcp.c Sun Oct 4 20:19:40 1998
--- net/ipv4/tcp.c Wed Oct 28 22:45:08 1998
***************
*** 1619,1624 ****
--- 1619,1626 ----
req->class->destructor(req);
tcp_openreq_free(req);
sk->ack_backlog--;
+ if(sk->keepopen)
+ tcp_inc_slow_timer(TCP_SLT_KEEPALIVE);

/*
* This does not pass any already set errors on the new socket
======================================================================

(alternatively, sk->keepopen could be set to 0 by default).

Bug#2
-----
When a socket is disconnected due to keepalive timeout (well, after a
LONG time...), the socket's state is set to TCP_CLOSE, an error is
set in sk->err, but no wakeup is done. Thus, a process possible
sleeping on this socket (e.g. a server, or a client or whatever)
indefinitely will not detect this event.
This is unlike other places in TCP: usually, whenever the state is
set to TCP_CLOSE, the code also performs:

sk->shutdown = SHUTDOWN_MASK;
if (!sk->dead)
sk->state_change(sk);

This is not the case in net/ipv4/tcp_timer.c in tcp_keepopen(). Here's
a diff to fix it:

======================================================================
*** net/ipv4/tcp_timer.c Tue Sep 15 08:52:10 1998
--- net/ipv4/tcp_timer.c Wed Oct 28 22:52:08 1998
***************
*** 229,234 ****
--- 229,237 ----
sk->err = ETIMEDOUT;

tcp_set_state(sk, TCP_CLOSE);
+ sk->shutdown = SHUTDOWN_MASK;
+ if (!sk->dead)
+ sk->state_change(sk);
} else {
tp->probes_out++;
tp->pending = TIME_KEEPOPEN;
======================================================================

Oren.

__________________________________________________________________________
______ ____ ___ ___ _ __ \
MOSIX Development Group ) ) ) ) ) ( ' ) \ / Oren Laadan \
The Hebrew University / / / / / \ / / orenl@cs.huji.ac.il \
of Jerusalem, Israel ( ( (___( ___) _(_ __/ \_______________________)

http://www.mosix.cs.huji.ac.il

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/