netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* possible bug in tcp_input.c
@ 2003-10-24 16:29 Tomas Szepe
  2003-10-25  2:30 ` David S. Miller
  0 siblings, 1 reply; 8+ messages in thread
From: Tomas Szepe @ 2003-10-24 16:29 UTC (permalink / raw)
  To: davem; +Cc: linux-kernel, netdev, grof

Hi David,

We came up with the attached patch during a hectic oops tracing session
that got started by our sysadmin writing down an oops using the pen & paper
method, no less.  The crashing machine has been a firewall running a very
unusual NAT + QoS configuration, however we believe that we might have
discovered a real bug in 2.4's tcp_input.c.  Since our insight into the
internals of the tcp/ip stack is far from even basic, we are seeking your
opinion on whether we are correct.

The static inline function skb_peek() as defined in include/linux/skbuff.h
returns a pointer to a sk_buff, or NULL when its argument is an empty list
or a pointer to the head element.  Since this is documented behavior, it is
not surprising that all segments of code within tcp_input.c dealing with
a return from skb_peek() take care not to dereference the returned pointer
if it happens to be NULL.  There is an exception, though:

/* tcp_input.c, line 1138 */
static inline int tcp_head_timedout(struct sock *sk, struct tcp_opt *tp)
{
  return tp->packets_out && tcp_skb_timedout(tp, skb_peek(&sk->write_queue));
}

The passed NULL (and yes, this is where we are getting one) is dereferenced
immediately in:

/* tcp_input.c, line 1133 */
static inline int tcp_skb_timedout(struct tcp_opt *tp, struct sk_buff *skb)
{
  return (tcp_time_stamp - TCP_SKB_CB(skb)->when > tp->rto);
}

with TCP_SKB_CB that is defined as

/* tcp.h, line 1034 */
#define TCP_SKB_CB(__skb)	((struct tcp_skb_cb *)&((__skb)->cb[0]))

We are proposing to cure the problem by adding a simple check in
tcp_head_timedout(), but are not sure whether this is the right
thing to do, because as a friend put it, we seem to be fixing
a leaking faucet in a god damn power plant.

Thanks for any help,
-- 
Tomas Szepe <szepe@pinerecords.com>


diff -urN a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
--- a/net/ipv4/tcp_input.c	2003-06-13 16:51:39 +0200
+++ b/net/ipv4/tcp_input.c	2003-10-24 17:41:19 +0200
@@ -1138,7 +1138,11 @@
 
 static inline int tcp_head_timedout(struct sock *sk, struct tcp_opt *tp)
 {
-	return tp->packets_out && tcp_skb_timedout(tp, skb_peek(&sk->write_queue));
+	struct sk_buff *skb = skb_peek(&sk->write_queue);
+	if (skb == NULL)
+		return 1;
+
+	return tp->packets_out && tcp_skb_timedout(tp, skb);
 }
 
 /* Linux NewReno/SACK/FACK/ECN state machine.

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

end of thread, other threads:[~2003-11-18 14:01 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20031024162959.GB11154@louise.pinerecords.com.suse.lists.linux.kernel>
2003-10-24 17:57 ` possible bug in tcp_input.c Andi Kleen
2003-11-18 13:58   ` Tomas Szepe
2003-11-18 14:01     ` Andi Kleen
2003-10-24 16:29 Tomas Szepe
2003-10-25  2:30 ` David S. Miller
2003-10-25  9:12   ` Tomas Szepe
2003-10-26  6:55   ` Tomas Szepe
2003-10-27  6:33     ` David S. 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).