From: Thomas Graf <tgraf@suug.ch>
To: davem@davemloft.net,
Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
Cc: Ying Xue <ying.xue@windriver.com>,
"richard.alpe@ericsson.com >> Richard Alpe"
<richard.alpe@ericsson.com>, Netdev <netdev@vger.kernel.org>,
tipc-discussion@lists.sourceforge.net
Subject: [PATCH net-next v2] rhashtable: rhashtable_remove() must unlink in both tbl and future_tbl
Date: Wed, 21 Jan 2015 11:54:01 +0000 [thread overview]
Message-ID: <20150121115401.GA12570@casper.infradead.org> (raw)
In-Reply-To: <54BEA1F9.1050908@cogentembedded.com>
As removals can occur during resizes, entries may be referred to from
both tbl and future_tbl when the removal is requested. Therefore
rhashtable_remove() must unlink the entry in both tables if this is
the case. The existing code did search both tables but stopped when it
hit the first match.
Failing to unlink in both tables resulted in use after free.
Fixes: 97defe1ecf86 ("rhashtable: Per bucket locks & deferred expansion/shrinking")
Reported-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
---
v2: 12 digit commit reference, commit msg clarification as pointed
out by Sergei.
lib/rhashtable.c | 24 +++++++++++++++---------
1 file changed, 15 insertions(+), 9 deletions(-)
diff --git a/lib/rhashtable.c b/lib/rhashtable.c
index 84a78e3..bc2d0d8 100644
--- a/lib/rhashtable.c
+++ b/lib/rhashtable.c
@@ -585,6 +585,7 @@ bool rhashtable_remove(struct rhashtable *ht, struct rhash_head *obj)
struct rhash_head *he;
spinlock_t *lock;
unsigned int hash;
+ bool ret = false;
rcu_read_lock();
tbl = rht_dereference_rcu(ht->tbl, ht);
@@ -602,17 +603,16 @@ restart:
}
rcu_assign_pointer(*pprev, obj->next);
- atomic_dec(&ht->nelems);
-
- spin_unlock_bh(lock);
-
- rhashtable_wakeup_worker(ht);
-
- rcu_read_unlock();
- return true;
+ ret = true;
+ break;
}
+ /* The entry may be linked in either 'tbl', 'future_tbl', or both.
+ * 'future_tbl' only exists for a short period of time during
+ * resizing. Thus traversing both is fine and the added cost is
+ * very rare.
+ */
if (tbl != rht_dereference_rcu(ht->future_tbl, ht)) {
spin_unlock_bh(lock);
@@ -625,9 +625,15 @@ restart:
}
spin_unlock_bh(lock);
+
+ if (ret) {
+ atomic_dec(&ht->nelems);
+ rhashtable_wakeup_worker(ht);
+ }
+
rcu_read_unlock();
- return false;
+ return ret;
}
EXPORT_SYMBOL_GPL(rhashtable_remove);
--
1.9.3
next prev parent reply other threads:[~2015-01-21 11:54 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-19 8:03 [3.19.0-rc4+] rhashtable: BUG kmalloc-2048 (Not tainted): Poison overwritten Ying Xue
2015-01-19 12:59 ` Thomas Graf
2015-01-20 2:53 ` Ying Xue
2015-01-20 16:58 ` [PATCH net-next] rhashtable: rhashtable_remove() must unlink in both tbl and future_tbl Thomas Graf
2015-01-20 18:44 ` Sergei Shtylyov
2015-01-21 11:54 ` Thomas Graf [this message]
2015-01-26 19:57 ` [PATCH net-next v2] " David Miller
2015-01-21 8:39 ` [PATCH net-next] " Ying Xue
2015-01-21 11:56 ` Thomas Graf
2015-01-30 8:37 ` Ying Xue
2015-01-21 8:51 ` Ying Xue
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=20150121115401.GA12570@casper.infradead.org \
--to=tgraf@suug.ch \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
--cc=richard.alpe@ericsson.com \
--cc=sergei.shtylyov@cogentembedded.com \
--cc=tipc-discussion@lists.sourceforge.net \
--cc=ying.xue@windriver.com \
/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).