Skip to content

Commit b3e456f

Browse files
congwangummakynes
authored andcommitted
netfilter: ipt_CLUSTERIP: fix a race condition of proc file creation
There is a race condition between clusterip_config_entry_put() and clusterip_config_init(), after we release the spinlock in clusterip_config_entry_put(), a new proc file with a same IP could be created immediately since it is already removed from the configs list, therefore it triggers this warning: ------------[ cut here ]------------ proc_dir_entry 'ipt_CLUSTERIP/172.20.0.170' already registered WARNING: CPU: 1 PID: 4152 at fs/proc/generic.c:330 proc_register+0x2a4/0x370 fs/proc/generic.c:329 Kernel panic - not syncing: panic_on_warn set ... As a quick fix, just move the proc_remove() inside the spinlock. Reported-by: <[email protected]> Fixes: 6c5d5cf ("netfilter: ipt_CLUSTERIP: check duplicate config when initializing") Tested-by: Paolo Abeni <[email protected]> Cc: Xin Long <[email protected]> Cc: Pablo Neira Ayuso <[email protected]> Signed-off-by: Cong Wang <[email protected]> Reviewed-by: Xin Long <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent fd2c19b commit b3e456f

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

net/ipv4/netfilter/ipt_CLUSTERIP.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,19 +107,19 @@ clusterip_config_entry_put(struct net *net, struct clusterip_config *c)
107107

108108
local_bh_disable();
109109
if (refcount_dec_and_lock(&c->entries, &cn->lock)) {
110-
list_del_rcu(&c->list);
111-
spin_unlock(&cn->lock);
112-
local_bh_enable();
113-
114-
unregister_netdevice_notifier(&c->notifier);
115-
116110
/* In case anyone still accesses the file, the open/close
117111
* functions are also incrementing the refcount on their own,
118112
* so it's safe to remove the entry even if it's in use. */
119113
#ifdef CONFIG_PROC_FS
120114
if (cn->procdir)
121115
proc_remove(c->pde);
122116
#endif
117+
list_del_rcu(&c->list);
118+
spin_unlock(&cn->lock);
119+
local_bh_enable();
120+
121+
unregister_netdevice_notifier(&c->notifier);
122+
123123
return;
124124
}
125125
local_bh_enable();

0 commit comments

Comments
 (0)