From: Minhong He <heminhong@kylinos.cn>
To: Paul Moore <paul@paul-moore.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>,
netdev@vger.kernel.org
Cc: linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH net v2] netlabel: check register_netdevice_notifier() error in netlbl_unlabel_init()
Date: Wed, 29 Jul 2026 17:07:16 +0800 [thread overview]
Message-ID: <20260729090716.138608-1-heminhong@kylinos.cn> (raw)
netlbl_unlabel_init() installs the unlabeled connection hash table and
registers a netdevice notifier, but ignores notifier registration errors
and always returns success.
Check the error and unwind the hash table allocation on failure.
Signed-off-by: Minhong He <heminhong@kylinos.cn>
Acked-by: Paul Moore <paul@paul-moore.com>
---
v2:
- Use rcu_assign_pointer() instead of RCU_INIT_POINTER() when clearing
netlbl_unlhsh on notifier registration failure, as suggested by Paul Moore
v1: https://lore.kernel.org/all/20260728031043.76586-1-heminhong@kylinos.cn/
net/netlabel/netlabel_unlabeled.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/net/netlabel/netlabel_unlabeled.c b/net/netlabel/netlabel_unlabeled.c
index 47bae5e48db6..fe1be424601f 100644
--- a/net/netlabel/netlabel_unlabeled.c
+++ b/net/netlabel/netlabel_unlabeled.c
@@ -1397,6 +1397,7 @@ static struct notifier_block netlbl_unlhsh_netdev_notifier = {
*/
int __init netlbl_unlabel_init(u32 size)
{
+ int err;
u32 iter;
struct netlbl_unlhsh_tbl *hsh_tbl;
@@ -1419,7 +1420,16 @@ int __init netlbl_unlabel_init(u32 size)
rcu_assign_pointer(netlbl_unlhsh, hsh_tbl);
spin_unlock(&netlbl_unlhsh_lock);
- register_netdevice_notifier(&netlbl_unlhsh_netdev_notifier);
+ err = register_netdevice_notifier(&netlbl_unlhsh_netdev_notifier);
+ if (err) {
+ spin_lock(&netlbl_unlhsh_lock);
+ rcu_assign_pointer(netlbl_unlhsh, NULL);
+ spin_unlock(&netlbl_unlhsh_lock);
+ synchronize_rcu();
+ kfree(hsh_tbl->tbl);
+ kfree(hsh_tbl);
+ return err;
+ }
return 0;
}
--
2.25.1
next reply other threads:[~2026-07-29 9:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-29 9:07 Minhong He [this message]
2026-08-03 23:32 ` [PATCH net v2] netlabel: check register_netdevice_notifier() error in netlbl_unlabel_init() Jakub Kicinski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260729090716.138608-1-heminhong@kylinos.cn \
--to=heminhong@kylinos.cn \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=paul@paul-moore.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox