From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yx1-f43.google.com (mail-yx1-f43.google.com [74.125.224.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD7D6369D57 for ; Sun, 23 Aug 2026 17:05:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787504762; cv=none; b=YQU4CyoKnZaP+kP0z6egPJeP/vlWLMCZ1Ie1QxqAlUSvXunvsvWTxBVkKC2fyfMNcyeJpd81C+cffl+7pmYNjWlWgsej4vaW+5PH8ZcpRZiiM83M2HZne1pW8eyLgPK+qxTadI+EF/5A7/TuHNGZJDtXUkqyR8wqUO2sB+/QQ/Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787504762; c=relaxed/simple; bh=MOSoskfPWCJYTRcElhbU7017zaNB/Jrp/HctCMM0yCU=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=kq721No4uHcvEZjvBs0u2WYUWis2V/5W4i1t/yQ9umb8JWC1F/Cl73JWzTnCRGr9PAWghCoeu+3BcISsXJVw9YEcnJRQyrauJptmvlxIJKxQYVqKOsu0a4ZPIZLtQG88dCgwsh7Kt/ljIcGqt5bBZ6jt/BFympbdeyMjpupBphs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=jfE6OZiZ; arc=none smtp.client-ip=74.125.224.43 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.b="jfE6OZiZ" Received: by mail-yx1-f43.google.com with SMTP id 956f58d0204a3-66c70cbd49aso308181d50.0 for ; Sun, 23 Aug 2026 10:05:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787504754; x=1788109554; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=esjqTaDB5DT6wtV4Y9AzgjqpTCrwMQJOjGYCKVsLIlo=; b=jfE6OZiZqfBaNW0nhyP/lZjc7Vog5R1/gxYLbRc13QdcVBI7eds/P9Pb5JpKM0zngZ /3frcuK4JN0d1jA+BOqHB7fcUqsGngxxSre8z5e6OjZyydlAWnE4E2ygbVYSnAnYUKOn S8Ft960HzFsHi64gLVrXkpGWcN6osyWlz2g5E3WmgvVwVeEilwBaXJtSCDpTIm2wp1H0 J8z7KF90hfu7q9M3M/v5zu4UzYivx8f/CMp8sB7jUGDCSxabchvfkpTyUZOOLUbRaQ69 FRs7kOiAyZWpmY40cE2ybtpDJ8oJLma6BKZucmO/wozU2lEQoQXQw4ZajemHcbuNHUEL 5wig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787504754; x=1788109554; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=esjqTaDB5DT6wtV4Y9AzgjqpTCrwMQJOjGYCKVsLIlo=; b=XQaNcDP6r5cOY9qmW9QssqtGVQM5Bgp42Z+F3JbtJcO1MJe3I4zs0vvF4TMBrJHO86 XLX7qzj9WqQhTTy84QofT+CEVxX2UooLixkUC5HhVr8tCPUDDsj7xzRbZ5cgtyD6rBfv JNIr5h6jIZc2IBkiD3lxPhjCtQbgyKQt7sfXaReWsda8sa5FfOp3MUaFxh/Vo1Tcld1T Lssu7/B1y9Lyxscd4gVHVZwkNuXhiJnS1UHelI2ksxJu9KhwfdDhPVstGBx6Y7nans80 GQgJrp9Gqf3IpU2oCHEGCUCEC23ylENUxWvAdgV6Yhk8gqbocOLzi53/mrUBCWpjgwYb NHyg== X-Forwarded-Encrypted: i=1; AHgh+Ro/D5mWXcgyJAVPcDzZVx8OTfm98ydrMKKbSUd0c4ZPsE02tbfz6EI7xOBgKnwdMP+5tOYY9ruVSAE2qNE=@vger.kernel.org X-Gm-Message-State: AFuF++nxMb8BpFXQ9hOPcwp4puF8sVCfM6aMv/fBmJc0lKBpmZ2erczU 5vOGb/8CvP1WfX6JRmW7hGUtNbn0j/qjTtHw33ccNrX/TL2c+muAJJQS X-Gm-Gg: AR+sD10KZIOSXlFrIzInHvgjdwzs5zTvwDnur9j/Gz7qzqGhzffh8kxxPcKO6c+s1KC 82tFoEpxDMUZvjOgKEGm/5fxyO58i34pW49zKLmmMZe4esK/H3qOYcKX374ZE0cD8ngFp8Hg9pm WJWsLGRYOKeQGRs1su962NRpzC5MujwqCmdK78OGcquUJH01/E5j6SfUCVRYPf7hNRBQ7HMBCKd +n32I/djecdNrFdTarOcVbcz28JA3fDYChK03YjzMvRC+LhdJwg6JIn9gVHUe5ciU8m1OC5JxCM 9cZpYaurH2QA1cQwK+fTmSiJ2kTZq7BgI1dHKBuHPmMCJpU0er86GzwaWiCXvZ/Yx/NNepByC+h 6E+qBDoP+jFeZ8+Bz0t66M3YzBo187T/dDcanoGF6UDi1sUVKuAr2TSc24muOzc0IMavtqGpA9i LTXYw4+KpJM+Y7v7tZlueAjFlvW0AwtpmaSZQgbYp7GW09X/JkYgYpZTTOI7lhYmfZdiikNB10u Q+UL+iEbmLERQK3EdaDUKtfFTXL7oJYfGG5pwUNh7zQAqEcRczfr98= X-Received: by 2002:a05:690e:4849:b0:668:99ce:a033 with SMTP id 956f58d0204a3-66ce4a9b51fmr4978933d50.2.1787504753689; Sun, 23 Aug 2026 10:05:53 -0700 (PDT) Received: from localhost.localdomain (45.78.65.84.16clouds.com. [45.78.65.84]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-66cf4a2c3c2sm2333298d50.17.2026.08.23.10.05.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Aug 2026 10:05:52 -0700 (PDT) From: Chengfeng Ye To: Pablo Neira Ayuso , Florian Westphal Cc: Phil Sutter , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Gao feng , netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Chengfeng Ye , stable@vger.kernel.org Subject: [PATCH net v2] netfilter: nf_log: unregister loggers before per-net teardown Date: Mon, 24 Aug 2026 01:05:38 +0800 Message-ID: <20260823170538.3856770-1-nicoyip.dev@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit nf_log_syslog and nfnetlink_log unregister their per-network namespace operations before unregistering their global logger backends. This leaves a window where a sysctl or netlink writer can rebind the still- registered logger after the per-net pre-exit callback cleared the old selection. The race looks like this: CPU 0 CPU 1 ---- ---- unregister_pernet_subsys() nf_log_unset(net, logger) net->nf.nf_loggers[pf] = NULL lock nf_log_mutex find logger in loggers[][] net->nf.nf_loggers[pf] = logger unlock nf_log_mutex nf_log_unregister(logger) lock nf_log_mutex loggers[pf][type] = NULL unlock nf_log_mutex synchronize_rcu() module exit returns module core frees backend memory Later, a sysctl read or packet logging operation can dereference the stale per-net logger pointer. Fix this by unregistering the global logger backends before tearing down per-net state. Once the global registrations are gone, later writers can no longer rebind the logger. unregister_pernet_subsys() already waits for an RCU grace period after the pre-exit callback clears the per-net selection, while nf_log_unregister() continues to cover readers of the global logger table. Apply this ordering fix to both nf_log backends that combine per-net teardown with global logger registration. Fixes: 5b023fc8d8e0 ("netfilter: enable per netns support for nf_loggers") Cc: stable@vger.kernel.org Signed-off-by: Chengfeng Ye --- Changes in v2: - Rework the fix around backend teardown ordering instead of clearing per-net bindings from nf_log_unregister(). - Apply the ordering fix to both nf_log_syslog and nfnetlink_log. - Drop the redundant trailing synchronize_rcu(). Link: https://lore.kernel.org/netdev/20260822184658.3787672-1-nicoyip.dev@gmail.com/ [v1] --- net/netfilter/nf_log_syslog.c | 2 +- net/netfilter/nfnetlink_log.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/net/netfilter/nf_log_syslog.c b/net/netfilter/nf_log_syslog.c --- a/net/netfilter/nf_log_syslog.c +++ b/net/netfilter/nf_log_syslog.c @@ -1073,12 +1073,12 @@ static void __exit nf_log_syslog_exit(void) { - unregister_pernet_subsys(&nf_log_syslog_net_ops); nf_log_unregister(&nf_ip_logger); nf_log_unregister(&nf_arp_logger); nf_log_unregister(&nf_ip6_logger); nf_log_unregister(&nf_netdev_logger); nf_log_unregister(&nf_bridge_logger); + unregister_pernet_subsys(&nf_log_syslog_net_ops); } module_init(nf_log_syslog_init); diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c --- a/net/netfilter/nfnetlink_log.c +++ b/net/netfilter/nfnetlink_log.c @@ -1233,8 +1233,8 @@ { nfnetlink_subsys_unregister(&nfulnl_subsys); netlink_unregister_notifier(&nfulnl_rtnl_notifier); - unregister_pernet_subsys(&nfnl_log_net_ops); nf_log_unregister(&nfulnl_logger); + unregister_pernet_subsys(&nfnl_log_net_ops); } MODULE_DESCRIPTION("netfilter userspace logging"); -- 2.43.0