nf_confirm_cthelper() is called via nf_conntrack_update() when a packet that was queued to a userspace conntrack helper is reinjected with an ACCEPT verdict. When the l4 header can't be located -- the packet is a fragment, or the header chain is malformed, or userspace rewrote the packet such that it no longer matches the conntrack tuple -- the function returns NF_ACCEPT without confirming the conntrack entry. This is wrong for packets that were queued from the confirm hook itself, which is the expected case: the userspace helper queues the packet from within nf_confirm(), i.e. before the conntrack entry was added to the hash table. On reinject there is no later hook that could confirm the entry, so the skb leaves the host with an unconfirmed conntrack entry attached. The entry is never inserted into the conntrack hash table, so later packets of the same flow create new (unconfirmed) entries and nat, helper and expectation state is lost. Skip helper and seqadj processing as before, but fall through to nf_conntrack_confirm(). Problem located during an LLM-assisted review of the helper hardening series; verified by inspection. No reproducer: it needs a userspace conntrack helper whose verdict rewrites the reinjected packet into a state that fails header validation. As this isn't supposed to be possible anymore, this patch should not have an observable effect. Fixes: ee04805ff54a ("netfilter: conntrack: make conntrack userspace helpers work again") Cc: stable@vger.kernel.org Signed-off-by: Florian Westphal --- net/netfilter/nf_conntrack_core.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c index 2ceb198c70ac..03c800f29ad5 100644 --- a/net/netfilter/nf_conntrack_core.c +++ b/net/netfilter/nf_conntrack_core.c @@ -2234,8 +2234,13 @@ static int nf_confirm_cthelper(struct sk_buff *skb, struct nf_conn *ct, return NF_ACCEPT; if (!nf_confirm_get_protoff(skb, nf_ct_net(ct), ct, ctinfo, &protoff, - &pnum)) - return NF_ACCEPT; + &pnum)) { + /* Helper and seqadj are skipped, but the ct must still be + * committed: the packet was queued from nf_confirm(), no + * later hook will confirm it. + */ + return nf_conntrack_confirm(skb); + } if (test_bit(IPS_SEQ_ADJUST_BIT, &ct->status) && !nf_is_loopback_packet(skb)) { -- 2.56.1