lkml.org 
[lkml]   [2021]   [May]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Date
SubjectRe: [PATCH] net: fix oops in socket ioctl cmd SIOCGSKNS when NET_NS is disabled
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.

Something like this:

diff --git a/fs/nsfs.c b/fs/nsfs.c
index 800c1d0eb0d0..d63414604e99 100644
--- a/fs/nsfs.c
+++ b/fs/nsfs.c
@@ -152,6 +152,9 @@ int open_related_ns(struct ns_common *ns,
int err;
int fd;

+ if (!ns->ops)
+ return -EOPNOTSUPP;
+
fd = get_unused_fd_flags(O_CLOEXEC);
if (fd < 0)
return fd;
\
 
 \ /
  Last update: 2021-05-29 21:16    [W:0.061 / U:0.072 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site