]> git.baikalelectronics.ru Git - kernel.git/commit
netfilter: nfnetlink_acct: fix race between nfacct del and xt_nfacct destroy
authorLiping Zhang <liping.zhang@spreadtrum.com>
Sat, 13 Aug 2016 15:13:01 +0000 (23:13 +0800)
committerPablo Neira Ayuso <pablo@netfilter.org>
Thu, 18 Aug 2016 13:16:36 +0000 (15:16 +0200)
commite37415dcadb068819b624e372645a979beb745c2
tree23ca6b03912195458a76e46afaf2857347d11b67
parent57cd17c21ecd72282b9baaf7c9d7998966384cf6
netfilter: nfnetlink_acct: fix race between nfacct del and xt_nfacct destroy

Suppose that we input the following commands at first:
  # nfacct add test
  # iptables -A INPUT -m nfacct --nfacct-name test

And now "test" acct's refcnt is 2, but later when we try to delete the
"test" nfacct and the related iptables rule at the same time, race maybe
happen:
      CPU0                                    CPU1
  nfnl_acct_try_del                      nfnl_acct_put
  atomic_dec_and_test //ref=1,testfail          -
       -                                 atomic_dec_and_test //ref=0,testok
       -                                 kfree_rcu
  atomic_inc //ref=1                            -

So after the rcu grace period, nf_acct will be freed but it is still linked
in the nfnl_acct_list, and we can access it later, then oops will happen.

Convert atomic_dec_and_test and atomic_inc combinaiton to one atomic
operation atomic_cmpxchg here to fix this problem.

Signed-off-by: Liping Zhang <liping.zhang@spreadtrum.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
net/netfilter/nfnetlink_acct.c