mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-26 20:44:32 +08:00
netfilter: nf_queue: drop packets with cloned unconfirmed conntracks
[ Upstream commit7d8dc1c7be
] Conntrack assumes an unconfirmed entry (not yet committed to global hash table) has a refcount of 1 and is not visible to other cores. With multicast forwarding this assumption breaks down because such skbs get cloned after being picked up, i.e. ct->use refcount is > 1. Likewise, bridge netfilter will clone broad/mutlicast frames and all frames in case they need to be flood-forwarded during learning phase. For ip multicast forwarding or plain bridge flood-forward this will "work" because packets don't leave softirq and are implicitly serialized. With nfqueue this no longer holds true, the packets get queued and can be reinjected in arbitrary ways. Disable this feature, I see no other solution. After this patch, nfqueue cannot queue packets except the last multicast/broadcast packet. Fixes:1da177e4c3
("Linux-2.6.12-rc2") Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
356beb911b
commit
6c4a0ba674
@ -602,8 +602,12 @@ static unsigned int br_nf_local_in(void *priv,
|
|||||||
if (likely(nf_ct_is_confirmed(ct)))
|
if (likely(nf_ct_is_confirmed(ct)))
|
||||||
return NF_ACCEPT;
|
return NF_ACCEPT;
|
||||||
|
|
||||||
|
if (WARN_ON_ONCE(refcount_read(&nfct->use) != 1)) {
|
||||||
|
nf_reset_ct(skb);
|
||||||
|
return NF_ACCEPT;
|
||||||
|
}
|
||||||
|
|
||||||
WARN_ON_ONCE(skb_shared(skb));
|
WARN_ON_ONCE(skb_shared(skb));
|
||||||
WARN_ON_ONCE(refcount_read(&nfct->use) != 1);
|
|
||||||
|
|
||||||
/* We can't call nf_confirm here, it would create a dependency
|
/* We can't call nf_confirm here, it would create a dependency
|
||||||
* on nf_conntrack module.
|
* on nf_conntrack module.
|
||||||
|
@ -640,10 +640,41 @@ static bool nf_ct_drop_unconfirmed(const struct nf_queue_entry *entry)
|
|||||||
{
|
{
|
||||||
#if IS_ENABLED(CONFIG_NF_CONNTRACK)
|
#if IS_ENABLED(CONFIG_NF_CONNTRACK)
|
||||||
static const unsigned long flags = IPS_CONFIRMED | IPS_DYING;
|
static const unsigned long flags = IPS_CONFIRMED | IPS_DYING;
|
||||||
const struct nf_conn *ct = (void *)skb_nfct(entry->skb);
|
struct nf_conn *ct = (void *)skb_nfct(entry->skb);
|
||||||
|
unsigned long status;
|
||||||
|
unsigned int use;
|
||||||
|
|
||||||
if (ct && ((ct->status & flags) == IPS_DYING))
|
if (!ct)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
status = READ_ONCE(ct->status);
|
||||||
|
if ((status & flags) == IPS_DYING)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
if (status & IPS_CONFIRMED)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
/* in some cases skb_clone() can occur after initial conntrack
|
||||||
|
* pickup, but conntrack assumes exclusive skb->_nfct ownership for
|
||||||
|
* unconfirmed entries.
|
||||||
|
*
|
||||||
|
* This happens for br_netfilter and with ip multicast routing.
|
||||||
|
* We can't be solved with serialization here because one clone could
|
||||||
|
* have been queued for local delivery.
|
||||||
|
*/
|
||||||
|
use = refcount_read(&ct->ct_general.use);
|
||||||
|
if (likely(use == 1))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
/* Can't decrement further? Exclusive ownership. */
|
||||||
|
if (!refcount_dec_not_one(&ct->ct_general.use))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
skb_set_nfct(entry->skb, 0);
|
||||||
|
/* No nf_ct_put(): we already decremented .use and it cannot
|
||||||
|
* drop down to 0.
|
||||||
|
*/
|
||||||
|
return true;
|
||||||
#endif
|
#endif
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user