From: Jiayuan Chen <jiayuan.chen@linux.dev>
To: netdev@vger.kernel.org
Cc: Jiayuan Chen <jiayuan.chen@linux.dev>,
syzbot+d3f912a2e30e2079a512@syzkaller.appspotmail.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>,
Christian Brauner <brauner@kernel.org>,
Kuniyuki Iwashima <kuniyu@google.com>, Jan Kara <jack@suse.cz>,
Qiliang Yuan <realwujing@gmail.com>,
Jeff Layton <jlayton@kernel.org>,
linux-kernel@vger.kernel.org
Subject: [PATCH net] net: fix refcnt_tracker use-after-free on netns creation failure
Date: Thu, 27 Aug 2026 13:22:16 +0800 [thread overview]
Message-ID: <20260827052219.290380-1-jiayuan.chen@linux.dev> (raw)
The copy_net_ns() error path tears the net down via net_passive_dec(),
which only exits notrefcnt_tracker. refcnt_tracker is exited in
__put_net(), which this path never reaches, so it is left alive.
Since ref_tracker_dir_init() started registering a debugfs file per
dir, that file must be dropped by ref_tracker_dir_exit(). The missing
exit leaves the file pointing at the freed net, so reading it walks
net->refcnt_tracker.lock and hits a use-after-free.
The missing exit has been there all along, but before the debugfs file
refcnt_tracker was just an in-memory ledger and empty on this path, so
skipping it leaked nothing and did no harm. Only the commit below, which
gives every dir a debugfs file, turned it into a use-after-free, so
Fixes points there.
Exit refcnt_tracker on the failure path.
Fixes: 65b584f53611 ("ref_tracker: automatically register a file in debugfs for a ref_tracker_dir")
Reported-by: syzbot+d3f912a2e30e2079a512@syzkaller.appspotmail.com
Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
---
net/core/net_namespace.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index a91d2b58aadd..0c3f169d9afb 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -591,6 +591,10 @@ struct net *copy_net_ns(u64 flags,
key_remove_domain(net->key_domain);
#endif
put_user_ns(user_ns);
+ /* setup_net() failure is not routed through __put_net(), so the
+ * refcnt_tracker (and its debugfs file) has to be released here.
+ */
+ ref_tracker_dir_exit(&net->refcnt_tracker);
net_passive_dec(net);
dec_ucounts:
dec_net_namespaces(ucounts);
--
2.43.0
next reply other threads:[~2026-08-27 5:22 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-27 5:22 Jiayuan Chen [this message]
2026-08-27 6:56 ` [PATCH net] net: fix refcnt_tracker use-after-free on netns creation failure Eric Dumazet
2026-08-27 7:05 ` Jiayuan Chen
2026-08-27 7:06 ` Jiayuan Chen
2026-08-30 10:57 ` Tetsuo Handa
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=20260827052219.290380-1-jiayuan.chen@linux.dev \
--to=jiayuan.chen@linux.dev \
--cc=brauner@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=jack@suse.cz \
--cc=jlayton@kernel.org \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=realwujing@gmail.com \
--cc=syzbot+d3f912a2e30e2079a512@syzkaller.appspotmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.