aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation
diff options
context:
space:
mode:
authorEric Dumazet <eric.dumazet@gmail.com>2009-07-16 08:03:40 -0400
committerPatrick McHardy <kaber@trash.net>2009-07-16 08:03:40 -0400
commit941297f443f871b8c3372feccf27a8733f6ce9e9 (patch)
treec98b7e30bf14255cfd87a3d8d929f26f35764d21 /Documentation
parentaa6a03eb0ae859c1371555ef381de4c96ca1e4e6 (diff)
netfilter: nf_conntrack: nf_conntrack_alloc() fixes
When a slab cache uses SLAB_DESTROY_BY_RCU, we must be careful when allocating objects, since slab allocator could give a freed object still used by lockless readers. In particular, nf_conntrack RCU lookups rely on ct->tuplehash[xxx].hnnode.next being always valid (ie containing a valid 'nulls' value, or a valid pointer to next object in hash chain.) kmem_cache_zalloc() setups object with NULL values, but a NULL value is not valid for ct->tuplehash[xxx].hnnode.next. Fix is to call kmem_cache_alloc() and do the zeroing ourself. As spotted by Patrick, we also need to make sure lookup keys are committed to memory before setting refcount to 1, or a lockless reader could get a reference on the old version of the object. Its key re-check could then pass the barrier. Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: Patrick McHardy <kaber@trash.net>
Diffstat (limited to 'Documentation')
-rw-r--r--Documentation/RCU/rculist_nulls.txt7
1 files changed, 6 insertions, 1 deletions
diff --git a/Documentation/RCU/rculist_nulls.txt b/Documentation/RCU/rculist_nulls.txt
index 93cb28d05dcd..18f9651ff23d 100644
--- a/Documentation/RCU/rculist_nulls.txt
+++ b/Documentation/RCU/rculist_nulls.txt
@@ -83,11 +83,12 @@ not detect it missed following items in original chain.
83obj = kmem_cache_alloc(...); 83obj = kmem_cache_alloc(...);
84lock_chain(); // typically a spin_lock() 84lock_chain(); // typically a spin_lock()
85obj->key = key; 85obj->key = key;
86atomic_inc(&obj->refcnt);
87/* 86/*
88 * we need to make sure obj->key is updated before obj->next 87 * we need to make sure obj->key is updated before obj->next
88 * or obj->refcnt
89 */ 89 */
90smp_wmb(); 90smp_wmb();
91atomic_set(&obj->refcnt, 1);
91hlist_add_head_rcu(&obj->obj_node, list); 92hlist_add_head_rcu(&obj->obj_node, list);
92unlock_chain(); // typically a spin_unlock() 93unlock_chain(); // typically a spin_unlock()
93 94
@@ -159,6 +160,10 @@ out:
159obj = kmem_cache_alloc(cachep); 160obj = kmem_cache_alloc(cachep);
160lock_chain(); // typically a spin_lock() 161lock_chain(); // typically a spin_lock()
161obj->key = key; 162obj->key = key;
163/*
164 * changes to obj->key must be visible before refcnt one
165 */
166smp_wmb();
162atomic_set(&obj->refcnt, 1); 167atomic_set(&obj->refcnt, 1);
163/* 168/*
164 * insert obj in RCU way (readers might be traversing chain) 169 * insert obj in RCU way (readers might be traversing chain)