Skip to content

Commit 617aebe

Browse files
committed
Merge tag 'usercopy-v4.16-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux
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 ...
2 parents 0771ad4 + e47e311 commit 617aebe

45 files changed

Lines changed: 515 additions & 215 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎arch/Kconfig‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,17 @@ config ARCH_TASK_STRUCT_ON_STACK
245245
config ARCH_TASK_STRUCT_ALLOCATOR
246246
bool
247247

248+
config HAVE_ARCH_THREAD_STRUCT_WHITELIST
249+
bool
250+
depends on !ARCH_TASK_STRUCT_ALLOCATOR
251+
help
252+
An architecture should select this to provide hardened usercopy
253+
knowledge about what region of the thread_struct should be
254+
whitelisted for copying to userspace. Normally this is only the
255+
FPU registers. Specifically, arch_thread_struct_whitelist()
256+
should be implemented. Without this, the entire thread_struct
257+
field in task_struct will be left whitelisted.
258+
248259
# Select if arch has its private alloc_thread_stack() function
249260
config ARCH_THREAD_STACK_ALLOCATOR
250261
bool

‎arch/arm/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ config ARM
5151
select HAVE_ARCH_KGDB if !CPU_ENDIAN_BE32 && MMU
5252
select HAVE_ARCH_MMAP_RND_BITS if MMU
5353
select HAVE_ARCH_SECCOMP_FILTER if (AEABI && !OABI_COMPAT)
54+
select HAVE_ARCH_THREAD_STRUCT_WHITELIST
5455
select HAVE_ARCH_TRACEHOOK
5556
select HAVE_ARM_SMCCC if CPU_V7
5657
select HAVE_EBPF_JIT if !CPU_ENDIAN_BE32

‎arch/arm/include/asm/processor.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ struct thread_struct {
4545
struct debug_info debug;
4646
};
4747

48+
/*
49+
* Everything usercopied to/from thread_struct is statically-sized, so
50+
* no hardened usercopy whitelist is needed.
51+
*/
52+
static inline void arch_thread_struct_whitelist(unsigned long *offset,
53+
unsigned long *size)
54+
{
55+
*offset = *size = 0;
56+
}
57+
4858
#define INIT_THREAD { }
4959

5060
#define start_thread(regs,pc,sp) \

‎arch/arm64/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ config ARM64
9191
select HAVE_ARCH_MMAP_RND_BITS
9292
select HAVE_ARCH_MMAP_RND_COMPAT_BITS if COMPAT
9393
select HAVE_ARCH_SECCOMP_FILTER
94+
select HAVE_ARCH_THREAD_STRUCT_WHITELIST
9495
select HAVE_ARCH_TRACEHOOK
9596
select HAVE_ARCH_TRANSPARENT_HUGEPAGE
9697
select HAVE_ARCH_VMAP_STACK

‎arch/arm64/include/asm/processor.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,16 @@ struct thread_struct {
113113
struct debug_info debug; /* debugging */
114114
};
115115

116+
/*
117+
* Everything usercopied to/from thread_struct is statically-sized, so
118+
* no hardened usercopy whitelist is needed.
119+
*/
120+
static inline void arch_thread_struct_whitelist(unsigned long *offset,
121+
unsigned long *size)
122+
{
123+
*offset = *size = 0;
124+
}
125+
116126
#ifdef CONFIG_COMPAT
117127
#define task_user_tls(t) \
118128
({ \

‎arch/x86/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ config X86
116116
select HAVE_ARCH_MMAP_RND_COMPAT_BITS if MMU && COMPAT
117117
select HAVE_ARCH_COMPAT_MMAP_BASES if MMU && COMPAT
118118
select HAVE_ARCH_SECCOMP_FILTER
119+
select HAVE_ARCH_THREAD_STRUCT_WHITELIST
119120
select HAVE_ARCH_TRACEHOOK
120121
select HAVE_ARCH_TRANSPARENT_HUGEPAGE
121122
select HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD if X86_64

‎arch/x86/include/asm/processor.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,14 @@ struct thread_struct {
507507
*/
508508
};
509509

510+
/* Whitelist the FPU state from the task_struct for hardened usercopy. */
511+
static inline void arch_thread_struct_whitelist(unsigned long *offset,
512+
unsigned long *size)
513+
{
514+
*offset = offsetof(struct thread_struct, fpu.state);
515+
*size = fpu_kernel_xstate_size;
516+
}
517+
510518
/*
511519
* Thread-synchronous status.
512520
*

‎arch/x86/kvm/x86.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4237,13 +4237,14 @@ long kvm_arch_vm_ioctl(struct file *filp,
42374237
mutex_unlock(&kvm->lock);
42384238
break;
42394239
case KVM_XEN_HVM_CONFIG: {
4240+
struct kvm_xen_hvm_config xhc;
42404241
r = -EFAULT;
4241-
if (copy_from_user(&kvm->arch.xen_hvm_config, argp,
4242-
sizeof(struct kvm_xen_hvm_config)))
4242+
if (copy_from_user(&xhc, argp, sizeof(xhc)))
42434243
goto out;
42444244
r = -EINVAL;
4245-
if (kvm->arch.xen_hvm_config.flags)
4245+
if (xhc.flags)
42464246
goto out;
4247+
memcpy(&kvm->arch.xen_hvm_config, &xhc, sizeof(xhc));
42474248
r = 0;
42484249
break;
42494250
}

‎drivers/misc/lkdtm.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ void __init lkdtm_usercopy_init(void);
7676
void __exit lkdtm_usercopy_exit(void);
7777
void lkdtm_USERCOPY_HEAP_SIZE_TO(void);
7878
void lkdtm_USERCOPY_HEAP_SIZE_FROM(void);
79-
void lkdtm_USERCOPY_HEAP_FLAG_TO(void);
80-
void lkdtm_USERCOPY_HEAP_FLAG_FROM(void);
79+
void lkdtm_USERCOPY_HEAP_WHITELIST_TO(void);
80+
void lkdtm_USERCOPY_HEAP_WHITELIST_FROM(void);
8181
void lkdtm_USERCOPY_STACK_FRAME_TO(void);
8282
void lkdtm_USERCOPY_STACK_FRAME_FROM(void);
8383
void lkdtm_USERCOPY_STACK_BEYOND(void);

‎drivers/misc/lkdtm_core.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ static const struct crashtype crashtypes[] = {
177177
CRASHTYPE(ATOMIC_TIMING),
178178
CRASHTYPE(USERCOPY_HEAP_SIZE_TO),
179179
CRASHTYPE(USERCOPY_HEAP_SIZE_FROM),
180-
CRASHTYPE(USERCOPY_HEAP_FLAG_TO),
181-
CRASHTYPE(USERCOPY_HEAP_FLAG_FROM),
180+
CRASHTYPE(USERCOPY_HEAP_WHITELIST_TO),
181+
CRASHTYPE(USERCOPY_HEAP_WHITELIST_FROM),
182182
CRASHTYPE(USERCOPY_STACK_FRAME_TO),
183183
CRASHTYPE(USERCOPY_STACK_FRAME_FROM),
184184
CRASHTYPE(USERCOPY_STACK_BEYOND),

0 commit comments

Comments
 (0)