From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.196 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796291388; b=NVMA/hZqs0jeh3S7UzlSV3YhYqoc0mPlxk/n3DxS4xMU/V0PGCG1fW7gzngYyMM+A3+u AROQRwA07TTYXRaJlzcIPXIbCUIa78REyGcQE0yOwMXBbzveDqsoqSz+0goVbR+SHpM8L kuCqFyQMFrtSMD0G1wuFYzEGfh4hNCLACBt/6Pk9rHOzJ0cawwW2UKurg+nfsxlccz4SQ CakqbxVXsCQHTrTBPnQu36fAFryc9pSPcn1OzfQKoEj6JqyLUciiBXDA/0BWnym94vG5Z bniBf0+Nn9AEootfEgjiIthAH622ZmF6gmvQKQ0QBrytwKXttdShSWcGG+rMfxD8LyQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796291388; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:X-Mailer; bh=3+DclFbr+htpGGTBOfhxtzlPft2pt6nAQ5TBMMeVKPA=; b=Y5OwNY5mpFvVKPmoUwvP42d1mXXGET+jEu3/GIYshQ4QbEiLtYRWgjU1QIsBgIQUumvv aU0UacU/Ns3LvUOOKSPsBsL/JBmiewXabrY9TYb8tphBG5hDHuH8Z+PJGg45WmDSi9uLL sudwkIVUDA+qmZjRZ5rbRNwjiVXkjqQIkbHClPYPFulLopFL1+R932nCSodqDGP7U3UfJ O/SwU8UpUmsdNVdNsSQh/ZlrH8O1aoIcH6OpHn/Jnz8Hg/i5G6LOKMDEGb92Tt3f08D2b hQuPi4pJFeKiGdoFCHCuU6jfDElHreP8Be6wsvxZRBRoWpaDlzk5fJ4FrlY11+pk9lg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=YBZrHPZC; arc=none smtp.remote-ip=209.85.214.196 Received: from mail-pl1-f196.google.com (mail-pl1-f196.google.com [209.85.214.196]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F019A606A334 for ; Thu, 3 Dec 2026 09:49:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org F019A606A334 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=YBZrHPZC Received: by mail-pl1-f196.google.com with SMTP id d9443c01a7336-2e9ae391a05so5884525ad.1 for ; Thu, 03 Dec 2026 01:49:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796291387; x=1796896187; darn=vger.kernel.org; h=content-disposition:content-type:mime-version:message-id:subject:cc :to:from:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=3+DclFbr+htpGGTBOfhxtzlPft2pt6nAQ5TBMMeVKPA=; b=YBZrHPZC/iiA4Jf/2B4mjxyqPHNCNtQajp4lLFlDsUvJpueYRLPzhoa4ZkTb6YMz0y pTxp/MANQcKzg1eEePN+k5NxujsDb67tzF/UIVi92Of2pRBlCG1kTZmUHarcuCKm/KnJ Kcs+uu1KlLa4d9Ex7Z4wA+Cs//yppVZPWvQFK8NXWZg40X86KNLUepkFZg2gnCG7vAYX uZkGZDhaUx7MXS3fw8AbgRF4M518IK4rKN++xhA3PnuzdhJUg46xaqBJTEWUAbyZjSHa r1I3mDCW1ZDn68XBaBBcvRZxHxhKEJo3J0MmcuXdikSkJqASjAiz0KkZjlZS2wZEr48f NYmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796291387; x=1796896187; h=content-disposition:content-type:mime-version:message-id:subject:cc :to:from:date:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=3+DclFbr+htpGGTBOfhxtzlPft2pt6nAQ5TBMMeVKPA=; b=LGXhokZPQ3rPgNKiUHWi+/jFO+x9/B68weH39kYOSIT7fryNWz4Uhti+kXYYTrWT9u sYT0QVQ+EYhbgaXU7ZV6Ngy6qIIiLcm1mbfv2br6oOcjQnDwufNo24pe6g7ssFbLA5A4 uev9rAGtCGOBldAzqL88yxojN/OZsf4LUQz2gT8R1u6SeCGBB3ysCw1cCq6Fkzc0BmPW 8BXn54NWsmbK2RIcK2pbm0CMxLcmm5rs9BGtuH3NDLp+rjvk5lWmzUGvcB4yvf2HTeXj kKEokxDZKCn9Y7Zyg+RoXOqe2SXCkMQOHfoF5ScMZ5ebfK5xirxPkoh5U5Cc+QX780dO M5WA== X-Forwarded-Encrypted: i=1; AL+hErH78z2chgMsdLrSX6+FtVx0K9+StI0jG37rHszjhehcKH9mZbIZboWTxca+xKqeJXvq4q6vE8Y=@vger.kernel.org X-Gm-Message-State: APuU4Z9QCd7u1bos7OQATcuHBcQ6d2vHWMa0kdHp+MuNkByeCOTQ6clJ 6Is3Xh6+ANrJLPPmZXPKczWnq5vUvyTl4ZrveU3MBbGb2s/zClcdbNBf X-Gm-Gg: AZFdTZcF9VqRgdCrjNqoCACXl5BDkgRMCbZkjbi7pgsCl1axrUTKUJHvh2sUJlRW4wN azKc4+S6At51kRn+ZLFGUj15czC+3pZOQcAfBZLOSalojZjlAnK+Ri9mlPrWuW9KMKm4K8LWxKE Egi1v5oByae2JGI2engb/86YrDtcPDwDQvy31bY6f3Pu2FADW7WoZES18BZnewH9dJSW8oK483D xRH4TEfV+sAUlAJpA3uObyx7jBl7TBAN0I0UmRM4rundTL2czk0vbcxN5smFTFdzDFVuhW7gL8k AEKhUmEoZAUGDJiHm74vnliTzzJ4ksAXlLNGPZjNovs6JIiRCZHDtRxA1JiHjJooZsd8IF1Rwk8 ioCqcsDbs5tyQRtHo11zB9VZps8mTT8iQLhvvLIHoR+IAKfrSRTSHr5TwGR5ntHXhRB8GnAtJp4 is2rMtHmr+AQ2mjqJh5ETW45fxqfdahGYriQAiSNN+KTYcwafNEYXTH0Mv+FHG1cVOSEBMHnlZB Syslhzz9BZLh7v46cCxvlVFeuZBFG5gCGtu91VNXsHIz+d2Pb8yCXW3siZlCfm/tU8H+0Z3UvjX yuRMzUYIX32XIJbp7suuxw== X-Received: by 2002:a17:902:d584:b0:2f1:3c0f:bafc with SMTP id d9443c01a7336-2f19715e248mr12067245ad.18.1796291386995; Thu, 03 Dec 2026 01:49:46 -0800 (PST) Received: from hhost ([2409:8a55:3161:29f0:7f14:2cb3:33a0:f9a3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2f051a566f7sm206285005ad.41.2026.12.03.01.49.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 01:49:46 -0800 (PST) Date: Thu, 3 Dec 2026 17:49:09 +0800 From: Xingyuan Mo To: Pablo Neira Ayuso , Florian Westphal , Phil Sutter , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: "open list:NETFILTER" , "open list:NETFILTER" , Xingyuan Mo , stable@vger.kernel.org Subject: [PATCH nf] netfilter: nf_nat: don't kill an unconfirmed conntrack on oif change Message-ID: <20261203094859.2263418-1-hdthky0@gmail.com> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Mailer: git-send-email 2.43.0 nf_nat_inet_fn() runs nf_ct_kill_acct() on the conntrack when a connection that has already been set up for masquerade shows up at POST_ROUTING with an output device other than the one the masquerade target recorded. Nothing guarantees that this conntrack was confirmed by then. ipmr forwards a multicast packet by cloning the skb for every vif and running each clone through NF_INET_FORWARD and ip_output(), so every clone reaches POST_ROUTING with its own output device while the conntrack created at PRE_ROUTING is still unconfirmed, because ip_mr_input() is a dst.input handler and LOCAL_IN with its nf_confirm hook is never crossed. If the first clone gets masqueraded and is then dropped by a postrouting hook that runs before nf_confirm, the second clone finds NAT already initialised for the connection, takes the oif_changed path and calls nf_ct_delete() on the unconfirmed conntrack. clean_from_lists() then unlinks tuplehash[IP_CT_DIR_ORIGINAL].hnnode, whose pprev is NULL until confirmation, and writes through the NULL pointer. An unconfirmed conntrack is not linked into any list, so there is nothing to delete. Drop the packet and leave the conntrack to be released by the last skb holding a reference to it. KASAN report: BUG: KASAN: null-ptr-deref in __nf_ct_delete_from_lists+0x1b3/0x290 Write of size 8 at addr 0000000000000000 by task poc119/577 Call Trace: __nf_ct_delete_from_lists+0x1b3/0x290 nf_ct_delete.part.0+0x119/0x320 nf_ct_kill_acct+0xbe/0xd0 nf_nat_inet_fn+0x2aa/0x450 nf_nat_ipv4_out+0x96/0x200 nf_hook_slow+0x69/0x140 ip_mc_output+0x413/0x500 ip_mr_output+0x119/0x810 ipmr_queue_fwd_xmit.constprop.0+0x512/0x520 ip_mr_forward+0x5d9/0x5e0 ip_mr_input+0x273/0x730 Fixes: c65ef8dc7b1c ("netfilter: nf_nat: Also handle non-ESTABLISHED routing changes in MASQUERADE") Cc: stable@vger.kernel.org Signed-off-by: Xingyuan Mo --- net/netfilter/nf_nat_core.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/netfilter/nf_nat_core.c b/net/netfilter/nf_nat_core.c index 5329881ce2fff..f9e9a6e5b1594 100644 --- a/net/netfilter/nf_nat_core.c +++ b/net/netfilter/nf_nat_core.c @@ -959,6 +959,9 @@ nf_nat_inet_fn(void *priv, struct sk_buff *skb, return nf_nat_packet(ct, ctinfo, state->hook, skb); oif_changed: + if (!nf_ct_is_confirmed(ct)) + return NF_DROP; + nf_ct_kill_acct(ct, ctinfo, skb); return NF_DROP; } -- 2.43.0