From: Raghu Angadi <raghuangadi@yahoo.com>
To: "David S. Miller" <davem@redhat.com>
Cc: kuznet@ms2.inr.ac.ru, linux-kernel@vger.kernel.org
Subject: Re: memory corruption in tcp bind hash buckets on SMP?
Date: Mon, 4 Mar 2002 16:54:39 -0800 (PST) [thread overview]
Message-ID: <20020305005439.87673.qmail@web12302.mail.yahoo.com> (raw)
In-Reply-To: <20020304.152646.123971801.davem@redhat.com>
1st patch: reverses the insertion order in __tcp_tw_hashdance(). This is what
we tested
2nd patch: removes conditional around tw->tb in tcp_timewait_kill(). I have
only made sure it compiles. "tw-tb == NULL;" is not strictly required.. but
esures oops if we end up in similar race again.
patch 1:
--------
--- linux-2.4.7-10/net/ipv4/tcp_minisocks.c Thu Sep 6 13:11:49 2001
+++ linux-2.4.7-10-mod/net/ipv4/tcp_minisocks.c Fri Mar 1 15:41:26 2002
@@ -304,9 +304,25 @@
struct tcp_bind_hashbucket *bhead;
struct sock **head, *sktw;
+
+ /* Step 1: Put TW into bind hash. Original socket stays there too.
+ Note, that any socket with sk->num!=0 MUST be bound in binding
+ cache, even if it is closed.
+ */
+ bhead = &tcp_bhash[tcp_bhashfn(sk->num)];
+ spin_lock(&bhead->lock);
+ tw->tb = (struct tcp_bind_bucket *)sk->prev;
+ BUG_TRAP(sk->prev!=NULL);
+ if ((tw->bind_next = tw->tb->owners) != NULL)
+ tw->tb->owners->bind_pprev = &tw->bind_next;
+ tw->tb->owners = (struct sock*)tw;
+ tw->bind_pprev = &tw->tb->owners;
+ spin_unlock(&bhead->lock);
+
write_lock(&ehead->lock);
- /* Step 1: Remove SK from established hash. */
+ /* Step 2: Remove SK from established hash. */
if (sk->pprev) {
if(sk->next)
sk->next->pprev = sk->pprev;
@@ -315,7 +331,7 @@
sock_prot_dec_use(sk->prot);
}
- /* Step 2: Hash TW into TIMEWAIT half of established hash table. */
+ /* Step 3: Hash TW into TIMEWAIT half of established hash table. */
head = &(ehead + tcp_ehash_size)->chain;
sktw = (struct sock *)tw;
if((sktw->next = *head) != NULL)
@@ -325,20 +341,6 @@
atomic_inc(&tw->refcnt);
write_unlock(&ehead->lock);
-
- /* Step 3: Put TW into bind hash. Original socket stays there too.
- Note, that any socket with sk->num!=0 MUST be bound in binding
- cache, even if it is closed.
- */
- bhead = &tcp_bhash[tcp_bhashfn(sk->num)];
- spin_lock(&bhead->lock);
- tw->tb = (struct tcp_bind_bucket *)sk->prev;
- BUG_TRAP(sk->prev!=NULL);
- if ((tw->bind_next = tw->tb->owners) != NULL)
- tw->tb->owners->bind_pprev = &tw->bind_next;
- tw->tb->owners = (struct sock*)tw;
- tw->bind_pprev = &tw->tb->owners;
- spin_unlock(&bhead->lock);
}
/*
patch 2:
--------
--- linux-2.4.7-10/net/ipv4/tcp_minisocks.c Thu Sep 6 13:11:49 2001
+++ linux-2.4.7-10-mod/net/ipv4/tcp_minisocks.c Mon Mar 4 16:41:35 2002
@@ -75,17 +75,16 @@
/* Disassociate with bind bucket. */
bhead = &tcp_bhash[tcp_bhashfn(tw->num)];
spin_lock(&bhead->lock);
- if ((tb = tw->tb) != NULL) {
- if(tw->bind_next)
- tw->bind_next->bind_pprev = tw->bind_pprev;
- *(tw->bind_pprev) = tw->bind_next;
- tw->tb = NULL;
- if (tb->owners == NULL) {
- if (tb->next)
- tb->next->pprev = tb->pprev;
- *(tb->pprev) = tb->next;
- kmem_cache_free(tcp_bucket_cachep, tb);
- }
+ tb = tw->tb;
+ if(tw->bind_next)
+ tw->bind_next->bind_pprev = tw->bind_pprev;
+ *(tw->bind_pprev) = tw->bind_next;
+ tw->tb = NULL;
+ if (tb->owners == NULL) {
+ if (tb->next)
+ tb->next->pprev = tb->pprev;
+ *(tb->pprev) = tb->next;
+ kmem_cache_free(tcp_bucket_cachep, tb);
}
spin_unlock(&bhead->lock);
--- "David S. Miller" <davem@redhat.com> wrote:
> From: Raghu Angadi <raghuangadi@yahoo.com>
> Date: Mon, 4 Mar 2002 12:48:32 -0800 (PST)
>
> We have been load testing the kernel with this patch (reverse the
> insertion
> order in __tcp_tw_hashdance(). It seems to work fine till now.
>
> Where was "this patch" posted? I never saw anyone post
> any code, all anyone did was merely describe the change :)
__________________________________________________
Do You Yahoo!?
Yahoo! Sports - sign up for Fantasy Baseball
http://sports.yahoo.com
next prev parent reply other threads:[~2002-03-05 0:54 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20020226.231934.116353439.davem@redhat.com>
2002-02-27 19:04 ` Fw: " kuznet
2002-02-27 19:46 ` Raghu Angadi
2002-02-27 20:05 ` Raghu Angadi
2002-02-27 20:12 ` kuznet
2002-02-27 20:31 ` Raghu Angadi
2002-03-01 19:07 ` kuznet
2002-03-04 20:48 ` Raghu Angadi
2002-03-04 23:26 ` David S. Miller
2002-03-05 0:54 ` Raghu Angadi [this message]
2002-03-05 4:30 ` David S. Miller
2002-02-27 20:08 ` Fw: " kuznet
2002-02-27 20:26 ` Raghu Angadi
2002-02-28 5:53 ` Raghu Angadi
2002-02-13 6:05 Raghu Angadi
2002-02-13 6:17 ` David S. Miller
2002-02-14 0:51 ` Raghu Angadi
2002-02-14 3:07 ` David S. Miller
2002-02-21 4:16 ` Raghu Angadi
2002-02-23 7:24 ` Raghu Angadi
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=20020305005439.87673.qmail@web12302.mail.yahoo.com \
--to=raghuangadi@yahoo.com \
--cc=davem@redhat.com \
--cc=kuznet@ms2.inr.ac.ru \
--cc=linux-kernel@vger.kernel.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
all inboxes | Powered by JetHome®