mirror of
https://github.com/team-infusion-developers/android_kernel_samsung_msm8976.git
synced 2024-10-31 18:09:19 +00:00
Merge "kasan, module, vmalloc: rework shadow allocation for modules"
This commit is contained in:
commit
76a448c498
5 changed files with 17 additions and 7 deletions
|
@ -5,6 +5,7 @@
|
|||
|
||||
struct kmem_cache;
|
||||
struct page;
|
||||
struct vm_struct;
|
||||
|
||||
#ifdef CONFIG_KASAN
|
||||
|
||||
|
@ -52,7 +53,7 @@ void kasan_slab_free(struct kmem_cache *s, void *object);
|
|||
#define MODULE_ALIGN (PAGE_SIZE << KASAN_SHADOW_SCALE_SHIFT)
|
||||
|
||||
int kasan_module_alloc(void *addr, size_t size);
|
||||
void kasan_module_free(void *addr);
|
||||
void kasan_free_shadow(const struct vm_struct *vm);
|
||||
|
||||
#else /* CONFIG_KASAN */
|
||||
|
||||
|
@ -82,7 +83,7 @@ static inline void kasan_slab_alloc(struct kmem_cache *s, void *object) {}
|
|||
static inline void kasan_slab_free(struct kmem_cache *s, void *object) {}
|
||||
|
||||
static inline int kasan_module_alloc(void *addr, size_t size) { return 0; }
|
||||
static inline void kasan_module_free(void *addr) {}
|
||||
static inline void kasan_free_shadow(const struct vm_struct *vm) {}
|
||||
|
||||
#endif /* CONFIG_KASAN */
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
|
|||
#define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
|
||||
#define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
|
||||
#define VM_LOWMEM 0x00000040 /* Tracking of direct mapped lowmem */
|
||||
#define VM_KASAN 0x00000080 /* has allocated kasan shadow memory */
|
||||
/* bits [20..32] reserved for arch specific ioremap internals */
|
||||
|
||||
/*
|
||||
|
|
|
@ -57,7 +57,6 @@
|
|||
#include <linux/async.h>
|
||||
#include <linux/percpu.h>
|
||||
#include <linux/kmemleak.h>
|
||||
#include <linux/kasan.h>
|
||||
#include <linux/jump_label.h>
|
||||
#include <linux/pfn.h>
|
||||
#include <linux/bsearch.h>
|
||||
|
@ -1852,7 +1851,6 @@ static void unset_module_init_ro_nx(struct module *mod) { }
|
|||
void __weak module_free(struct module *mod, void *module_region)
|
||||
{
|
||||
vfree(module_region);
|
||||
kasan_module_free(module_region);
|
||||
}
|
||||
|
||||
void __weak module_arch_cleanup(struct module *mod)
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include <linux/stacktrace.h>
|
||||
#include <linux/string.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/vmalloc.h>
|
||||
#include <linux/kasan.h>
|
||||
|
||||
#include "kasan.h"
|
||||
|
@ -414,12 +415,19 @@ int kasan_module_alloc(void *addr, size_t size)
|
|||
GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
|
||||
PAGE_KERNEL, VM_NO_GUARD, NUMA_NO_NODE,
|
||||
__builtin_return_address(0));
|
||||
return ret ? 0 : -ENOMEM;
|
||||
|
||||
if (ret) {
|
||||
find_vm_area(addr)->flags |= VM_KASAN;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
void kasan_module_free(void *addr)
|
||||
void kasan_free_shadow(const struct vm_struct *vm)
|
||||
{
|
||||
vfree(kasan_mem_to_shadow(addr));
|
||||
if (vm->flags & VM_KASAN)
|
||||
vfree(kasan_mem_to_shadow(vm->addr));
|
||||
}
|
||||
|
||||
static void register_global(struct kasan_global *global)
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include <linux/seq_file.h>
|
||||
#include <linux/debugobjects.h>
|
||||
#include <linux/kallsyms.h>
|
||||
#include <linux/kasan.h>
|
||||
#include <linux/list.h>
|
||||
#include <linux/rbtree.h>
|
||||
#include <linux/radix-tree.h>
|
||||
|
@ -1559,6 +1560,7 @@ struct vm_struct *remove_vm_area(const void *addr)
|
|||
spin_unlock(&vmap_area_lock);
|
||||
|
||||
vmap_debug_free_range(va->va_start, va->va_end);
|
||||
kasan_free_shadow(vm);
|
||||
free_unmap_vmap_area(va);
|
||||
vm->size -= PAGE_SIZE;
|
||||
|
||||
|
|
Loading…
Reference in a new issue