]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - net/socket.c
x86/speculation/mds: Conditionally clear CPU buffers on idle entry
[mirror_ubuntu-bionic-kernel.git] / net / socket.c
index 78acd6ce74c7051f260d54b62262eb32c4a97ffa..0f3ec95ce966cb74e0a50503dbd51be61a035952 100644 (file)
@@ -89,6 +89,7 @@
 #include <linux/magic.h>
 #include <linux/slab.h>
 #include <linux/xattr.h>
+#include <linux/nospec.h>
 
 #include <linux/uaccess.h>
 #include <asm/unistd.h>
@@ -436,8 +437,10 @@ static int sock_map_fd(struct socket *sock, int flags)
 {
        struct file *newfile;
        int fd = get_unused_fd_flags(flags);
-       if (unlikely(fd < 0))
+       if (unlikely(fd < 0)) {
+               sock_release(sock);
                return fd;
+       }
 
        newfile = sock_alloc_file(sock, flags, NULL);
        if (likely(!IS_ERR(newfile))) {
@@ -542,7 +545,10 @@ static int sockfs_setattr(struct dentry *dentry, struct iattr *iattr)
        if (!err && (iattr->ia_valid & ATTR_UID)) {
                struct socket *sock = SOCKET_I(d_inode(dentry));
 
-               sock->sk->sk_uid = iattr->ia_uid;
+               if (sock->sk)
+                       sock->sk->sk_uid = iattr->ia_uid;
+               else
+                       err = -ENOENT;
        }
 
        return err;
@@ -592,12 +598,17 @@ EXPORT_SYMBOL(sock_alloc);
  *     an inode not a file.
  */
 
-void sock_release(struct socket *sock)
+static void __sock_release(struct socket *sock, struct inode *inode)
 {
        if (sock->ops) {
                struct module *owner = sock->ops->owner;
 
+               if (inode)
+                       inode_lock(inode);
                sock->ops->release(sock);
+               sock->sk = NULL;
+               if (inode)
+                       inode_unlock(inode);
                sock->ops = NULL;
                module_put(owner);
        }
@@ -612,6 +623,11 @@ void sock_release(struct socket *sock)
        }
        sock->file = NULL;
 }
+
+void sock_release(struct socket *sock)
+{
+       __sock_release(sock, NULL);
+}
 EXPORT_SYMBOL(sock_release);
 
 void __sock_tx_timestamp(__u16 tsflags, __u8 *tx_flags)
@@ -1126,7 +1142,7 @@ static int sock_mmap(struct file *file, struct vm_area_struct *vma)
 
 static int sock_close(struct inode *inode, struct file *filp)
 {
-       sock_release(SOCKET_I(inode));
+       __sock_release(SOCKET_I(inode), inode);
        return 0;
 }
 
@@ -2409,6 +2425,7 @@ SYSCALL_DEFINE2(socketcall, int, call, unsigned long __user *, args)
 
        if (call < 1 || call > SYS_SENDMMSG)
                return -EINVAL;
+       call = array_index_nospec(call, SYS_SENDMMSG + 1);
 
        len = nargs[call];
        if (len > sizeof(a))