Merge tag 'usercopy-v4.16-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees...
authorLinus Torvalds <torvalds@linux-foundation.org>
Sun, 4 Feb 2018 00:25:42 +0000 (16:25 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sun, 4 Feb 2018 00:25:42 +0000 (16:25 -0800)
Pull hardened usercopy whitelisting from Kees Cook:
 "Currently, hardened usercopy performs dynamic bounds checking on slab
  cache objects. This is good, but still leaves a lot of kernel memory
  available to be copied to/from userspace in the face of bugs.

  To further restrict what memory is available for copying, this creates
  a way to whitelist specific areas of a given slab cache object for
  copying to/from userspace, allowing much finer granularity of access
  control.

  Slab caches that are never exposed to userspace can declare no
  whitelist for their objects, thereby keeping them unavailable to
  userspace via dynamic copy operations. (Note, an implicit form of
  whitelisting is the use of constant sizes in usercopy operations and
  get_user()/put_user(); these bypass all hardened usercopy checks since
  these sizes cannot change at runtime.)

  This new check is WARN-by-default, so any mistakes can be found over
  the next several releases without breaking anyone's system.

  The series has roughly the following sections:
   - remove %p and improve reporting with offset
   - prepare infrastructure and whitelist kmalloc
   - update VFS subsystem with whitelists
   - update SCSI subsystem with whitelists
   - update network subsystem with whitelists
   - update process memory with whitelists
   - update per-architecture thread_struct with whitelists
   - update KVM with whitelists and fix ioctl bug
   - mark all other allocations as not whitelisted
   - update lkdtm for more sensible test overage"

* tag 'usercopy-v4.16-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux: (38 commits)
  lkdtm: Update usercopy tests for whitelisting
  usercopy: Restrict non-usercopy caches to size 0
  kvm: x86: fix KVM_XEN_HVM_CONFIG ioctl
  kvm: whitelist struct kvm_vcpu_arch
  arm: Implement thread_struct whitelist for hardened usercopy
  arm64: Implement thread_struct whitelist for hardened usercopy
  x86: Implement thread_struct whitelist for hardened usercopy
  fork: Provide usercopy whitelisting for task_struct
  fork: Define usercopy region in thread_stack slab caches
  fork: Define usercopy region in mm_struct slab caches
  net: Restrict unwhitelisted proto caches to size 0
  sctp: Copy struct sctp_sock.autoclose to userspace using put_user()
  sctp: Define usercopy region in SCTP proto slab cache
  caif: Define usercopy region in caif proto slab cache
  ip: Define usercopy region in IP proto slab cache
  net: Define usercopy region in struct proto slab cache
  scsi: Define usercopy region in scsi_sense_cache slab cache
  cifs: Define usercopy region in cifs_request slab cache
  vxfs: Define usercopy region in vxfs_inode slab cache
  ufs: Define usercopy region in ufs_inode_cache slab cache
  ...

30 files changed:
1  2 
arch/Kconfig
arch/arm/Kconfig
arch/arm64/Kconfig
arch/arm64/include/asm/processor.h
arch/x86/Kconfig
arch/x86/include/asm/processor.h
arch/x86/kvm/x86.c
drivers/misc/lkdtm_core.c
drivers/scsi/scsi_lib.c
fs/cifs/cifsfs.c
fs/dcache.c
fs/exofs/super.c
fs/ext2/super.c
fs/ext4/super.c
fs/ufs/super.c
include/net/sctp/structs.h
include/net/sock.h
kernel/fork.c
mm/slab.c
mm/slab.h
mm/slab_common.c
mm/slub.c
net/caif/caif_socket.c
net/core/sock.c
net/ipv4/raw.c
net/ipv6/raw.c
net/sctp/socket.c
security/Kconfig
tools/objtool/check.c
virt/kvm/kvm_main.c

diff --cc arch/Kconfig
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
diff --cc fs/dcache.c
Simple merge
Simple merge
diff --cc fs/ext2/super.c
Simple merge
diff --cc fs/ext4/super.c
Simple merge
diff --cc fs/ufs/super.c
Simple merge
Simple merge
Simple merge
diff --cc kernel/fork.c
Simple merge
diff --cc mm/slab.c
Simple merge
diff --cc mm/slab.h
Simple merge
@@@ -366,9 -348,37 +377,10 @@@ struct kmem_cache *find_mergeable(size_
        return NULL;
  }
  
 -/*
 - * Figure out what the alignment of the objects will be given a set of
 - * flags, a user specified alignment and the size of the objects.
 - */
 -unsigned long calculate_alignment(slab_flags_t flags,
 -              unsigned long align, unsigned long size)
 -{
 -      /*
 -       * If the user wants hardware cache aligned objects then follow that
 -       * suggestion if the object is sufficiently large.
 -       *
 -       * The hardware cache alignment cannot override the specified
 -       * alignment though. If that is greater then use it.
 -       */
 -      if (flags & SLAB_HWCACHE_ALIGN) {
 -              unsigned long ralign = cache_line_size();
 -              while (size <= ralign / 2)
 -                      ralign /= 2;
 -              align = max(align, ralign);
 -      }
 -
 -      if (align < ARCH_SLAB_MINALIGN)
 -              align = ARCH_SLAB_MINALIGN;
 -
 -      return ALIGN(align, sizeof(void *));
 -}
 -
  static struct kmem_cache *create_cache(const char *name,
                size_t object_size, size_t size, size_t align,
-               slab_flags_t flags, void (*ctor)(void *),
+               slab_flags_t flags, size_t useroffset,
+               size_t usersize, void (*ctor)(void *),
                struct mem_cgroup *memcg, struct kmem_cache *root_cache)
  {
        struct kmem_cache *s;
diff --cc mm/slub.c
Simple merge
Simple merge
diff --cc net/core/sock.c
Simple merge
diff --cc net/ipv4/raw.c
Simple merge
diff --cc net/ipv6/raw.c
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge