* [PATCH][NEIGH]: Fix race between neighbor lookup and table's hash_rnd update.
@ 2008-02-22 9:37 Pavel Emelyanov
2008-02-24 3:57 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: Pavel Emelyanov @ 2008-02-22 9:37 UTC (permalink / raw)
To: David Miller, Linux Netdev List, devel
The neigh_hash_grow() may update the tbl->hash_rnd value, which
is used in all tbl->hash callbacks to calculate the hashval.
Two lookup routines may race with this, since they call the
->hash callback without the tbl->lock held. Since the hash_rnd
is changed with this lock write-locked moving the calls to ->hash
under this lock read-locked closes this gap.
Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
---
diff --git a/net/core/neighbour.c b/net/core/neighbour.c
index 4062b88..2328acb 100644
--- a/net/core/neighbour.c
+++ b/net/core/neighbour.c
@@ -358,11 +358,12 @@ struct neighbour *neigh_lookup(struct neigh_table *tbl, const void *pkey,
{
struct neighbour *n;
int key_len = tbl->key_len;
- u32 hash_val = tbl->hash(pkey, dev);
+ u32 hash_val;
NEIGH_CACHE_STAT_INC(tbl, lookups);
read_lock_bh(&tbl->lock);
+ hash_val = tbl->hash(pkey, dev);
for (n = tbl->hash_buckets[hash_val & tbl->hash_mask]; n; n = n->next) {
if (dev == n->dev && !memcmp(n->primary_key, pkey, key_len)) {
neigh_hold(n);
@@ -379,11 +380,12 @@ struct neighbour *neigh_lookup_nodev(struct neigh_table *tbl, struct net *net,
{
struct neighbour *n;
int key_len = tbl->key_len;
- u32 hash_val = tbl->hash(pkey, NULL);
+ u32 hash_val;
NEIGH_CACHE_STAT_INC(tbl, lookups);
read_lock_bh(&tbl->lock);
+ hash_val = tbl->hash(pkey, NULL);
for (n = tbl->hash_buckets[hash_val & tbl->hash_mask]; n; n = n->next) {
if (!memcmp(n->primary_key, pkey, key_len) &&
(net == n->dev->nd_net)) {
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH][NEIGH]: Fix race between neighbor lookup and table's hash_rnd update.
2008-02-22 9:37 [PATCH][NEIGH]: Fix race between neighbor lookup and table's hash_rnd update Pavel Emelyanov
@ 2008-02-24 3:57 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2008-02-24 3:57 UTC (permalink / raw)
To: xemul; +Cc: netdev, devel
From: Pavel Emelyanov <xemul@openvz.org>
Date: Fri, 22 Feb 2008 12:37:03 +0300
> The neigh_hash_grow() may update the tbl->hash_rnd value, which
> is used in all tbl->hash callbacks to calculate the hashval.
>
> Two lookup routines may race with this, since they call the
> ->hash callback without the tbl->lock held. Since the hash_rnd
> is changed with this lock write-locked moving the calls to ->hash
> under this lock read-locked closes this gap.
>
> Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
Applied, thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-02-24 3:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-22 9:37 [PATCH][NEIGH]: Fix race between neighbor lookup and table's hash_rnd update Pavel Emelyanov
2008-02-24 3:57 ` David 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).