Re: [PATCH] net: fix oops in socket ioctl cmd SIOCGSKNS when NET_NS is disabled

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, May 28, 2021 at 11:08 PM Changbin Du <changbin.du@xxxxxxxxx> 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;



[Index of Archives]     [Linux Kernel]     [Kernel Development Newbies]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux