CPU0 CPU1 xt_CT attaches tmpl_ct remove rule with xt_CT ... ... nf_queue_nf_hook_drop() nfqueue's enqueue_skb While skb is flying to be enqueued by nfqueue, the rule and the helper/timeout can be removed, leaving a dangling pointer in the ct extensions. Set on dying bit in the template and handle this from nfnetlink_queue. Fixes: 84f3bb9ae9db ("netfilter: xtables: add CT target") Signed-off-by: Pablo Neira Ayuso --- net/netfilter/nfnetlink_queue.c | 20 ++++++++++++++++++++ net/netfilter/xt_CT.c | 2 ++ 2 files changed, 22 insertions(+) diff --git a/net/netfilter/nfnetlink_queue.c b/net/netfilter/nfnetlink_queue.c index 984a0eb9e149..c682adc34dcf 100644 --- a/net/netfilter/nfnetlink_queue.c +++ b/net/netfilter/nfnetlink_queue.c @@ -412,6 +412,20 @@ static void nf_reinject(struct nf_queue_entry *entry, unsigned int verdict) nf_queue_entry_free(entry); } +static bool nf_ct_drop_template(const struct nf_queue_entry *entry) +{ +#if IS_ENABLED(CONFIG_NF_CONNTRACK) + struct nf_conn *ct = (void *)skb_nfct(entry->skb); + + if (!ct || !nf_ct_is_template(ct)) + return false; + + if (nf_ct_is_dying(ct)) + return true; +#endif + return false; +} + /* return true if the entry has an unconfirmed conntrack attached that isn't owned by us * exclusively. */ @@ -468,6 +482,9 @@ static void nfqnl_reinject(struct nf_queue_entry *entry, unsigned int verdict) } } + if (nf_ct_drop_template(entry)) + verdict = NF_DROP; + if (verdict != NF_DROP && entry->nf_ct_is_unconfirmed) { /* If first queued segment was already reinjected then * there is a good chance the ct entry is now confirmed. @@ -1077,6 +1094,9 @@ nfqnl_enqueue_packet(struct nf_queue_entry *entry, unsigned int queuenum) break; } + if (nf_ct_drop_template(entry)) + return -EINVAL; + /* Check if someone already holds another reference to * unconfirmed ct. If so, we cannot queue the skb: * concurrent modifications of nf_conn->ext are not diff --git a/net/netfilter/xt_CT.c b/net/netfilter/xt_CT.c index 827e45f5d5ee..9c4e8e3f6d25 100644 --- a/net/netfilter/xt_CT.c +++ b/net/netfilter/xt_CT.c @@ -285,6 +285,8 @@ static void xt_ct_tg_destroy(const struct xt_tgdtor_param *par, struct nf_conn_help *help; if (ct) { + set_bit(IPS_DYING_BIT, &ct->status); + if (info->helper[0] || info->timeout[0]) nf_queue_nf_hook_drop(par->net); -- 2.47.3