[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20210531153100.pfwlrkrqdisp6heu@mail.google.com>
Date: Mon, 31 May 2021 23:31:00 +0800
From: Changbin Du <changbin.du@...il.com>
To: David Laight <David.Laight@...LAB.COM>
Cc: 'Cong Wang' <xiyou.wangcong@...il.com>,
Changbin Du <changbin.du@...il.com>,
"David S. Miller" <davem@...emloft.net>,
Jakub Kici nski <kuba@...nel.org>,
Linux Kernel Network Developers <netdev@...r.kernel.org>,
LKML <linux-kernel@...r.kernel.org>,
stable <stable@...r.kernel.org>
Subject: Re: [PATCH] net: fix oops in socket ioctl cmd SIOCGSKNS when NET_NS
is disabled
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@...il.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
Powered by blists - more mailing lists