Thread (6 messages) 6 messages, 4 authors, 2021-05-31

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

From: Cong Wang <hidden>
Date: 2021-05-29 19:15:12
Also in: lkml, stable
Subsystem: filesystems (vfs and infrastructure), the rest · Maintainers: Alexander Viro, Christian Brauner, Linus Torvalds

On Fri, May 28, 2021 at 11:08 PM Changbin Du [off-list ref] wrote:
quoted hunk ↗ jump to hunk
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;
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help