From: Cong Wang <hidden> Date: 2018-02-08 05:59:30
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: <redacted>
Fixes: 6c5d5cfbe3c5 ("netfilter: ipt_CLUSTERIP: check duplicate config when initializing")
Tested-by: Paolo Abeni <pabeni@redhat.com>
Cc: Xin Long <lucien.xin@gmail.com>
Cc: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Cong Wang <redacted>
---
net/ipv4/netfilter/ipt_CLUSTERIP.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
@@ -107,12 +107,6 @@ clusterip_config_entry_put(struct net *net, struct clusterip_config *c)local_bh_disable();if(refcount_dec_and_lock(&c->entries,&cn->lock)){-list_del_rcu(&c->list);-spin_unlock(&cn->lock);-local_bh_enable();--unregister_netdevice_notifier(&c->notifier);-/* In case anyone still accesses the file, the open/close*functionsarealsoincrementingtherefcountontheirown,*soit'ssafetoremovetheentryevenifit'sinuse.*/
@@ -120,6 +114,12 @@ clusterip_config_entry_put(struct net *net, struct clusterip_config *c)if(cn->procdir)proc_remove(c->pde);#endif+list_del_rcu(&c->list);+spin_unlock(&cn->lock);+local_bh_enable();++unregister_netdevice_notifier(&c->notifier);+return;}local_bh_enable();
From: Cong Wang <hidden> Date: 2018-02-08 05:59:18
In clusterip_config_find_get() we hold RCU read lock so it could
run concurrently with clusterip_config_entry_put(), as a result,
the refcnt could go back to 1 from 0, which leads to a double
list_del()... Just replace refcount_inc() with
refcount_inc_not_zero(), as for c->refcount.
Fixes: d73f33b16883 ("netfilter: CLUSTERIP: RCU conversion")
Cc: Eric Dumazet <redacted>
Cc: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Cong Wang <redacted>
---
net/ipv4/netfilter/ipt_CLUSTERIP.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
In clusterip_config_find_get() we hold RCU read lock so it could
run concurrently with clusterip_config_entry_put(), as a result,
the refcnt could go back to 1 from 0, which leads to a double
list_del()... Just replace refcount_inc() with
refcount_inc_not_zero(), as for c->refcount.
Fixes: d73f33b16883 ("netfilter: CLUSTERIP: RCU conversion")
Cc: Eric Dumazet <redacted>
Cc: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Cong Wang <redacted>
---
net/ipv4/netfilter/ipt_CLUSTERIP.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
From: Xin Long <lucien.xin@gmail.com> Date: 2018-02-08 11:45:06
On Thu, Feb 8, 2018 at 1:59 PM, Cong Wang [off-list ref] wrote:
quoted hunk
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: <redacted>
Fixes: 6c5d5cfbe3c5 ("netfilter: ipt_CLUSTERIP: check duplicate config when initializing")
Tested-by: Paolo Abeni <pabeni@redhat.com>
Cc: Xin Long <lucien.xin@gmail.com>
Cc: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Cong Wang <redacted>
---
net/ipv4/netfilter/ipt_CLUSTERIP.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
@@ -107,12 +107,6 @@ clusterip_config_entry_put(struct net *net, struct clusterip_config *c)local_bh_disable();if(refcount_dec_and_lock(&c->entries,&cn->lock)){-list_del_rcu(&c->list);-spin_unlock(&cn->lock);-local_bh_enable();--unregister_netdevice_notifier(&c->notifier);-/* In case anyone still accesses the file, the open/close*functionsarealsoincrementingtherefcountontheirown,*soit'ssafetoremovetheentryevenifit'sinuse.*/
@@ -120,6 +114,12 @@ clusterip_config_entry_put(struct net *net, struct clusterip_config *c)if(cn->procdir)proc_remove(c->pde);#endif+list_del_rcu(&c->list);+spin_unlock(&cn->lock);+local_bh_enable();++unregister_netdevice_notifier(&c->notifier);+return;}local_bh_enable();--
From: Pablo Neira Ayuso <pablo@netfilter.org> Date: 2018-02-08 16:58:30
On Wed, Feb 07, 2018 at 09:59:17PM -0800, Cong Wang wrote:
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.
From: Cong Wang <hidden> Date: 2018-02-08 20:05:48
On Thu, Feb 8, 2018 at 12:01 AM, Florian Westphal [off-list ref] wrote:
Cong Wang [off-list ref] wrote:
quoted
In clusterip_config_find_get() we hold RCU read lock so it could
run concurrently with clusterip_config_entry_put(), as a result,
the refcnt could go back to 1 from 0, which leads to a double
list_del()... Just replace refcount_inc() with
refcount_inc_not_zero(), as for c->refcount.
Fixes: d73f33b16883 ("netfilter: CLUSTERIP: RCU conversion")
Cc: Eric Dumazet <redacted>
Cc: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Cong Wang <redacted>
---
net/ipv4/netfilter/ipt_CLUSTERIP.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)