|
23 | 23 | */
|
24 | 24 | #include <linux/module.h>
|
25 | 25 | #include <linux/errno.h>
|
| 26 | +#include <linux/kasan.h> |
26 | 27 | #include <linux/mm.h>
|
27 | 28 | #include <linux/vmalloc.h>
|
28 | 29 | #include <linux/io.h>
|
@@ -115,16 +116,40 @@ int ioremap_page(unsigned long virt, unsigned long phys,
|
115 | 116 | }
|
116 | 117 | EXPORT_SYMBOL(ioremap_page);
|
117 | 118 |
|
| 119 | +#ifdef CONFIG_KASAN |
| 120 | +static unsigned long arm_kasan_mem_to_shadow(unsigned long addr) |
| 121 | +{ |
| 122 | + return (unsigned long)kasan_mem_to_shadow((void *)addr); |
| 123 | +} |
| 124 | +#else |
| 125 | +static unsigned long arm_kasan_mem_to_shadow(unsigned long addr) |
| 126 | +{ |
| 127 | + return 0; |
| 128 | +} |
| 129 | +#endif |
| 130 | + |
| 131 | +static void memcpy_pgd(struct mm_struct *mm, unsigned long start, |
| 132 | + unsigned long end) |
| 133 | +{ |
| 134 | + end = ALIGN(end, PGDIR_SIZE); |
| 135 | + memcpy(pgd_offset(mm, start), pgd_offset_k(start), |
| 136 | + sizeof(pgd_t) * (pgd_index(end) - pgd_index(start))); |
| 137 | +} |
| 138 | + |
118 | 139 | void __check_vmalloc_seq(struct mm_struct *mm)
|
119 | 140 | {
|
120 | 141 | int seq;
|
121 | 142 |
|
122 | 143 | do {
|
123 | 144 | seq = atomic_read(&init_mm.context.vmalloc_seq);
|
124 |
| - memcpy(pgd_offset(mm, VMALLOC_START), |
125 |
| - pgd_offset_k(VMALLOC_START), |
126 |
| - sizeof(pgd_t) * (pgd_index(VMALLOC_END) - |
127 |
| - pgd_index(VMALLOC_START))); |
| 145 | + memcpy_pgd(mm, VMALLOC_START, VMALLOC_END); |
| 146 | + if (IS_ENABLED(CONFIG_KASAN_VMALLOC)) { |
| 147 | + unsigned long start = |
| 148 | + arm_kasan_mem_to_shadow(VMALLOC_START); |
| 149 | + unsigned long end = |
| 150 | + arm_kasan_mem_to_shadow(VMALLOC_END); |
| 151 | + memcpy_pgd(mm, start, end); |
| 152 | + } |
128 | 153 | /*
|
129 | 154 | * Use a store-release so that other CPUs that observe the
|
130 | 155 | * counter's new value are guaranteed to see the results of the
|
|
0 commit comments