Skip to content

Commit 8cc196d

Browse files
dsaherndavem330
authored andcommitted
neighbor: gc_list changes should be protected by table lock
Adding and removing neighbor entries to / from the gc_list need to be done while holding the table lock; a couple of places were missed in the original patch. Move the list_add_tail in neigh_alloc to ___neigh_create where the lock is already obtained. Since neighbor entries should rarely be moved to/from PERMANENT state, add lock/unlock around the gc_list changes in neigh_change_state rather than extending the lock hold around all neighbor updates. Fixes: 5895631 ("neighbor: Improve garbage collection") Reported-by: Andrei Vagin <[email protected]> Reported-by: [email protected] Reported-by: [email protected] Reported-by: [email protected] Reported-by: [email protected] Reported-by: [email protected] Reported-by: [email protected] Signed-off-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 9369832 commit 8cc196d

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

net/core/neighbour.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,17 @@ static void neigh_change_state(struct neighbour *n, u8 new)
138138
* add to the gc list if new state is not permanent
139139
*/
140140
if (new_is_perm && on_gc_list) {
141+
write_lock_bh(&n->tbl->lock);
141142
list_del_init(&n->gc_list);
143+
write_unlock_bh(&n->tbl->lock);
144+
142145
atomic_dec(&n->tbl->gc_entries);
143146
} else if (!new_is_perm && !on_gc_list) {
144147
/* add entries to the tail; cleaning removes from the front */
148+
write_lock_bh(&n->tbl->lock);
145149
list_add_tail(&n->gc_list, &n->tbl->gc_list);
150+
write_unlock_bh(&n->tbl->lock);
151+
146152
atomic_inc(&n->tbl->gc_entries);
147153
}
148154
}
@@ -390,11 +396,7 @@ static struct neighbour *neigh_alloc(struct neigh_table *tbl,
390396
n->tbl = tbl;
391397
refcount_set(&n->refcnt, 1);
392398
n->dead = 1;
393-
394-
if (!permanent)
395-
list_add_tail(&n->gc_list, &n->tbl->gc_list);
396-
else
397-
INIT_LIST_HEAD(&n->gc_list);
399+
INIT_LIST_HEAD(&n->gc_list);
398400

399401
atomic_inc(&tbl->entries);
400402
out:
@@ -616,6 +618,9 @@ static struct neighbour *___neigh_create(struct neigh_table *tbl,
616618
}
617619

618620
n->dead = 0;
621+
if (!permanent)
622+
list_add_tail(&n->gc_list, &n->tbl->gc_list);
623+
619624
if (want_ref)
620625
neigh_hold(n);
621626
rcu_assign_pointer(n->next,

0 commit comments

Comments
 (0)