From: Changbin Du <changbin.du@gmail.com>
To: David Laight <David.Laight@ACULAB.COM>
Cc: 'Cong Wang' <xiyou.wangcong@gmail.com>,
Changbin Du <changbin.du@gmail.com>,
"David S. Miller" <davem@davemloft.net>,
Jakub Kici nski <kuba@kernel.org>,
Linux Kernel Network Developers <netdev@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
stable <stable@vger.kernel.org>
Subject: Re: [PATCH] net: fix oops in socket ioctl cmd SIOCGSKNS when NET_NS is disabled
Date: Mon, 31 May 2021 23:31:00 +0800 [thread overview]
Message-ID: <20210531153100.pfwlrkrqdisp6heu@mail.google.com> (raw)
In-Reply-To: <55effe20acc54ea4a96ea86015d99a5b@AcuMS.aculab.com>
On Mon, May 31, 2021 at 08:30:58AM +0000, David Laight wrote:
> From: Cong Wang
> > Sent: 29 May 2021 20:15
> >
> > On Fri, May 28, 2021 at 11:08 PM Changbin Du <changbin.du@gmail.com> wrote:
> > > diff --git a/net/socket.c b/net/socket.c
> > > index 27e3e7d53f8e..644b46112d35 100644
> > > --- a/net/socket.c
> > > +++ b/net/socket.c
> > > @@ -1149,11 +1149,15 @@ static long sock_ioctl(struct file *file, unsigned cmd, unsigned long arg)
> > > mutex_unlock(&vlan_ioctl_mutex);
> > > break;
> > > case SIOCGSKNS:
> > > +#ifdef CONFIG_NET_NS
> > > err = -EPERM;
> > > if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
> > > break;
> > >
> > > err = open_related_ns(&net->ns, get_net_ns);
> > > +#else
> > > + err = -ENOTSUPP;
> > > +#endif
> >
> > I wonder if it is easier if we just reject ns->ops==NULL case
> > in open_related_ns(). For 1) we can save an ugly #ifdef here;
> > 2) drivers/net/tun.c has the same bugs.
>
> If CONFIG_NET_NS is unset then why not make both ns_capable()
> and open_related_ns() unconditionally return -ENOTSUPP?
>
Here is the new fix that reject creating indoe for disabled ns.
--- a/fs/nsfs.c
+++ b/fs/nsfs.c
@@ -62,6 +62,10 @@ static int __ns_get_path(struct path *path, struct ns_common *ns)
struct inode *inode;
unsigned long d;
+ /* In case the namespace is not actually enabled. */
+ if (!ns->ops)
+ return -EOPNOTSUPP;
> David
>
> -
> Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> Registration No: 1397386 (Wales)
--
Cheers,
Changbin Du
prev parent reply other threads:[~2021-05-31 17:18 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-29 6:05 Changbin Du
2021-05-29 18:27 ` Jakub Kicinski
2021-05-31 15:28 ` Changbin Du
2021-05-29 19:14 ` Cong Wang
2021-05-31 8:30 ` David Laight
2021-05-31 15:31 ` Changbin Du [this message]
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=20210531153100.pfwlrkrqdisp6heu@mail.google.com \
--to=changbin.du@gmail.com \
--cc=David.Laight@ACULAB.COM \
--cc=davem@davemloft.net \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=xiyou.wangcong@gmail.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
all inboxes | Powered by JetHome®