From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.netfilter.org (mail.netfilter.org [217.70.190.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 779E42C3251; Thu, 3 Sep 2026 00:42:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.190.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788396124; cv=none; b=RkYK4XggNJiYXRJ+7cIyzbbscSUF87AQKAWuVGMYs1E+bMaQ2E3EZUxfck+aedn/010X9+Tt7S1L9mTWU75NNzNmK4hK69OVISOCcGd9GRg6Mm+9eWgCAZubAEOpRpDTihNYAEPHEoMkFM/i+NkXvqD/NmFBMH+tXPTlMzGjU0k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788396124; c=relaxed/simple; bh=KDMZxKBokX/eFmwjI6AiPYr9lz9zdu6GtHeQGtGseKM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ce/vD0SJNNzqkNHaMz/FfO/+MvYobuY1ZNzyM5jO1X1+3dKgdxY8URVcVIm4j7cv4hBV0miWPG104DzALIjegWqK9yUw2YqWPB4Hyacl8OH1aWHePFXCoXhlT9qH+p62CP6C/pWLiKhnGGjM3+188f+Ppy1bFN3w2QQAmVgekAo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=netfilter.org; spf=pass smtp.mailfrom=netfilter.org; dkim=pass (2048-bit key) header.d=netfilter.org header.i=@netfilter.org header.b=lqPZ0Ykr; arc=none smtp.client-ip=217.70.190.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=netfilter.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=netfilter.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=netfilter.org header.i=@netfilter.org header.b="lqPZ0Ykr" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netfilter.org; s=2025; t=1788396120; bh=+Qvb7ZF0hgN+b8Z8TtazAeZH6daOLVVsMU/uL6SjuRs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lqPZ0Ykrg1UDVj9ks7VKUj056W6rCxnUYKuykOX2Gnw9FC75nVmya618/2e8Yk12G Dxe8ttpzUJKGxWj3i4xF8vFyhgs90xb5JIoFTDEGTaMSvK36etC/Hu73hysMAHbPdq 0Npsq2rjeC0KWbwSgBBAhwZXiZc1HG39UCNOKPzGpNFeQELDoJoJV/CGjBBvvU6MFt fza0FRyAbMQBDhTAyQ+5OFAkaWJWq6yIstS+r0+uJuDkfjgHtJLBq+AzYHTqp6lxj6 h+R/51kL9OjSQhk63qN8MgMwFoYqhwfcGUcbRi8JbwibYSmPHI4kMlX68klACdODqy Q/NIEKcbaO4Xw== Received: from localhost.localdomain (mail-agni [217.70.190.124]) by mail.netfilter.org (Postfix) with ESMTPSA id CEC406079C; Thu, 3 Sep 2026 02:41:59 +0200 (CEST) From: Pablo Neira Ayuso To: netfilter-devel@vger.kernel.org Cc: davem@davemloft.net, netdev@vger.kernel.org, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, horms@kernel.org, fw@strlen.de, ja@ssi.bg Subject: [PATCH net 04/12] netfilter: cttimeout: prevent UAF during module unload Date: Thu, 3 Sep 2026 02:41:41 +0200 Message-ID: <20260903004149.1037028-5-pablo@netfilter.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260903004149.1037028-1-pablo@netfilter.org> References: <20260903004149.1037028-1-pablo@netfilter.org> Precedence: bulk X-Mailing-List: netfilter-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Chengfeng Ye nf_ct_set_timeout() protects the timeout hook dereference and policy lookup with rcu_read_lock(). cttimeout_exit(), however, unregisters the per-net operations before it clears the hook. This allows the following interleaving: CPU 0 CPU 1 cttimeout_exit() nf_ct_set_timeout() unregister_pernet_subsys() rcu_read_lock() kfree(pernet) h = nf_ct_timeout_hook h->timeout_find_get() nfct_timeout_pernet() The hook still points to ctnl_timeout_find_get() when CPU 1 looks up the already freed per-net timeout list. KASAN reported: BUG: KASAN: slab-use-after-free in ctnl_timeout_find_get Read of size 8 by task poc/90 Call Trace: ctnl_timeout_find_get+0x271/0x2a0 [nfnetlink_cttimeout] nf_ct_set_timeout+0x7b/0x3c0 xt_ct_tg_check+0x724/0xb20 xt_check_target+0x234/0xa90 do_ipt_set_ctl+0x570/0x1270 Allocated by task 89: __kmalloc_noprof+0x16e/0x460 ops_init+0x6d/0x420 register_pernet_operations+0x2f6/0x670 Freed by task 91: kfree+0x131/0x390 ops_undo_list+0x3d4/0x730 unregister_pernet_operations+0x232/0x490 unregister_pernet_subsys+0x1c/0x30 cttimeout_exit+0x52/0x970 [nfnetlink_cttimeout] Clear the hook and wait for existing readers before unregistering the per-net operations. This blocks new policy lookups and ensures readers that observed the hook finish before the per-net storage is freed. Fixes: ebfbe67568a7 ("netfilter: cttimeout: use net_generic infra") Cc: stable@vger.kernel.org Signed-off-by: Chengfeng Ye Signed-off-by: Pablo Neira Ayuso --- net/netfilter/nfnetlink_cttimeout.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/netfilter/nfnetlink_cttimeout.c b/net/netfilter/nfnetlink_cttimeout.c index 66c2016f6049..132c02ac7c4e 100644 --- a/net/netfilter/nfnetlink_cttimeout.c +++ b/net/netfilter/nfnetlink_cttimeout.c @@ -652,9 +652,9 @@ static void __exit cttimeout_exit(void) { nfnetlink_subsys_unregister(&cttimeout_subsys); - unregister_pernet_subsys(&cttimeout_ops); RCU_INIT_POINTER(nf_ct_timeout_hook, NULL); synchronize_net(); + unregister_pernet_subsys(&cttimeout_ops); } module_init(cttimeout_init); -- 2.47.3