|
Message-Id: <20181011233117.7883-3-rick.p.edgecombe@intel.com> Date: Thu, 11 Oct 2018 16:31:12 -0700 From: Rick Edgecombe <rick.p.edgecombe@...el.com> To: kernel-hardening@...ts.openwall.com, daniel@...earbox.net, keescook@...omium.org, catalin.marinas@....com, will.deacon@....com, davem@...emloft.net, tglx@...utronix.de, mingo@...hat.com, bp@...en8.de, x86@...nel.org, arnd@...db.de, jeyu@...nel.org, linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org, linux-mips@...ux-mips.org, linux-s390@...r.kernel.org, sparclinux@...r.kernel.org, linux-fsdevel@...r.kernel.org, linux-arch@...r.kernel.org Cc: kristen@...ux.intel.com, dave.hansen@...el.com, arjan@...ux.intel.com, deneen.t.dock@...el.com, Rick Edgecombe <rick.p.edgecombe@...el.com> Subject: [PATCH v2 2/7] x86/modules: Add rlimit checking for x86 modules This adds in the rlimit checking for the x86 module allocator. Signed-off-by: Rick Edgecombe <rick.p.edgecombe@...el.com> --- arch/x86/include/asm/pgtable_32_types.h | 3 +++ arch/x86/include/asm/pgtable_64_types.h | 2 ++ arch/x86/kernel/module.c | 7 ++++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h index b0bc0fff5f1f..185e382fa8c3 100644 --- a/arch/x86/include/asm/pgtable_32_types.h +++ b/arch/x86/include/asm/pgtable_32_types.h @@ -68,6 +68,9 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */ #define MODULES_END VMALLOC_END #define MODULES_LEN (MODULES_VADDR - MODULES_END) +/* Half of 128MB vmalloc space */ +#define MODSPACE_LIMIT (1 << 25) + #define MAXMEM (VMALLOC_END - PAGE_OFFSET - __VMALLOC_RESERVE) #endif /* _ASM_X86_PGTABLE_32_DEFS_H */ diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h index 04edd2d58211..c256931f4667 100644 --- a/arch/x86/include/asm/pgtable_64_types.h +++ b/arch/x86/include/asm/pgtable_64_types.h @@ -143,6 +143,8 @@ extern unsigned int ptrs_per_p4d; #define MODULES_END _AC(0xffffffffff000000, UL) #define MODULES_LEN (MODULES_END - MODULES_VADDR) +#define MODSPACE_LIMIT (MODULES_LEN / 2) + #define ESPFIX_PGD_ENTRY _AC(-2, UL) #define ESPFIX_BASE_ADDR (ESPFIX_PGD_ENTRY << P4D_SHIFT) diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c index f58336af095c..5eb3f9c5a976 100644 --- a/arch/x86/kernel/module.c +++ b/arch/x86/kernel/module.c @@ -84,16 +84,21 @@ void *module_alloc(unsigned long size) if (PAGE_ALIGN(size) > MODULES_LEN) return NULL; + if (check_inc_mod_rlimit(size)) + return NULL; + p = __vmalloc_node_range(size, MODULE_ALIGN, MODULES_VADDR + get_module_load_offset(), MODULES_END, GFP_KERNEL, PAGE_KERNEL_EXEC, 0, NUMA_NO_NODE, __builtin_return_address(0)); if (p && (kasan_module_alloc(p, size) < 0)) { - vfree(p); + module_memfree(p); return NULL; } + update_mod_rlimit(p, size); + return p; } -- 2.17.1
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.