From: Christian Brauner <brauner@kernel.org>
To: Jan Kara <jack@suse.cz>
Cc: linux-fsdevel@vger.kernel.org,
"Amir Goldstein" <amir73il@gmail.com>,
"Josef Bacik" <josef@toxicpanda.com>,
"Jeff Layton" <jlayton@kernel.org>, "Mike Yuan" <me@yhndnzj.com>,
"Zbigniew Jędrzejewski-Szmek" <zbyszek@in.waw.pl>,
"Lennart Poettering" <mzxreary@0pointer.de>,
"Daan De Meyer" <daan.j.demeyer@gmail.com>,
"Aleksa Sarai" <cyphar@cyphar.com>,
"Alexander Viro" <viro@zeniv.linux.org.uk>,
"Tejun Heo" <tj@kernel.org>,
"Johannes Weiner" <hannes@cmpxchg.org>,
"Michal Koutný" <mkoutny@suse.com>,
"Jakub Kicinski" <kuba@kernel.org>,
"Anna-Maria Behnsen" <anna-maria@linutronix.de>,
"Frederic Weisbecker" <frederic@kernel.org>,
"Thomas Gleixner" <tglx@linutronix.de>,
cgroups@vger.kernel.org, linux-kernel@vger.kernel.org,
netdev@vger.kernel.org
Subject: Re: [PATCH 7/9] net: centralize ns_common initialization
Date: Fri, 19 Sep 2025 10:08:33 +0200 [thread overview]
Message-ID: <20250919-fanatiker-ethik-7a9bb32ee334@brauner> (raw)
In-Reply-To: <kiyr4pnrw2a2oeoc3lavj73glvdg5llsfz2txfnn56bxmytfgw@o6weansm3iyi>
On Thu, Sep 18, 2025 at 11:42:38AM +0200, Jan Kara wrote:
> On Wed 17-09-25 12:28:06, Christian Brauner wrote:
> > Centralize ns_common initialization.
> >
> > Signed-off-by: Christian Brauner <brauner@kernel.org>
> > ---
> > net/core/net_namespace.c | 23 +++--------------------
> > 1 file changed, 3 insertions(+), 20 deletions(-)
> >
> > diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
> > index a57b3cda8dbc..897f4927df9e 100644
> > --- a/net/core/net_namespace.c
> > +++ b/net/core/net_namespace.c
> > @@ -409,7 +409,7 @@ static __net_init int preinit_net(struct net *net, struct user_namespace *user_n
> > ns_ops = NULL;
> > #endif
> >
> > - ret = ns_common_init(&net->ns, ns_ops, false);
> > + ret = ns_common_init(&net->ns, ns_ops, true);
> > if (ret)
> > return ret;
> >
> > @@ -597,6 +597,7 @@ struct net *copy_net_ns(unsigned long flags,
> > net_passive_dec(net);
> > dec_ucounts:
> > dec_net_namespaces(ucounts);
> > + ns_free_inum(&net->ns);
>
> This looks like a wrong place to put it? dec_ucounts also gets called when we
> failed to create 'net' and thus net == NULL.
>
> > return ERR_PTR(rv);
> > }
> > return net;
> > @@ -718,6 +719,7 @@ static void cleanup_net(struct work_struct *work)
> > #endif
> > put_user_ns(net->user_ns);
> > net_passive_dec(net);
> > + ns_free_inum(&net->ns);
>
> The calling of ns_free_inum() after we've dropped our reference
> (net_passive_dec()) looks suspicious. Given how 'net' freeing works I don't
> think this can lead to actual UAF issues but it is in my opinion a bad
> coding pattern and for no good reason AFAICT.
All good points. I can't say I'm fond of the complexity in this specific
instance in general.
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index 897f4927df9e..9df236811454 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -590,6 +590,7 @@ struct net *copy_net_ns(unsigned long flags,
if (rv < 0) {
put_userns:
+ ns_free_inum(&net->ns);
#ifdef CONFIG_KEYS
key_remove_domain(net->key_domain);
#endif
@@ -597,7 +598,6 @@ struct net *copy_net_ns(unsigned long flags,
net_passive_dec(net);
dec_ucounts:
dec_net_namespaces(ucounts);
- ns_free_inum(&net->ns);
return ERR_PTR(rv);
}
return net;
@@ -713,13 +713,13 @@ static void cleanup_net(struct work_struct *work)
/* Finally it is safe to free my network namespace structure */
list_for_each_entry_safe(net, tmp, &net_exit_list, exit_list) {
list_del_init(&net->exit_list);
+ ns_free_inum(&net->ns);
dec_net_namespaces(net->ucounts);
#ifdef CONFIG_KEYS
key_remove_domain(net->key_domain);
#endif
put_user_ns(net->user_ns);
net_passive_dec(net);
- ns_free_inum(&net->ns);
}
WRITE_ONCE(cleanup_net_task, NULL);
}
next prev parent reply other threads:[~2025-09-19 8:08 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-17 10:27 [PATCH 0/9] ns: rework common initialization Christian Brauner
2025-09-17 10:28 ` [PATCH 1/9] uts: split namespace into separate header Christian Brauner
2025-09-17 16:28 ` Jan Kara
2025-09-17 10:28 ` [PATCH 2/9] mnt: expose pointer to init_mnt_ns Christian Brauner
2025-09-17 16:28 ` Jan Kara
2025-09-19 10:05 ` Christian Brauner
2025-09-22 10:19 ` Jan Kara
2025-09-23 10:44 ` Christian Brauner
2025-09-17 10:28 ` [PATCH 3/9] nscommon: move to separate file Christian Brauner
2025-09-17 16:30 ` Jan Kara
2025-09-17 10:28 ` [PATCH 4/9] cgroup: split namespace into separate header Christian Brauner
2025-09-17 16:30 ` Tejun Heo
2025-09-17 16:30 ` Jan Kara
2025-09-17 10:28 ` [PATCH 5/9] nsfs: add inode number for anon namespace Christian Brauner
2025-09-17 16:31 ` Jan Kara
2025-09-17 10:28 ` [PATCH 6/9] mnt: simplify ns_common_init() handling Christian Brauner
2025-09-17 16:45 ` Jan Kara
2025-09-18 8:15 ` Christian Brauner
2025-09-18 9:12 ` Jan Kara
2025-09-17 10:28 ` [PATCH 7/9] net: centralize ns_common initialization Christian Brauner
2025-09-18 9:42 ` Jan Kara
2025-09-19 8:08 ` Christian Brauner [this message]
2025-09-22 10:19 ` Jan Kara
2025-09-17 10:28 ` [PATCH 8/9] nscommon: simplify initialization Christian Brauner
2025-09-18 9:45 ` Jan Kara
2025-09-17 10:28 ` [PATCH 9/9] ns: add ns_common_free() Christian Brauner
2025-09-18 9:11 ` Jan Kara
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=20250919-fanatiker-ethik-7a9bb32ee334@brauner \
--to=brauner@kernel.org \
--cc=amir73il@gmail.com \
--cc=anna-maria@linutronix.de \
--cc=cgroups@vger.kernel.org \
--cc=cyphar@cyphar.com \
--cc=daan.j.demeyer@gmail.com \
--cc=frederic@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=jack@suse.cz \
--cc=jlayton@kernel.org \
--cc=josef@toxicpanda.com \
--cc=kuba@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=me@yhndnzj.com \
--cc=mkoutny@suse.com \
--cc=mzxreary@0pointer.de \
--cc=netdev@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=tj@kernel.org \
--cc=viro@zeniv.linux.org.uk \
--cc=zbyszek@in.waw.pl \
/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