]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blobdiff - net/socket.c
tuntap: add sanity checks about msg_controllen in sendmsg
[mirror_ubuntu-focal-kernel.git] / net / socket.c
index 432800b39ddb9ea8763432506c3f5f191b9ef059..94358566c9d10b564e94455ef7320ba9752e63ae 100644 (file)
@@ -485,7 +485,7 @@ static struct socket *sockfd_lookup_light(int fd, int *err, int *fput_needed)
        if (f.file) {
                sock = sock_from_file(f.file, err);
                if (likely(sock)) {
-                       *fput_needed = f.flags;
+                       *fput_needed = f.flags & FDPUT_FPUT;
                        return sock;
                }
                fdput(f);
@@ -1053,7 +1053,7 @@ static long sock_do_ioctl(struct net *net, struct socket *sock,
                rtnl_unlock();
                if (!err && copy_to_user(argp, &ifc, sizeof(struct ifconf)))
                        err = -EFAULT;
-       } else {
+       } else if (is_socket_ioctl_cmd(cmd)) {
                struct ifreq ifr;
                bool need_copyout;
                if (copy_from_user(&ifr, argp, sizeof(struct ifreq)))
@@ -1062,6 +1062,8 @@ static long sock_do_ioctl(struct net *net, struct socket *sock,
                if (!err && need_copyout)
                        if (copy_to_user(argp, &ifr, sizeof(struct ifreq)))
                                return -EFAULT;
+       } else {
+               err = -ENOTTY;
        }
        return err;
 }
@@ -1071,19 +1073,6 @@ static long sock_do_ioctl(struct net *net, struct socket *sock,
  *     what to do with it - that's up to the protocol still.
  */
 
-/**
- *     get_net_ns - increment the refcount of the network namespace
- *     @ns: common namespace (net)
- *
- *     Returns the net's common namespace.
- */
-
-struct ns_common *get_net_ns(struct ns_common *ns)
-{
-       return &get_net(container_of(ns, struct net, ns))->ns;
-}
-EXPORT_SYMBOL_GPL(get_net_ns);
-
 static long sock_ioctl(struct file *file, unsigned cmd, unsigned long arg)
 {
        struct socket *sock;
@@ -3241,6 +3230,8 @@ static int compat_ifr_data_ioctl(struct net *net, unsigned int cmd,
        struct ifreq ifreq;
        u32 data32;
 
+       if (!is_socket_ioctl_cmd(cmd))
+               return -ENOTTY;
        if (copy_from_user(ifreq.ifr_name, u_ifreq32->ifr_name, IFNAMSIZ))
                return -EFAULT;
        if (get_user(data32, &u_ifreq32->ifr_data))