Skip to content

Commit 9464d0b

Browse files
lxinummakynes
authored andcommitted
netfilter: conntrack: fix using __this_cpu_add in preemptible
Currently in nf_conntrack_hash_check_insert(), when it fails in nf_ct_ext_valid_pre/post(), NF_CT_STAT_INC() will be called in the preemptible context, a call trace can be triggered: BUG: using __this_cpu_add() in preemptible [00000000] code: conntrack/1636 caller is nf_conntrack_hash_check_insert+0x45/0x430 [nf_conntrack] Call Trace: <TASK> dump_stack_lvl+0x33/0x46 check_preemption_disabled+0xc3/0xf0 nf_conntrack_hash_check_insert+0x45/0x430 [nf_conntrack] ctnetlink_create_conntrack+0x3cd/0x4e0 [nf_conntrack_netlink] ctnetlink_new_conntrack+0x1c0/0x450 [nf_conntrack_netlink] nfnetlink_rcv_msg+0x277/0x2f0 [nfnetlink] netlink_rcv_skb+0x50/0x100 nfnetlink_rcv+0x65/0x144 [nfnetlink] netlink_unicast+0x1ae/0x290 netlink_sendmsg+0x257/0x4f0 sock_sendmsg+0x5f/0x70 This patch is to fix it by changing to use NF_CT_STAT_INC_ATOMIC() for nf_ct_ext_valid_pre/post() check in nf_conntrack_hash_check_insert(), as well as nf_ct_ext_valid_post() in __nf_conntrack_confirm(). Note that nf_ct_ext_valid_pre() check in __nf_conntrack_confirm() is safe to use NF_CT_STAT_INC(), as it's under local_bh_disable(). Fixes: c56716c ("netfilter: extensions: introduce extension genid count") Signed-off-by: Xin Long <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent a810471 commit 9464d0b

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

net/netfilter/nf_conntrack_core.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ nf_conntrack_hash_check_insert(struct nf_conn *ct)
891891
zone = nf_ct_zone(ct);
892892

893893
if (!nf_ct_ext_valid_pre(ct->ext)) {
894-
NF_CT_STAT_INC(net, insert_failed);
894+
NF_CT_STAT_INC_ATOMIC(net, insert_failed);
895895
return -ETIMEDOUT;
896896
}
897897

@@ -938,7 +938,7 @@ nf_conntrack_hash_check_insert(struct nf_conn *ct)
938938

939939
if (!nf_ct_ext_valid_post(ct->ext)) {
940940
nf_ct_kill(ct);
941-
NF_CT_STAT_INC(net, drop);
941+
NF_CT_STAT_INC_ATOMIC(net, drop);
942942
return -ETIMEDOUT;
943943
}
944944

@@ -1275,7 +1275,7 @@ __nf_conntrack_confirm(struct sk_buff *skb)
12751275
*/
12761276
if (!nf_ct_ext_valid_post(ct->ext)) {
12771277
nf_ct_kill(ct);
1278-
NF_CT_STAT_INC(net, drop);
1278+
NF_CT_STAT_INC_ATOMIC(net, drop);
12791279
return NF_DROP;
12801280
}
12811281

0 commit comments

Comments
 (0)