Merge branch 'work.misc' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
authorLinus Torvalds <torvalds@linux-foundation.org>
Wed, 31 Jan 2018 17:25:20 +0000 (09:25 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 31 Jan 2018 17:25:20 +0000 (09:25 -0800)
Pull misc vfs updates from Al Viro:
 "All kinds of misc stuff, without any unifying topic, from various
  people.

  Neil's d_anon patch, several bugfixes, introduction of kvmalloc
  analogue of kmemdup_user(), extending bitfield.h to deal with
  fixed-endians, assorted cleanups all over the place..."

* 'work.misc' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: (28 commits)
  alpha: osf_sys.c: use timespec64 where appropriate
  alpha: osf_sys.c: fix put_tv32 regression
  jffs2: Fix use-after-free bug in jffs2_iget()'s error handling path
  dcache: delete unused d_hash_mask
  dcache: subtract d_hash_shift from 32 in advance
  fs/buffer.c: fold init_buffer() into init_page_buffers()
  fs: fold __inode_permission() into inode_permission()
  fs: add RWF_APPEND
  sctp: use vmemdup_user() rather than badly open-coding memdup_user()
  snd_ctl_elem_init_enum_names(): switch to vmemdup_user()
  replace_user_tlv(): switch to vmemdup_user()
  new primitive: vmemdup_user()
  memdup_user(): switch to GFP_USER
  eventfd: fold eventfd_ctx_get() into eventfd_ctx_fileget()
  eventfd: fold eventfd_ctx_read() into eventfd_read()
  eventfd: convert to use anon_inode_getfd()
  nfs4file: get rid of pointless include of btrfs.h
  uvc_v4l2: clean copyin/copyout up
  vme_user: don't use __copy_..._user()
  usx2y: don't bother with memdup_user() for 16-byte structure
  ...

15 files changed:
1  2 
drivers/media/usb/uvc/uvc_v4l2.c
fs/buffer.c
fs/dcache.c
fs/eventfd.c
fs/file.c
fs/jffs2/fs.c
fs/namei.c
fs/super.c
include/linux/fs.h
include/linux/string.h
net/sctp/socket.c
sound/core/control.c
sound/core/hwdep.c
sound/usb/usx2y/us122l.c
sound/usb/usx2y/usX2Yhwdep.c

index ed3bf05e2462f67cbc25eeb453f510e81b45be34,329a967382ddd66ff33deca79bd168921e1b7247..381f614b2f4cfcbea7c5672df976f4efbe22673b
@@@ -1284,36 -1284,30 +1284,30 @@@ struct uvc_xu_control_mapping32 
  static int uvc_v4l2_get_xu_mapping(struct uvc_xu_control_mapping *kp,
                        const struct uvc_xu_control_mapping32 __user *up)
  {
-       compat_caddr_t p;
+       struct uvc_xu_control_mapping32 *p = (void *)kp;
+       compat_caddr_t info;
+       u32 count;
  
-       if (!access_ok(VERIFY_READ, up, sizeof(*up)) ||
-           __copy_from_user(kp, up, offsetof(typeof(*up), menu_info)) ||
-           __get_user(kp->menu_count, &up->menu_count))
+       if (copy_from_user(p, up, sizeof(*p)))
                return -EFAULT;
  
-       memset(kp->reserved, 0, sizeof(kp->reserved));
-       if (kp->menu_count == 0) {
-               kp->menu_info = NULL;
-               return 0;
-       }
-       if (__get_user(p, &up->menu_info))
-               return -EFAULT;
-       kp->menu_info = compat_ptr(p);
+       count = p->menu_count;
+       info = p->menu_info;
  
+       memset(kp->reserved, 0, sizeof(kp->reserved));
+       kp->menu_info = count ? compat_ptr(info) : NULL;
+       kp->menu_count = count;
        return 0;
  }
  
  static int uvc_v4l2_put_xu_mapping(const struct uvc_xu_control_mapping *kp,
                        struct uvc_xu_control_mapping32 __user *up)
  {
-       if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) ||
-           __copy_to_user(up, kp, offsetof(typeof(*up), menu_info)) ||
-           __put_user(kp->menu_count, &up->menu_count))
+       if (copy_to_user(up, kp, offsetof(typeof(*up), menu_info)) ||
+           put_user(kp->menu_count, &up->menu_count))
                return -EFAULT;
  
-       if (__clear_user(up->reserved, sizeof(up->reserved)))
+       if (clear_user(up->reserved, sizeof(up->reserved)))
                return -EFAULT;
  
        return 0;
@@@ -1330,31 -1324,26 +1324,26 @@@ struct uvc_xu_control_query32 
  static int uvc_v4l2_get_xu_query(struct uvc_xu_control_query *kp,
                        const struct uvc_xu_control_query32 __user *up)
  {
-       compat_caddr_t p;
+       struct uvc_xu_control_query32 v;
  
-       if (!access_ok(VERIFY_READ, up, sizeof(*up)) ||
-           __copy_from_user(kp, up, offsetof(typeof(*up), data)))
+       if (copy_from_user(&v, up, sizeof(v)))
                return -EFAULT;
  
-       if (kp->size == 0) {
-               kp->data = NULL;
-               return 0;
-       }
-       if (__get_user(p, &up->data))
-               return -EFAULT;
-       kp->data = compat_ptr(p);
+       *kp = (struct uvc_xu_control_query){
+               .unit = v.unit,
+               .selector = v.selector,
+               .query = v.query,
+               .size = v.size,
+               .data = v.size ? compat_ptr(v.data) : NULL
+       };
        return 0;
  }
  
  static int uvc_v4l2_put_xu_query(const struct uvc_xu_control_query *kp,
                        struct uvc_xu_control_query32 __user *up)
  {
-       if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) ||
-           __copy_to_user(up, kp, offsetof(typeof(*up), data)))
+       if (copy_to_user(up, kp, offsetof(typeof(*up), data)))
                return -EFAULT;
        return 0;
  }
  
@@@ -1423,7 -1412,7 +1412,7 @@@ static int uvc_v4l2_mmap(struct file *f
        return uvc_queue_mmap(&stream->queue, vma);
  }
  
 -static unsigned int uvc_v4l2_poll(struct file *file, poll_table *wait)
 +static __poll_t uvc_v4l2_poll(struct file *file, poll_table *wait)
  {
        struct uvc_fh *handle = file->private_data;
        struct uvc_streaming *stream = handle->stream;
diff --combined fs/buffer.c
index 8b26295a56fe4ecade9206b443c6a5f8c2c6c64e,3091801169ce5143c6d9d9546e136c79f44d9243..9a73924db22f988df19662e45d534950a4c174f4
@@@ -53,13 -53,6 +53,6 @@@ static int submit_bh_wbc(int op, int op
  
  #define BH_ENTRY(list) list_entry((list), struct buffer_head, b_assoc_buffers)
  
- void init_buffer(struct buffer_head *bh, bh_end_io_t *handler, void *private)
- {
-       bh->b_end_io = handler;
-       bh->b_private = private;
- }
- EXPORT_SYMBOL(init_buffer);
  inline void touch_buffer(struct buffer_head *bh)
  {
        trace_block_touch_buffer(bh);
@@@ -922,7 -915,8 +915,8 @@@ init_page_buffers(struct page *page, st
  
        do {
                if (!buffer_mapped(bh)) {
-                       init_buffer(bh, NULL, NULL);
+                       bh->b_end_io = NULL;
+                       bh->b_private = NULL;
                        bh->b_bdev = bdev;
                        bh->b_blocknr = block;
                        if (uptodate)
@@@ -3014,7 -3008,7 +3008,7 @@@ static void end_bio_bh_io_sync(struct b
  void guard_bio_eod(int op, struct bio *bio)
  {
        sector_t maxsector;
 -      struct bio_vec *bvec = &bio->bi_io_vec[bio->bi_vcnt - 1];
 +      struct bio_vec *bvec = bio_last_bvec_all(bio);
        unsigned truncated_bytes;
        struct hd_struct *part;
  
diff --combined fs/dcache.c
index 379dce86f0014d8fedefc1f00008a5d915c64f1b,f110e9eebb58d31ef975f41cde3ed928fb189456..c6d996ee2d61922ba5aaf13440e67d40dddcd0e6
@@@ -32,7 -32,6 +32,6 @@@
  #include <linux/swap.h>
  #include <linux/bootmem.h>
  #include <linux/fs_struct.h>
- #include <linux/hardirq.h>
  #include <linux/bit_spinlock.h>
  #include <linux/rculist_bl.h>
  #include <linux/prefetch.h>
@@@ -49,8 -48,8 +48,8 @@@
   *   - i_dentry, d_u.d_alias, d_inode of aliases
   * dcache_hash_bucket lock protects:
   *   - the dcache hash table
-  * s_anon bl list spinlock protects:
-  *   - the s_anon list (see __d_drop)
+  * s_roots bl list spinlock protects:
+  *   - the s_roots list (see __d_drop)
   * dentry->d_sb->s_dentry_lru_lock protects:
   *   - the dcache lru lists and counters
   * d_lock protects:
@@@ -68,7 -67,7 +67,7 @@@
   *   dentry->d_lock
   *     dentry->d_sb->s_dentry_lru_lock
   *     dcache_hash_bucket lock
-  *     s_anon lock
+  *     s_roots lock
   *
   * If there is an ancestor relationship:
   * dentry->d_parent->...->d_parent->d_lock
@@@ -104,14 -103,13 +103,13 @@@ EXPORT_SYMBOL(slash_name)
   * information, yet avoid using a prime hash-size or similar.
   */
  
- static unsigned int d_hash_mask __read_mostly;
  static unsigned int d_hash_shift __read_mostly;
  
  static struct hlist_bl_head *dentry_hashtable __read_mostly;
  
  static inline struct hlist_bl_head *d_hash(unsigned int hash)
  {
-       return dentry_hashtable + (hash >> (32 - d_hash_shift));
+       return dentry_hashtable + (hash >> d_hash_shift);
  }
  
  #define IN_LOOKUP_SHIFT 10
@@@ -477,10 -475,10 +475,10 @@@ void __d_drop(struct dentry *dentry
                /*
                 * Hashed dentries are normally on the dentry hashtable,
                 * with the exception of those newly allocated by
-                * d_obtain_alias, which are always IS_ROOT:
+                * d_obtain_root, which are always IS_ROOT:
                 */
                if (unlikely(IS_ROOT(dentry)))
-                       b = &dentry->d_sb->s_anon;
+                       b = &dentry->d_sb->s_roots;
                else
                        b = d_hash(dentry->d_name.hash);
  
@@@ -1500,8 -1498,8 +1498,8 @@@ void shrink_dcache_for_umount(struct su
        sb->s_root = NULL;
        do_one_tree(dentry);
  
-       while (!hlist_bl_empty(&sb->s_anon)) {
-               dentry = dget(hlist_bl_entry(hlist_bl_first(&sb->s_anon), struct dentry, d_hash));
+       while (!hlist_bl_empty(&sb->s_roots)) {
+               dentry = dget(hlist_bl_entry(hlist_bl_first(&sb->s_roots), struct dentry, d_hash));
                do_one_tree(dentry);
        }
  }
@@@ -1636,7 -1634,8 +1634,7 @@@ struct dentry *__d_alloc(struct super_b
        dname[name->len] = 0;
  
        /* Make sure we always see the terminating NUL character */
 -      smp_wmb();
 -      dentry->d_name.name = dname;
 +      smp_store_release(&dentry->d_name.name, dname); /* ^^^ */
  
        dentry->d_lockref.count = 1;
        dentry->d_flags = 0;
@@@ -1964,9 -1963,11 +1962,11 @@@ static struct dentry *__d_obtain_alias(
        spin_lock(&tmp->d_lock);
        __d_set_inode_and_type(tmp, inode, add_flags);
        hlist_add_head(&tmp->d_u.d_alias, &inode->i_dentry);
-       hlist_bl_lock(&tmp->d_sb->s_anon);
-       hlist_bl_add_head(&tmp->d_hash, &tmp->d_sb->s_anon);
-       hlist_bl_unlock(&tmp->d_sb->s_anon);
+       if (!disconnected) {
+               hlist_bl_lock(&tmp->d_sb->s_roots);
+               hlist_bl_add_head(&tmp->d_hash, &tmp->d_sb->s_roots);
+               hlist_bl_unlock(&tmp->d_sb->s_roots);
+       }
        spin_unlock(&tmp->d_lock);
        spin_unlock(&inode->i_lock);
  
@@@ -3046,14 -3047,17 +3046,14 @@@ static int prepend(char **buffer, int *
   * retry it again when a d_move() does happen. So any garbage in the buffer
   * due to mismatched pointer and length will be discarded.
   *
 - * Data dependency barrier is needed to make sure that we see that terminating
 - * NUL.  Alpha strikes again, film at 11...
 + * Load acquire is needed to make sure that we see that terminating NUL.
   */
  static int prepend_name(char **buffer, int *buflen, const struct qstr *name)
  {
 -      const char *dname = READ_ONCE(name->name);
 +      const char *dname = smp_load_acquire(&name->name); /* ^^^ */
        u32 dlen = READ_ONCE(name->len);
        char *p;
  
 -      smp_read_barrier_depends();
 -
        *buflen -= dlen + 1;
        if (*buflen < 0)
                return -ENAMETOOLONG;
@@@ -3585,9 -3589,10 +3585,10 @@@ static void __init dcache_init_early(vo
                                        13,
                                        HASH_EARLY | HASH_ZERO,
                                        &d_hash_shift,
-                                       &d_hash_mask,
+                                       NULL,
                                        0,
                                        0);
+       d_hash_shift = 32 - d_hash_shift;
  }
  
  static void __init dcache_init(void)
                                        13,
                                        HASH_ZERO,
                                        &d_hash_shift,
-                                       &d_hash_mask,
+                                       NULL,
                                        0,
                                        0);
+       d_hash_shift = 32 - d_hash_shift;
  }
  
  /* SLAB cache for __getname() consumers */
diff --combined fs/eventfd.c
index 6318a9b57e53a9add1f2e41cd38c5adb71bc206a,bc0105ae253f37f5959ab6dee610e9c5e4eeb272..04fd824142a12b606015281ac79a15f30a68012c
@@@ -79,25 -79,12 +79,12 @@@ static void eventfd_free(struct kref *k
        eventfd_free_ctx(ctx);
  }
  
- /**
-  * eventfd_ctx_get - Acquires a reference to the internal eventfd context.
-  * @ctx: [in] Pointer to the eventfd context.
-  *
-  * Returns: In case of success, returns a pointer to the eventfd context.
-  */
- struct eventfd_ctx *eventfd_ctx_get(struct eventfd_ctx *ctx)
- {
-       kref_get(&ctx->kref);
-       return ctx;
- }
- EXPORT_SYMBOL_GPL(eventfd_ctx_get);
  /**
   * eventfd_ctx_put - Releases a reference to the internal eventfd context.
   * @ctx: [in] Pointer to eventfd context.
   *
   * The eventfd context reference must have been previously acquired either
-  * with eventfd_ctx_get() or eventfd_ctx_fdget().
+  * with eventfd_ctx_fdget() or eventfd_ctx_fileget().
   */
  void eventfd_ctx_put(struct eventfd_ctx *ctx)
  {
@@@ -114,10 -101,10 +101,10 @@@ static int eventfd_release(struct inod
        return 0;
  }
  
 -static unsigned int eventfd_poll(struct file *file, poll_table *wait)
 +static __poll_t eventfd_poll(struct file *file, poll_table *wait)
  {
        struct eventfd_ctx *ctx = file->private_data;
 -      unsigned int events = 0;
 +      __poll_t events = 0;
        u64 count;
  
        poll_wait(file, &ctx->wqh, wait);
@@@ -207,36 -194,27 +194,27 @@@ int eventfd_ctx_remove_wait_queue(struc
  }
  EXPORT_SYMBOL_GPL(eventfd_ctx_remove_wait_queue);
  
- /**
-  * eventfd_ctx_read - Reads the eventfd counter or wait if it is zero.
-  * @ctx: [in] Pointer to eventfd context.
-  * @no_wait: [in] Different from zero if the operation should not block.
-  * @cnt: [out] Pointer to the 64-bit counter value.
-  *
-  * Returns %0 if successful, or the following error codes:
-  *
-  *  - -EAGAIN      : The operation would have blocked but @no_wait was non-zero.
-  *  - -ERESTARTSYS : A signal interrupted the wait operation.
-  *
-  * If @no_wait is zero, the function might sleep until the eventfd internal
-  * counter becomes greater than zero.
-  */
- ssize_t eventfd_ctx_read(struct eventfd_ctx *ctx, int no_wait, __u64 *cnt)
+ static ssize_t eventfd_read(struct file *file, char __user *buf, size_t count,
+                           loff_t *ppos)
  {
+       struct eventfd_ctx *ctx = file->private_data;
        ssize_t res;
+       __u64 ucnt = 0;
        DECLARE_WAITQUEUE(wait, current);
  
+       if (count < sizeof(ucnt))
+               return -EINVAL;
        spin_lock_irq(&ctx->wqh.lock);
-       *cnt = 0;
        res = -EAGAIN;
        if (ctx->count > 0)
-               res = 0;
-       else if (!no_wait) {
+               res = sizeof(ucnt);
+       else if (!(file->f_flags & O_NONBLOCK)) {
                __add_wait_queue(&ctx->wqh, &wait);
                for (;;) {
                        set_current_state(TASK_INTERRUPTIBLE);
                        if (ctx->count > 0) {
-                               res = 0;
+                               res = sizeof(ucnt);
                                break;
                        }
                        if (signal_pending(current)) {
                __remove_wait_queue(&ctx->wqh, &wait);
                __set_current_state(TASK_RUNNING);
        }
-       if (likely(res == 0)) {
-               eventfd_ctx_do_read(ctx, cnt);
+       if (likely(res > 0)) {
+               eventfd_ctx_do_read(ctx, &ucnt);
                if (waitqueue_active(&ctx->wqh))
                        wake_up_locked_poll(&ctx->wqh, POLLOUT);
        }
        spin_unlock_irq(&ctx->wqh.lock);
  
-       return res;
- }
- EXPORT_SYMBOL_GPL(eventfd_ctx_read);
- static ssize_t eventfd_read(struct file *file, char __user *buf, size_t count,
-                           loff_t *ppos)
- {
-       struct eventfd_ctx *ctx = file->private_data;
-       ssize_t res;
-       __u64 cnt;
-       if (count < sizeof(cnt))
-               return -EINVAL;
-       res = eventfd_ctx_read(ctx, file->f_flags & O_NONBLOCK, &cnt);
-       if (res < 0)
-               return res;
+       if (res > 0 && put_user(ucnt, (__u64 __user *)buf))
+               return -EFAULT;
  
-       return put_user(cnt, (__u64 __user *) buf) ? -EFAULT : sizeof(cnt);
+       return res;
  }
  
  static ssize_t eventfd_write(struct file *file, const char __user *buf, size_t count,
@@@ -405,79 -369,44 +369,44 @@@ EXPORT_SYMBOL_GPL(eventfd_ctx_fdget)
   */
  struct eventfd_ctx *eventfd_ctx_fileget(struct file *file)
  {
+       struct eventfd_ctx *ctx;
        if (file->f_op != &eventfd_fops)
                return ERR_PTR(-EINVAL);
  
-       return eventfd_ctx_get(file->private_data);
+       ctx = file->private_data;
+       kref_get(&ctx->kref);
+       return ctx;
  }
  EXPORT_SYMBOL_GPL(eventfd_ctx_fileget);
  
- /**
-  * eventfd_file_create - Creates an eventfd file pointer.
-  * @count: Initial eventfd counter value.
-  * @flags: Flags for the eventfd file.
-  *
-  * This function creates an eventfd file pointer, w/out installing it into
-  * the fd table. This is useful when the eventfd file is used during the
-  * initialization of data structures that require extra setup after the eventfd
-  * creation. So the eventfd creation is split into the file pointer creation
-  * phase, and the file descriptor installation phase.
-  * In this way races with userspace closing the newly installed file descriptor
-  * can be avoided.
-  * Returns an eventfd file pointer, or a proper error pointer.
-  */
- struct file *eventfd_file_create(unsigned int count, int flags)
+ SYSCALL_DEFINE2(eventfd2, unsigned int, count, int, flags)
  {
-       struct file *file;
        struct eventfd_ctx *ctx;
+       int fd;
  
        /* Check the EFD_* constants for consistency.  */
        BUILD_BUG_ON(EFD_CLOEXEC != O_CLOEXEC);
        BUILD_BUG_ON(EFD_NONBLOCK != O_NONBLOCK);
  
        if (flags & ~EFD_FLAGS_SET)
-               return ERR_PTR(-EINVAL);
+               return -EINVAL;
  
        ctx = kmalloc(sizeof(*ctx), GFP_KERNEL);
        if (!ctx)
-               return ERR_PTR(-ENOMEM);
+               return -ENOMEM;
  
        kref_init(&ctx->kref);
        init_waitqueue_head(&ctx->wqh);
        ctx->count = count;
        ctx->flags = flags;
  
-       file = anon_inode_getfile("[eventfd]", &eventfd_fops, ctx,
-                                 O_RDWR | (flags & EFD_SHARED_FCNTL_FLAGS));
-       if (IS_ERR(file))
+       fd = anon_inode_getfd("[eventfd]", &eventfd_fops, ctx,
+                             O_RDWR | (flags & EFD_SHARED_FCNTL_FLAGS));
+       if (fd < 0)
                eventfd_free_ctx(ctx);
  
-       return file;
- }
- SYSCALL_DEFINE2(eventfd2, unsigned int, count, int, flags)
- {
-       int fd, error;
-       struct file *file;
-       error = get_unused_fd_flags(flags & EFD_SHARED_FCNTL_FLAGS);
-       if (error < 0)
-               return error;
-       fd = error;
-       file = eventfd_file_create(count, flags);
-       if (IS_ERR(file)) {
-               error = PTR_ERR(file);
-               goto err_put_unused_fd;
-       }
-       fd_install(fd, file);
        return fd;
- err_put_unused_fd:
-       put_unused_fd(fd);
-       return error;
  }
  
  SYSCALL_DEFINE1(eventfd, unsigned int, count)
diff --combined fs/file.c
index fc0eeb812e2cbeb7e0615b17f49d331b0a91867e,bb2d251e19c1035df9c3e6518f05619b56f5f017..42f0db4bd0fb54402171de9609ab961cc3f6aa6e
+++ b/fs/file.c
  #include <linux/export.h>
  #include <linux/fs.h>
  #include <linux/mm.h>
- #include <linux/mmzone.h>
- #include <linux/time.h>
  #include <linux/sched/signal.h>
  #include <linux/slab.h>
- #include <linux/vmalloc.h>
  #include <linux/file.h>
  #include <linux/fdtable.h>
  #include <linux/bitops.h>
- #include <linux/interrupt.h>
  #include <linux/spinlock.h>
  #include <linux/rcupdate.h>
- #include <linux/workqueue.h>
  
  unsigned int sysctl_nr_open __read_mostly = 1024*1024;
  unsigned int sysctl_nr_open_min = BITS_PER_LONG;
@@@ -391,7 -386,7 +386,7 @@@ static struct fdtable *close_files(stru
                                struct file * file = xchg(&fdt->fd[i], NULL);
                                if (file) {
                                        filp_close(file, files);
 -                                      cond_resched_rcu_qs();
 +                                      cond_resched();
                                }
                        }
                        i++;
diff --combined fs/jffs2/fs.c
index d8c274d39ddb986c38cc9482c11de8711b9a8964,3c96f4bdc549833f697ce7a1b24a18526c5f353d..eab04eca95a3f6accd533be6b0c36fe7a92c75f1
@@@ -362,7 -362,6 +362,6 @@@ error_io
        ret = -EIO;
  error:
        mutex_unlock(&f->sem);
-       jffs2_do_clear_inode(c, f);
        iget_failed(inode);
        return ERR_PTR(ret);
  }
@@@ -409,10 -408,10 +408,10 @@@ int jffs2_do_remount_fs(struct super_bl
                mutex_unlock(&c->alloc_sem);
        }
  
 -      if (!(*flags & MS_RDONLY))
 +      if (!(*flags & SB_RDONLY))
                jffs2_start_garbage_collect_thread(c);
  
 -      *flags |= MS_NOATIME;
 +      *flags |= SB_NOATIME;
        return 0;
  }
  
diff --combined fs/namei.c
index 7c221fb0836bc5fa2022e512d56892e14387b361,29b044022e9c6642209f3fdb67c7fa8829c5ba04..921ae32dbc8053813e70b2a6454bf7dc4f85306a
@@@ -390,50 -390,6 +390,6 @@@ static inline int do_inode_permission(s
        return generic_permission(inode, mask);
  }
  
- /**
-  * __inode_permission - Check for access rights to a given inode
-  * @inode: Inode to check permission on
-  * @mask: Right to check for (%MAY_READ, %MAY_WRITE, %MAY_EXEC)
-  *
-  * Check for read/write/execute permissions on an inode.
-  *
-  * When checking for MAY_APPEND, MAY_WRITE must also be set in @mask.
-  *
-  * This does not check for a read-only file system.  You probably want
-  * inode_permission().
-  */
- int __inode_permission(struct inode *inode, int mask)
- {
-       int retval;
-       if (unlikely(mask & MAY_WRITE)) {
-               /*
-                * Nobody gets write access to an immutable file.
-                */
-               if (IS_IMMUTABLE(inode))
-                       return -EPERM;
-               /*
-                * Updating mtime will likely cause i_uid and i_gid to be
-                * written back improperly if their true value is unknown
-                * to the vfs.
-                */
-               if (HAS_UNMAPPED_ID(inode))
-                       return -EACCES;
-       }
-       retval = do_inode_permission(inode, mask);
-       if (retval)
-               return retval;
-       retval = devcgroup_inode_permission(inode, mask);
-       if (retval)
-               return retval;
-       return security_inode_permission(inode, mask);
- }
- EXPORT_SYMBOL(__inode_permission);
  /**
   * sb_permission - Check superblock-level permissions
   * @sb: Superblock of inode to check permission on
@@@ -472,7 -428,32 +428,32 @@@ int inode_permission(struct inode *inod
        retval = sb_permission(inode->i_sb, inode, mask);
        if (retval)
                return retval;
-       return __inode_permission(inode, mask);
+       if (unlikely(mask & MAY_WRITE)) {
+               /*
+                * Nobody gets write access to an immutable file.
+                */
+               if (IS_IMMUTABLE(inode))
+                       return -EPERM;
+               /*
+                * Updating mtime will likely cause i_uid and i_gid to be
+                * written back improperly if their true value is unknown
+                * to the vfs.
+                */
+               if (HAS_UNMAPPED_ID(inode))
+                       return -EACCES;
+       }
+       retval = do_inode_permission(inode, mask);
+       if (retval)
+               return retval;
+       retval = devcgroup_inode_permission(inode, mask);
+       if (retval)
+               return retval;
+       return security_inode_permission(inode, mask);
  }
  EXPORT_SYMBOL(inode_permission);
  
@@@ -1129,9 -1110,21 +1110,9 @@@ static int follow_automount(struct pat
         * of the daemon to instantiate them before they can be used.
         */
        if (!(nd->flags & (LOOKUP_PARENT | LOOKUP_DIRECTORY |
 -                         LOOKUP_OPEN | LOOKUP_CREATE |
 -                         LOOKUP_AUTOMOUNT))) {
 -              /* Positive dentry that isn't meant to trigger an
 -               * automount, EISDIR will allow it to be used,
 -               * otherwise there's no mount here "now" so return
 -               * ENOENT.
 -               */
 -              if (path->dentry->d_inode)
 -                      return -EISDIR;
 -              else
 -                      return -ENOENT;
 -      }
 -
 -      if (path->dentry->d_sb->s_user_ns != &init_user_ns)
 -              return -EACCES;
 +                         LOOKUP_OPEN | LOOKUP_CREATE | LOOKUP_AUTOMOUNT)) &&
 +          path->dentry->d_inode)
 +              return -EISDIR;
  
        nd->total_link_count++;
        if (nd->total_link_count >= 40)
@@@ -2895,27 -2888,6 +2876,27 @@@ int vfs_create(struct inode *dir, struc
  }
  EXPORT_SYMBOL(vfs_create);
  
 +int vfs_mkobj(struct dentry *dentry, umode_t mode,
 +              int (*f)(struct dentry *, umode_t, void *),
 +              void *arg)
 +{
 +      struct inode *dir = dentry->d_parent->d_inode;
 +      int error = may_create(dir, dentry);
 +      if (error)
 +              return error;
 +
 +      mode &= S_IALLUGO;
 +      mode |= S_IFREG;
 +      error = security_inode_create(dir, dentry, mode);
 +      if (error)
 +              return error;
 +      error = f(dentry, mode, arg);
 +      if (!error)
 +              fsnotify_create(dir, dentry);
 +      return error;
 +}
 +EXPORT_SYMBOL(vfs_mkobj);
 +
  bool may_open_dev(const struct path *path)
  {
        return !(path->mnt->mnt_flags & MNT_NODEV) &&
diff --combined fs/super.c
index 06bd25d90ba591f45c6f772e218ffce91c915dbc,9ea66601d66460cec07a7b58cc21df182711a876..672538ca983183e0e4a6dff83db28ff5c9341054
@@@ -191,24 -191,6 +191,24 @@@ static struct super_block *alloc_super(
  
        INIT_LIST_HEAD(&s->s_mounts);
        s->s_user_ns = get_user_ns(user_ns);
 +      init_rwsem(&s->s_umount);
 +      lockdep_set_class(&s->s_umount, &type->s_umount_key);
 +      /*
 +       * sget() can have s_umount recursion.
 +       *
 +       * When it cannot find a suitable sb, it allocates a new
 +       * one (this one), and tries again to find a suitable old
 +       * one.
 +       *
 +       * In case that succeeds, it will acquire the s_umount
 +       * lock of the old one. Since these are clearly distrinct
 +       * locks, and this object isn't exposed yet, there's no
 +       * risk of deadlocks.
 +       *
 +       * Annotate this by putting this lock in a different
 +       * subclass.
 +       */
 +      down_write_nested(&s->s_umount, SINGLE_DEPTH_NESTING);
  
        if (security_sb_alloc(s))
                goto fail;
        if (s->s_user_ns != &init_user_ns)
                s->s_iflags |= SB_I_NODEV;
        INIT_HLIST_NODE(&s->s_instances);
-       INIT_HLIST_BL_HEAD(&s->s_anon);
+       INIT_HLIST_BL_HEAD(&s->s_roots);
        mutex_init(&s->s_sync_lock);
        INIT_LIST_HEAD(&s->s_inodes);
        spin_lock_init(&s->s_inode_list_lock);
                goto fail;
        if (list_lru_init_memcg(&s->s_inode_lru))
                goto fail;
 -
 -      init_rwsem(&s->s_umount);
 -      lockdep_set_class(&s->s_umount, &type->s_umount_key);
 -      /*
 -       * sget() can have s_umount recursion.
 -       *
 -       * When it cannot find a suitable sb, it allocates a new
 -       * one (this one), and tries again to find a suitable old
 -       * one.
 -       *
 -       * In case that succeeds, it will acquire the s_umount
 -       * lock of the old one. Since these are clearly distrinct
 -       * locks, and this object isn't exposed yet, there's no
 -       * risk of deadlocks.
 -       *
 -       * Annotate this by putting this lock in a different
 -       * subclass.
 -       */
 -      down_write_nested(&s->s_umount, SINGLE_DEPTH_NESTING);
        s->s_count = 1;
        atomic_set(&s->s_active, 1);
        mutex_init(&s->s_vfs_rename_mutex);
@@@ -517,11 -518,7 +517,11 @@@ retry
        hlist_add_head(&s->s_instances, &type->fs_supers);
        spin_unlock(&sb_lock);
        get_filesystem(type);
 -      register_shrinker(&s->s_shrink);
 +      err = register_shrinker(&s->s_shrink);
 +      if (err) {
 +              deactivate_locked_super(s);
 +              s = ERR_PTR(err);
 +      }
        return s;
  }
  
diff --combined include/linux/fs.h
index 9798a133e7185b9a78a58c12ce36226a9224298d,b49251112add368bc272521b901eea029534a91f..8f6654c2171185e4eae7ad6504b9625b7c7a1e00
@@@ -639,7 -639,7 +639,7 @@@ struct inode 
                struct hlist_head       i_dentry;
                struct rcu_head         i_rcu;
        };
 -      u64                     i_version;
 +      atomic64_t              i_version;
        atomic_t                i_count;
        atomic_t                i_dio_count;
        atomic_t                i_writecount;
@@@ -1359,7 -1359,7 +1359,7 @@@ struct super_block 
  
        const struct fscrypt_operations *s_cop;
  
-       struct hlist_bl_head    s_anon;         /* anonymous dentries for (nfs) exporting */
+       struct hlist_bl_head    s_roots;        /* alternate root dentries for NFS */
        struct list_head        s_mounts;       /* list of mounts; _not_ for fs use */
        struct block_device     *s_bdev;
        struct backing_dev_info *s_bdi;
@@@ -1608,10 -1608,6 +1608,10 @@@ extern int vfs_whiteout(struct inode *
  extern struct dentry *vfs_tmpfile(struct dentry *dentry, umode_t mode,
                                  int open_flag);
  
 +int vfs_mkobj(struct dentry *, umode_t,
 +              int (*f)(struct dentry *, umode_t, void *),
 +              void *);
 +
  /*
   * VFS file helper functions.
   */
@@@ -1702,7 -1698,7 +1702,7 @@@ struct file_operations 
        ssize_t (*write_iter) (struct kiocb *, struct iov_iter *);
        int (*iterate) (struct file *, struct dir_context *);
        int (*iterate_shared) (struct file *, struct dir_context *);
 -      unsigned int (*poll) (struct file *, struct poll_table_struct *);
 +      __poll_t (*poll) (struct file *, struct poll_table_struct *);
        long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);
        long (*compat_ioctl) (struct file *, unsigned int, unsigned long);
        int (*mmap) (struct file *, struct vm_area_struct *);
@@@ -1876,7 -1872,7 +1876,7 @@@ struct super_operations 
   */
  #define __IS_FLG(inode, flg)  ((inode)->i_sb->s_flags & (flg))
  
 -static inline bool sb_rdonly(const struct super_block *sb) { return sb->s_flags & MS_RDONLY; }
 +static inline bool sb_rdonly(const struct super_block *sb) { return sb->s_flags & SB_RDONLY; }
  #define IS_RDONLY(inode)      sb_rdonly((inode)->i_sb)
  #define IS_SYNC(inode)                (__IS_FLG(inode, SB_SYNCHRONOUS) || \
                                        ((inode)->i_flags & S_SYNC))
@@@ -2040,6 -2036,21 +2040,6 @@@ static inline void inode_dec_link_count
        mark_inode_dirty(inode);
  }
  
 -/**
 - * inode_inc_iversion - increments i_version
 - * @inode: inode that need to be updated
 - *
 - * Every time the inode is modified, the i_version field will be incremented.
 - * The filesystem has to be mounted with i_version flag
 - */
 -
 -static inline void inode_inc_iversion(struct inode *inode)
 -{
 -       spin_lock(&inode->i_lock);
 -       inode->i_version++;
 -       spin_unlock(&inode->i_lock);
 -}
 -
  enum file_time_flags {
        S_ATIME = 1,
        S_MTIME = 2,
@@@ -2688,7 -2699,6 +2688,6 @@@ extern sector_t bmap(struct inode *, se
  #endif
  extern int notify_change(struct dentry *, struct iattr *, struct inode **);
  extern int inode_permission(struct inode *, int);
- extern int __inode_permission(struct inode *, int);
  extern int generic_permission(struct inode *, int);
  extern int __check_sticky(struct inode *dir, struct inode *inode);
  
@@@ -3077,8 -3087,7 +3076,8 @@@ static inline int vfs_lstat(const char 
  static inline int vfs_fstatat(int dfd, const char __user *filename,
                              struct kstat *stat, int flags)
  {
 -      return vfs_statx(dfd, filename, flags, stat, STATX_BASIC_STATS);
 +      return vfs_statx(dfd, filename, flags | AT_NO_AUTOMOUNT,
 +                       stat, STATX_BASIC_STATS);
  }
  static inline int vfs_fstat(int fd, struct kstat *stat)
  {
@@@ -3184,20 -3193,6 +3183,20 @@@ static inline bool vma_is_dax(struct vm
        return vma->vm_file && IS_DAX(vma->vm_file->f_mapping->host);
  }
  
 +static inline bool vma_is_fsdax(struct vm_area_struct *vma)
 +{
 +      struct inode *inode;
 +
 +      if (!vma->vm_file)
 +              return false;
 +      if (!vma_is_dax(vma))
 +              return false;
 +      inode = file_inode(vma->vm_file);
 +      if (inode->i_mode == S_IFCHR)
 +              return false; /* device-dax */
 +      return true;
 +}
 +
  static inline int iocb_flags(struct file *file)
  {
        int res = 0;
@@@ -3228,6 -3223,8 +3227,8 @@@ static inline int kiocb_set_rw_flags(st
                ki->ki_flags |= IOCB_DSYNC;
        if (flags & RWF_SYNC)
                ki->ki_flags |= (IOCB_DSYNC | IOCB_SYNC);
+       if (flags & RWF_APPEND)
+               ki->ki_flags |= IOCB_APPEND;
        return 0;
  }
  
diff --combined include/linux/string.h
index 96115bf561b452112f411ecbcd61f5e016b00911,12d5429de0c87e00fbb31ad26cb4f0ec7feee519..dd39a690c841e4abc05516b6f83151e31809da9c
@@@ -11,6 -11,7 +11,7 @@@
  
  extern char *strndup_user(const char __user *, long);
  extern void *memdup_user(const void __user *, size_t);
+ extern void *vmemdup_user(const void __user *, size_t);
  extern void *memdup_user_nul(const void __user *, size_t);
  
  /*
@@@ -28,7 -29,7 +29,7 @@@ extern char * strncpy(char *,const cha
  size_t strlcpy(char *, const char *, size_t);
  #endif
  #ifndef __HAVE_ARCH_STRSCPY
 -ssize_t __must_check strscpy(char *, const char *, size_t);
 +ssize_t strscpy(char *, const char *, size_t);
  #endif
  #ifndef __HAVE_ARCH_STRCAT
  extern char * strcat(char *, const char *);
@@@ -259,10 -260,7 +260,10 @@@ __FORTIFY_INLINE __kernel_size_t strlen
  {
        __kernel_size_t ret;
        size_t p_size = __builtin_object_size(p, 0);
 -      if (p_size == (size_t)-1)
 +
 +      /* Work around gcc excess stack consumption issue */
 +      if (p_size == (size_t)-1 ||
 +          (__builtin_constant_p(p[p_size - 1]) && p[p_size - 1] == '\0'))
                return __builtin_strlen(p);
        ret = strnlen(p, p_size);
        if (p_size <= ret)
diff --combined net/sctp/socket.c
index 37382317fba4e6204a060c98db939b5349a0e04b,c2cccc9902d63fc855a9aeda13e7ed621782e6d1..737e551fbf6740ac1d4633048807788293bc5523
@@@ -85,7 -85,7 +85,7 @@@
  static int sctp_writeable(struct sock *sk);
  static void sctp_wfree(struct sk_buff *skb);
  static int sctp_wait_for_sndbuf(struct sctp_association *asoc, long *timeo_p,
 -                              size_t msg_len, struct sock **orig_sk);
 +                              size_t msg_len);
  static int sctp_wait_for_packet(struct sock *sk, int *err, long *timeo_p);
  static int sctp_wait_for_connect(struct sctp_association *, long *timeo_p);
  static int sctp_wait_for_accept(struct sock *sk, long timeo);
@@@ -188,13 -188,13 +188,13 @@@ static void sctp_for_each_tx_datachunk(
                list_for_each_entry(chunk, &t->transmitted, transmitted_list)
                        cb(chunk);
  
 -      list_for_each_entry(chunk, &q->retransmit, list)
 +      list_for_each_entry(chunk, &q->retransmit, transmitted_list)
                cb(chunk);
  
 -      list_for_each_entry(chunk, &q->sacked, list)
 +      list_for_each_entry(chunk, &q->sacked, transmitted_list)
                cb(chunk);
  
 -      list_for_each_entry(chunk, &q->abandoned, list)
 +      list_for_each_entry(chunk, &q->abandoned, transmitted_list)
                cb(chunk);
  
        list_for_each_entry(chunk, &q->out_chunk_list, list)
@@@ -335,14 -335,16 +335,14 @@@ static struct sctp_af *sctp_sockaddr_af
        if (len < sizeof (struct sockaddr))
                return NULL;
  
 +      if (!opt->pf->af_supported(addr->sa.sa_family, opt))
 +              return NULL;
 +
        /* V4 mapped address are really of AF_INET family */
        if (addr->sa.sa_family == AF_INET6 &&
 -          ipv6_addr_v4mapped(&addr->v6.sin6_addr)) {
 -              if (!opt->pf->af_supported(AF_INET, opt))
 -                      return NULL;
 -      } else {
 -              /* Does this PF support this AF? */
 -              if (!opt->pf->af_supported(addr->sa.sa_family, opt))
 -                      return NULL;
 -      }
 +          ipv6_addr_v4mapped(&addr->v6.sin6_addr) &&
 +          !opt->pf->af_supported(AF_INET, opt))
 +              return NULL;
  
        /* If we get this far, af is valid. */
        af = sctp_get_af_specific(addr->sa.sa_family);
@@@ -968,13 -970,6 +968,6 @@@ int sctp_asconf_mgmt(struct sctp_sock *
   * This is used for tunneling the sctp_bindx() request through sctp_setsockopt()
   * from userspace.
   *
-  * We don't use copy_from_user() for optimization: we first do the
-  * sanity checks (buffer size -fast- and access check-healthy
-  * pointer); if all of those succeed, then we can alloc the memory
-  * (expensive operation) needed to copy the data to kernel. Then we do
-  * the copying without checking the user space area
-  * (__copy_from_user()).
-  *
   * On exit there is no need to do sockfd_put(), sys_setsockopt() does
   * it.
   *
@@@ -1004,25 -999,15 +997,15 @@@ static int sctp_setsockopt_bindx(struc
        if (unlikely(addrs_size <= 0))
                return -EINVAL;
  
-       /* Check the user passed a healthy pointer.  */
-       if (unlikely(!access_ok(VERIFY_READ, addrs, addrs_size)))
-               return -EFAULT;
-       /* Alloc space for the address array in kernel memory.  */
-       kaddrs = kmalloc(addrs_size, GFP_USER | __GFP_NOWARN);
-       if (unlikely(!kaddrs))
-               return -ENOMEM;
-       if (__copy_from_user(kaddrs, addrs, addrs_size)) {
-               kfree(kaddrs);
-               return -EFAULT;
-       }
+       kaddrs = vmemdup_user(addrs, addrs_size);
+       if (unlikely(IS_ERR(kaddrs)))
+               return PTR_ERR(kaddrs);
  
        /* Walk through the addrs buffer and count the number of addresses. */
        addr_buf = kaddrs;
        while (walk_size < addrs_size) {
                if (walk_size + sizeof(sa_family_t) > addrs_size) {
-                       kfree(kaddrs);
+                       kvfree(kaddrs);
                        return -EINVAL;
                }
  
                 * causes the address buffer to overflow return EINVAL.
                 */
                if (!af || (walk_size + af->sockaddr_len) > addrs_size) {
-                       kfree(kaddrs);
+                       kvfree(kaddrs);
                        return -EINVAL;
                }
                addrcnt++;
        }
  
  out:
-       kfree(kaddrs);
+       kvfree(kaddrs);
  
        return err;
  }
@@@ -1321,13 -1306,6 +1304,6 @@@ out_free
   * land and invoking either sctp_connectx(). This is used for tunneling
   * the sctp_connectx() request through sctp_setsockopt() from userspace.
   *
-  * We don't use copy_from_user() for optimization: we first do the
-  * sanity checks (buffer size -fast- and access check-healthy
-  * pointer); if all of those succeed, then we can alloc the memory
-  * (expensive operation) needed to copy the data to kernel. Then we do
-  * the copying without checking the user space area
-  * (__copy_from_user()).
-  *
   * On exit there is no need to do sockfd_put(), sys_setsockopt() does
   * it.
   *
@@@ -1343,7 -1321,6 +1319,6 @@@ static int __sctp_setsockopt_connectx(s
                                      sctp_assoc_t *assoc_id)
  {
        struct sockaddr *kaddrs;
-       gfp_t gfp = GFP_KERNEL;
        int err = 0;
  
        pr_debug("%s: sk:%p addrs:%p addrs_size:%d\n",
        if (unlikely(addrs_size <= 0))
                return -EINVAL;
  
-       /* Check the user passed a healthy pointer.  */
-       if (unlikely(!access_ok(VERIFY_READ, addrs, addrs_size)))
-               return -EFAULT;
-       /* Alloc space for the address array in kernel memory.  */
-       if (sk->sk_socket->file)
-               gfp = GFP_USER | __GFP_NOWARN;
-       kaddrs = kmalloc(addrs_size, gfp);
-       if (unlikely(!kaddrs))
-               return -ENOMEM;
-       if (__copy_from_user(kaddrs, addrs, addrs_size)) {
-               err = -EFAULT;
-       } else {
-               err = __sctp_connect(sk, kaddrs, addrs_size, assoc_id);
-       }
+       kaddrs = vmemdup_user(addrs, addrs_size);
+       if (unlikely(IS_ERR(kaddrs)))
+               return PTR_ERR(kaddrs);
  
-       kfree(kaddrs);
+       err = __sctp_connect(sk, kaddrs, addrs_size, assoc_id);
+       kvfree(kaddrs);
  
        return err;
  }
@@@ -1881,14 -1846,8 +1844,14 @@@ static int sctp_sendmsg(struct sock *sk
                 */
                if (sinit) {
                        if (sinit->sinit_num_ostreams) {
 -                              asoc->c.sinit_num_ostreams =
 -                                      sinit->sinit_num_ostreams;
 +                              __u16 outcnt = sinit->sinit_num_ostreams;
 +
 +                              asoc->c.sinit_num_ostreams = outcnt;
 +                              /* outcnt has been changed, so re-init stream */
 +                              err = sctp_stream_init(&asoc->stream, outcnt, 0,
 +                                                     GFP_KERNEL);
 +                              if (err)
 +                                      goto out_free;
                        }
                        if (sinit->sinit_max_instreams) {
                                asoc->c.sinit_max_instreams =
        timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT);
        if (!sctp_wspace(asoc)) {
                /* sk can be changed by peel off when waiting for buf. */
 -              err = sctp_wait_for_sndbuf(asoc, &timeo, msg_len, &sk);
 +              err = sctp_wait_for_sndbuf(asoc, &timeo, msg_len);
                if (err) {
                        if (err == -ESRCH) {
                                /* asoc is already dead. */
@@@ -2281,7 -2240,7 +2244,7 @@@ static int sctp_setsockopt_events(struc
  
                if (asoc && sctp_outq_is_empty(&asoc->outqueue)) {
                        event = sctp_ulpevent_make_sender_dry_event(asoc,
 -                                      GFP_ATOMIC);
 +                                      GFP_USER | __GFP_NOWARN);
                        if (!event)
                                return -ENOMEM;
  
@@@ -3502,8 -3461,6 +3465,8 @@@ static int sctp_setsockopt_hmac_ident(s
  
        if (optlen < sizeof(struct sctp_hmacalgo))
                return -EINVAL;
 +      optlen = min_t(unsigned int, optlen, sizeof(struct sctp_hmacalgo) +
 +                                           SCTP_AUTH_NUM_HMACS * sizeof(u16));
  
        hmacs = memdup_user(optval, optlen);
        if (IS_ERR(hmacs))
@@@ -3542,11 -3499,6 +3505,11 @@@ static int sctp_setsockopt_auth_key(str
  
        if (optlen <= sizeof(struct sctp_authkey))
                return -EINVAL;
 +      /* authkey->sca_keylength is u16, so optlen can't be bigger than
 +       * this.
 +       */
 +      optlen = min_t(unsigned int, optlen, USHRT_MAX +
 +                                           sizeof(struct sctp_authkey));
  
        authkey = memdup_user(optval, optlen);
        if (IS_ERR(authkey))
@@@ -3902,20 -3854,13 +3865,20 @@@ static int sctp_setsockopt_reset_stream
        struct sctp_association *asoc;
        int retval = -EINVAL;
  
 -      if (optlen < sizeof(struct sctp_reset_streams))
 +      if (optlen < sizeof(*params))
                return -EINVAL;
 +      /* srs_number_streams is u16, so optlen can't be bigger than this. */
 +      optlen = min_t(unsigned int, optlen, USHRT_MAX +
 +                                           sizeof(__u16) * sizeof(*params));
  
        params = memdup_user(optval, optlen);
        if (IS_ERR(params))
                return PTR_ERR(params);
  
 +      if (params->srs_number_streams * sizeof(__u16) >
 +          optlen - sizeof(*params))
 +              goto out;
 +
        asoc = sctp_id2assoc(sk, params->srs_assoc_id);
        if (!asoc)
                goto out;
@@@ -4512,7 -4457,7 +4475,7 @@@ static int sctp_init_sock(struct sock *
        SCTP_DBG_OBJCNT_INC(sock);
  
        local_bh_disable();
 -      percpu_counter_inc(&sctp_sockets_allocated);
 +      sk_sockets_allocated_inc(sk);
        sock_prot_inuse_add(net, sk->sk_prot, 1);
  
        /* Nothing can fail after this block, otherwise
@@@ -4556,7 -4501,7 +4519,7 @@@ static void sctp_destroy_sock(struct so
        }
        sctp_endpoint_free(sp->ep);
        local_bh_disable();
 -      percpu_counter_dec(&sctp_sockets_allocated);
 +      sk_sockets_allocated_dec(sk);
        sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1);
        local_bh_enable();
  }
@@@ -5029,7 -4974,7 +4992,7 @@@ static int sctp_getsockopt_autoclose(st
        len = sizeof(int);
        if (put_user(len, optlen))
                return -EFAULT;
 -      if (copy_to_user(optval, &sctp_sk(sk)->autoclose, sizeof(int)))
 +      if (copy_to_user(optval, &sctp_sk(sk)->autoclose, len))
                return -EFAULT;
        return 0;
  }
@@@ -5098,6 -5043,7 +5061,6 @@@ static int sctp_getsockopt_peeloff_comm
        *newfile = sock_alloc_file(newsock, 0, NULL);
        if (IS_ERR(*newfile)) {
                put_unused_fd(retval);
 -              sock_release(newsock);
                retval = PTR_ERR(*newfile);
                *newfile = NULL;
                return retval;
@@@ -5659,9 -5605,6 +5622,9 @@@ copy_getaddrs
                err = -EFAULT;
                goto out;
        }
 +      /* XXX: We should have accounted for sizeof(struct sctp_getaddrs) too,
 +       * but we can't change it anymore.
 +       */
        if (put_user(bytes_copied, optlen))
                err = -EFAULT;
  out:
@@@ -6098,7 -6041,7 +6061,7 @@@ static int sctp_getsockopt_maxseg(struc
                params.assoc_id = 0;
        } else if (len >= sizeof(struct sctp_assoc_value)) {
                len = sizeof(struct sctp_assoc_value);
 -              if (copy_from_user(&params, optval, sizeof(params)))
 +              if (copy_from_user(&params, optval, len))
                        return -EFAULT;
        } else
                return -EINVAL;
@@@ -6268,9 -6211,7 +6231,9 @@@ static int sctp_getsockopt_active_key(s
  
        if (len < sizeof(struct sctp_authkeyid))
                return -EINVAL;
 -      if (copy_from_user(&val, optval, sizeof(struct sctp_authkeyid)))
 +
 +      len = sizeof(struct sctp_authkeyid);
 +      if (copy_from_user(&val, optval, len))
                return -EFAULT;
  
        asoc = sctp_id2assoc(sk, val.scact_assoc_id);
        else
                val.scact_keynumber = ep->active_key_id;
  
 -      len = sizeof(struct sctp_authkeyid);
        if (put_user(len, optlen))
                return -EFAULT;
        if (copy_to_user(optval, &val, len))
@@@ -6307,7 -6249,7 +6270,7 @@@ static int sctp_getsockopt_peer_auth_ch
        if (len < sizeof(struct sctp_authchunks))
                return -EINVAL;
  
 -      if (copy_from_user(&val, optval, sizeof(struct sctp_authchunks)))
 +      if (copy_from_user(&val, optval, sizeof(val)))
                return -EFAULT;
  
        to = p->gauth_chunks;
@@@ -6352,7 -6294,7 +6315,7 @@@ static int sctp_getsockopt_local_auth_c
        if (len < sizeof(struct sctp_authchunks))
                return -EINVAL;
  
 -      if (copy_from_user(&val, optval, sizeof(struct sctp_authchunks)))
 +      if (copy_from_user(&val, optval, sizeof(val)))
                return -EFAULT;
  
        to = p->gauth_chunks;
   * here, again, by modeling the current TCP/UDP code.  We don't have
   * a good way to test with it yet.
   */
 -unsigned int sctp_poll(struct file *file, struct socket *sock, poll_table *wait)
 +__poll_t sctp_poll(struct file *file, struct socket *sock, poll_table *wait)
  {
        struct sock *sk = sock->sk;
        struct sctp_sock *sp = sctp_sk(sk);
 -      unsigned int mask;
 +      __poll_t mask;
  
        poll_wait(file, sk_sleep(sk), wait);
  
@@@ -8020,12 -7962,12 +7983,12 @@@ void sctp_sock_rfree(struct sk_buff *sk
  
  /* Helper function to wait for space in the sndbuf.  */
  static int sctp_wait_for_sndbuf(struct sctp_association *asoc, long *timeo_p,
 -                              size_t msg_len, struct sock **orig_sk)
 +                              size_t msg_len)
  {
        struct sock *sk = asoc->base.sk;
 -      int err = 0;
        long current_timeo = *timeo_p;
        DEFINE_WAIT(wait);
 +      int err = 0;
  
        pr_debug("%s: asoc:%p, timeo:%ld, msg_len:%zu\n", __func__, asoc,
                 *timeo_p, msg_len);
                release_sock(sk);
                current_timeo = schedule_timeout(current_timeo);
                lock_sock(sk);
 -              if (sk != asoc->base.sk) {
 -                      release_sock(sk);
 -                      sk = asoc->base.sk;
 -                      lock_sock(sk);
 -              }
 +              if (sk != asoc->base.sk)
 +                      goto do_error;
  
                *timeo_p = current_timeo;
        }
  
  out:
 -      *orig_sk = sk;
        finish_wait(&asoc->wait, &wait);
  
        /* Release the association's refcnt.  */
diff --combined sound/core/control.c
index 494389fb966ca6a7daf0971b709c21ada354bc45,d16b53d0547cc1ed275a527af89a1ad7cda65f7e..50fa16022f1fe67eb88881f2a8f4d4544934ea90
@@@ -25,6 -25,7 +25,7 @@@
  #include <linux/slab.h>
  #include <linux/vmalloc.h>
  #include <linux/time.h>
+ #include <linux/mm.h>
  #include <linux/sched/signal.h>
  #include <sound/core.h>
  #include <sound/minors.h>
@@@ -1129,7 -1130,7 +1130,7 @@@ static int replace_user_tlv(struct snd_
        if (size > 1024 * 128)  /* sane value */
                return -EINVAL;
  
-       container = memdup_user(buf, size);
+       container = vmemdup_user(buf, size);
        if (IS_ERR(container))
                return PTR_ERR(container);
  
        if (!change)
                change = memcmp(ue->tlv_data, container, size) != 0;
        if (!change) {
-               kfree(container);
+               kvfree(container);
                return 0;
        }
  
                mask = SNDRV_CTL_EVENT_MASK_INFO;
        }
  
-       kfree(ue->tlv_data);
+       kvfree(ue->tlv_data);
        ue->tlv_data = container;
        ue->tlv_data_size = size;
  
@@@ -1197,7 -1198,7 +1198,7 @@@ static int snd_ctl_elem_init_enum_names
        if (ue->info.value.enumerated.names_length > 64 * 1024)
                return -EINVAL;
  
-       names = memdup_user((const void __user *)user_ptrval,
+       names = vmemdup_user((const void __user *)user_ptrval,
                ue->info.value.enumerated.names_length);
        if (IS_ERR(names))
                return PTR_ERR(names);
        for (i = 0; i < ue->info.value.enumerated.items; ++i) {
                name_len = strnlen(p, buf_len);
                if (name_len == 0 || name_len >= 64 || name_len == buf_len) {
-                       kfree(names);
+                       kvfree(names);
                        return -EINVAL;
                }
                p += name_len + 1;
@@@ -1225,8 -1226,8 +1226,8 @@@ static void snd_ctl_elem_user_free(stru
  {
        struct user_element *ue = kcontrol->private_data;
  
-       kfree(ue->tlv_data);
-       kfree(ue->priv_data);
+       kvfree(ue->tlv_data);
+       kvfree(ue->priv_data);
        kfree(ue);
  }
  
@@@ -1666,9 -1667,9 +1667,9 @@@ static ssize_t snd_ctl_read(struct fil
                return result > 0 ? result : err;
  }
  
 -static unsigned int snd_ctl_poll(struct file *file, poll_table * wait)
 +static __poll_t snd_ctl_poll(struct file *file, poll_table * wait)
  {
 -      unsigned int mask;
 +      __poll_t mask;
        struct snd_ctl_file *ctl;
  
        ctl = file->private_data;
diff --combined sound/core/hwdep.c
index cbda5c8b675fe14ecbd276496aeab72b0991a726,25b8f2234fc72310841f22402d3952e3a5c12493..26e71cf05f1e0b67aa8fb9f8f8617cc1a66aee06
@@@ -177,7 -177,7 +177,7 @@@ static int snd_hwdep_release(struct ino
        return err;
  }
  
 -static unsigned int snd_hwdep_poll(struct file * file, poll_table * wait)
 +static __poll_t snd_hwdep_poll(struct file * file, poll_table * wait)
  {
        struct snd_hwdep *hw = file->private_data;
        if (hw->ops.poll)
@@@ -233,8 -233,6 +233,6 @@@ static int snd_hwdep_dsp_load(struct sn
        /* check whether the dsp was already loaded */
        if (hw->dsp_loaded & (1 << info.index))
                return -EBUSY;
-       if (!access_ok(VERIFY_READ, info.image, info.length))
-               return -EFAULT;
        err = hw->ops.dsp_load(hw, &info);
        if (err < 0)
                return err;
diff --combined sound/usb/usx2y/us122l.c
index 509680d9b698605886ffd217dd2d9c41f64ded32,8c394178a38535d6e2e7a0c5158670a486a24913..e2be10d1711833f3803b5609abe08d60e5fb9065
@@@ -271,12 -271,12 +271,12 @@@ out
        return err;
  }
  
 -static unsigned int usb_stream_hwdep_poll(struct snd_hwdep *hw,
 +static __poll_t usb_stream_hwdep_poll(struct snd_hwdep *hw,
                                          struct file *file, poll_table *wait)
  {
        struct us122l   *us122l = hw->private_data;
        unsigned        *polled;
 -      unsigned int    mask;
 +      __poll_t        mask;
  
        poll_wait(file, &us122l->sk.sleep, wait);
  
@@@ -378,7 -378,7 +378,7 @@@ out
  static int usb_stream_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
                                  unsigned cmd, unsigned long arg)
  {
-       struct usb_stream_config *cfg;
+       struct usb_stream_config cfg;
        struct us122l *us122l = hw->private_data;
        struct usb_stream *s;
        unsigned min_period_frames;
        if (cmd != SNDRV_USB_STREAM_IOCTL_SET_PARAMS)
                return -ENOTTY;
  
-       cfg = memdup_user((void *)arg, sizeof(*cfg));
-       if (IS_ERR(cfg))
-               return PTR_ERR(cfg);
+       if (copy_from_user(&cfg, (void __user *)arg, sizeof(cfg)))
+               return -EFAULT;
+       if (cfg.version != USB_STREAM_INTERFACE_VERSION)
+               return -ENXIO;
  
-       if (cfg->version != USB_STREAM_INTERFACE_VERSION) {
-               err = -ENXIO;
-               goto free;
-       }
        high_speed = us122l->dev->speed == USB_SPEED_HIGH;
-       if ((cfg->sample_rate != 44100 && cfg->sample_rate != 48000  &&
+       if ((cfg.sample_rate != 44100 && cfg.sample_rate != 48000  &&
             (!high_speed ||
-             (cfg->sample_rate != 88200 && cfg->sample_rate != 96000))) ||
-           cfg->frame_size != 6 ||
-           cfg->period_frames > 0x3000) {
-               err = -EINVAL;
-               goto free;
-       }
-       switch (cfg->sample_rate) {
+             (cfg.sample_rate != 88200 && cfg.sample_rate != 96000))) ||
+           cfg.frame_size != 6 ||
+           cfg.period_frames > 0x3000)
+               return -EINVAL;
+       switch (cfg.sample_rate) {
        case 44100:
                min_period_frames = 48;
                break;
        }
        if (!high_speed)
                min_period_frames <<= 1;
-       if (cfg->period_frames < min_period_frames) {
-               err = -EINVAL;
-               goto free;
-       }
+       if (cfg.period_frames < min_period_frames)
+               return -EINVAL;
  
        snd_power_wait(hw->card, SNDRV_CTL_POWER_D0);
  
        if (!us122l->master)
                us122l->master = file;
        else if (us122l->master != file) {
-               if (!s || memcmp(cfg, &s->cfg, sizeof(*cfg))) {
+               if (!s || memcmp(&cfg, &s->cfg, sizeof(cfg))) {
                        err = -EIO;
                        goto unlock;
                }
                us122l->slave = file;
        }
-       if (!s || memcmp(cfg, &s->cfg, sizeof(*cfg)) ||
+       if (!s || memcmp(&cfg, &s->cfg, sizeof(cfg)) ||
            s->state == usb_stream_xrun) {
                us122l_stop(us122l);
-               if (!us122l_start(us122l, cfg->sample_rate, cfg->period_frames))
+               if (!us122l_start(us122l, cfg.sample_rate, cfg.period_frames))
                        err = -EIO;
                else
                        err = 1;
        }
  unlock:
        mutex_unlock(&us122l->mutex);
- free:
-       kfree(cfg);
        wake_up_all(&us122l->sk.sleep);
        return err;
  }
index 8b0a1eae573c046029d58402dc4470543b67199c,2bbcf4af06dd0fd72a015d7e861c679e77f2ecd5..07d15bae75bceb8efa5c211a248bdb8551d902cc
@@@ -86,9 -86,9 +86,9 @@@ static int snd_us428ctls_mmap(struct sn
        return 0;
  }
  
 -static unsigned int snd_us428ctls_poll(struct snd_hwdep *hw, struct file *file, poll_table *wait)
 +static __poll_t snd_us428ctls_poll(struct snd_hwdep *hw, struct file *file, poll_table *wait)
  {
 -      unsigned int    mask = 0;
 +      __poll_t        mask = 0;
        struct usX2Ydev *us428 = hw->private_data;
        struct us428ctls_sharedmem *shm = us428->us428ctls_sharedmem;
        if (us428->chip_status & USX2Y_STAT_CHIP_HUP)
@@@ -198,24 -198,22 +198,22 @@@ static int snd_usX2Y_hwdep_dsp_load(str
                                    struct snd_hwdep_dsp_image *dsp)
  {
        struct usX2Ydev *priv = hw->private_data;
-       int     lret, err = -EINVAL;
-       snd_printdd( "dsp_load %s\n", dsp->name);
+       struct usb_device* dev = priv->dev;
+       int lret, err;
+       char *buf;
  
-       if (access_ok(VERIFY_READ, dsp->image, dsp->length)) {
-               struct usb_device* dev = priv->dev;
-               char *buf;
+       snd_printdd( "dsp_load %s\n", dsp->name);
  
-               buf = memdup_user(dsp->image, dsp->length);
-               if (IS_ERR(buf))
-                       return PTR_ERR(buf);
+       buf = memdup_user(dsp->image, dsp->length);
+       if (IS_ERR(buf))
+               return PTR_ERR(buf);
  
-               err = usb_set_interface(dev, 0, 1);
-               if (err)
-                       snd_printk(KERN_ERR "usb_set_interface error \n");
-               else
-                       err = usb_bulk_msg(dev, usb_sndbulkpipe(dev, 2), buf, dsp->length, &lret, 6000);
-               kfree(buf);
-       }
+       err = usb_set_interface(dev, 0, 1);
+       if (err)
+               snd_printk(KERN_ERR "usb_set_interface error \n");
+       else
+               err = usb_bulk_msg(dev, usb_sndbulkpipe(dev, 2), buf, dsp->length, &lret, 6000);
+       kfree(buf);
        if (err)
                return err;
        if (dsp->index == 1) {