From: Eric Dumazet <eric.dumazet@gmail.com>
To: "Ilpo Järvinen" <ilpo.jarvinen@helsinki.fi>
Cc: David Miller <davem@davemloft.net>,
Andrew Morton <akpm@linux-foundation.org>,
Stephen Hemminger <shemminger@linux-foundation.org>,
Netdev <netdev@vger.kernel.org>,
kolo@albatani.cz, bugzilla-daemon@bugzilla.kernel.org
Subject: Re: Fw: [Bug 14470] New: freez in TCP stack
Date: Thu, 29 Oct 2009 15:08:30 +0100 [thread overview]
Message-ID: <4AE9A1DE.6000808@gmail.com> (raw)
In-Reply-To: <alpine.DEB.2.00.0910291316340.19761@wel-95.cs.helsinki.fi>
> ...I don't understand how a stale reference would yield to a consistent
> NULL ptr crash there rather than hard to track corruption for most of the
> times and random crashes then here and there. Or perhaps we were just very
> lucky to immediately get only those reports which point out to the right
> track :-).
>
When a skb is freed, and re-allocated, we clear most of its fields
in __alloc_skb()
memset(skb, 0, offsetof(struct sk_buff, tail));
Then if this skb is freed again, not queued anywhere, its skb->next stays NULL
So if we have a stale reference to a freed skb, we can :
- Get a NULL pointer, or a poisonned value (if SLUB_DEBUG)
Here is a debug patch to check we dont have stale pointers, maybe this will help ?sync
[PATCH] tcp: check stale pointers in tcp_unlink_write_queue()
In order to track some obscure bug, we check in tcp_unlink_write_queue() if
we dont have stale references to unlinked skb
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
---
include/net/tcp.h | 4 ++++
net/ipv4/tcp.c | 2 +-
net/ipv4/tcp_input.c | 4 ++--
net/ipv4/tcp_output.c | 8 ++++----
4 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/include/net/tcp.h b/include/net/tcp.h
index 740d09b..09da342 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -1357,6 +1357,10 @@ static inline void tcp_insert_write_queue_before(struct sk_buff *new,
static inline void tcp_unlink_write_queue(struct sk_buff *skb, struct sock *sk)
{
+ WARN_ON(skb == tcp_sk(sk)->retransmit_skb_hint);
+ WARN_ON(skb == tcp_sk(sk)->lost_skb_hint);
+ WARN_ON(skb == tcp_sk(sk)->scoreboard_skb_hint);
+ WARN_ON(skb == sk->sk_send_head);
__skb_unlink(skb, &sk->sk_write_queue);
}
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index e0cfa63..328bdb1 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -1102,11 +1102,11 @@ out:
do_fault:
if (!skb->len) {
- tcp_unlink_write_queue(skb, sk);
/* It is the one place in all of TCP, except connection
* reset, where we can be unlinking the send_head.
*/
tcp_check_send_head(sk, skb);
+ tcp_unlink_write_queue(skb, sk);
sk_wmem_free_skb(sk, skb);
}
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index ba0eab6..fccc6e9 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -3251,13 +3251,13 @@ static int tcp_clean_rtx_queue(struct sock *sk, int prior_fackets,
if (!fully_acked)
break;
- tcp_unlink_write_queue(skb, sk);
- sk_wmem_free_skb(sk, skb);
tp->scoreboard_skb_hint = NULL;
if (skb == tp->retransmit_skb_hint)
tp->retransmit_skb_hint = NULL;
if (skb == tp->lost_skb_hint)
tp->lost_skb_hint = NULL;
+ tcp_unlink_write_queue(skb, sk);
+ sk_wmem_free_skb(sk, skb);
}
if (likely(between(tp->snd_up, prior_snd_una, tp->snd_una)))
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 616c686..196171d 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -1791,6 +1791,10 @@ static void tcp_collapse_retrans(struct sock *sk, struct sk_buff *skb)
tcp_highest_sack_combine(sk, next_skb, skb);
+ /* changed transmit queue under us so clear hints */
+ tcp_clear_retrans_hints_partial(tp);
+ if (next_skb == tp->retransmit_skb_hint)
+ tp->retransmit_skb_hint = skb;
tcp_unlink_write_queue(next_skb, sk);
skb_copy_from_linear_data(next_skb, skb_put(skb, next_skb_size),
@@ -1813,10 +1817,6 @@ static void tcp_collapse_retrans(struct sock *sk, struct sk_buff *skb)
*/
TCP_SKB_CB(skb)->sacked |= TCP_SKB_CB(next_skb)->sacked & TCPCB_EVER_RETRANS;
- /* changed transmit queue under us so clear hints */
- tcp_clear_retrans_hints_partial(tp);
- if (next_skb == tp->retransmit_skb_hint)
- tp->retransmit_skb_hint = skb;
tcp_adjust_pcount(sk, next_skb, tcp_skb_pcount(next_skb));
next prev parent reply other threads:[~2009-10-29 14:08 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-26 15:41 Fw: [Bug 14470] New: freez in TCP stack Stephen Hemminger
2009-10-28 22:13 ` Andrew Morton
2009-10-28 22:27 ` Denys Fedoryschenko
2009-10-29 5:35 ` Eric Dumazet
2009-10-29 5:59 ` Eric Dumazet
2009-10-29 6:02 ` David Miller
2009-10-29 8:00 ` David Miller
2009-11-26 21:54 ` Ilpo Järvinen
2009-11-26 23:37 ` David Miller
2009-11-27 6:17 ` Eric Dumazet
2009-12-02 23:10 ` David Miller
2009-12-03 6:24 ` David Miller
2010-03-18 21:04 ` Andrew Morton
2010-03-19 15:52 ` Ilpo Järvinen
2009-10-29 12:58 ` Fw: " Ilpo Järvinen
2009-10-29 14:08 ` Eric Dumazet [this message]
2009-10-30 20:18 ` Herbert Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4AE9A1DE.6000808@gmail.com \
--to=eric.dumazet@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=bugzilla-daemon@bugzilla.kernel.org \
--cc=davem@davemloft.net \
--cc=ilpo.jarvinen@helsinki.fi \
--cc=kolo@albatani.cz \
--cc=netdev@vger.kernel.org \
--cc=shemminger@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).