.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * VDSO implementations. |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (C) 2012 ARM Limited |
---|
5 | | - * |
---|
6 | | - * This program is free software; you can redistribute it and/or modify |
---|
7 | | - * it under the terms of the GNU General Public License version 2 as |
---|
8 | | - * published by the Free Software Foundation. |
---|
9 | | - * |
---|
10 | | - * This program is distributed in the hope that it will be useful, |
---|
11 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
13 | | - * GNU General Public License for more details. |
---|
14 | | - * |
---|
15 | | - * You should have received a copy of the GNU General Public License |
---|
16 | | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
17 | 6 | * |
---|
18 | 7 | * Author: Will Deacon <will.deacon@arm.com> |
---|
19 | 8 | */ |
---|
.. | .. |
---|
29 | 18 | #include <linux/sched.h> |
---|
30 | 19 | #include <linux/signal.h> |
---|
31 | 20 | #include <linux/slab.h> |
---|
| 21 | +#include <linux/time_namespace.h> |
---|
32 | 22 | #include <linux/timekeeper_internal.h> |
---|
33 | 23 | #include <linux/vmalloc.h> |
---|
34 | 24 | #include <vdso/datapage.h> |
---|
.. | .. |
---|
40 | 30 | #include <asm/vdso.h> |
---|
41 | 31 | |
---|
42 | 32 | extern char vdso_start[], vdso_end[]; |
---|
43 | | -#ifdef CONFIG_COMPAT_VDSO |
---|
44 | 33 | extern char vdso32_start[], vdso32_end[]; |
---|
45 | | -#endif /* CONFIG_COMPAT_VDSO */ |
---|
46 | 34 | |
---|
47 | | -/* vdso_lookup arch_index */ |
---|
48 | | -enum arch_vdso_type { |
---|
49 | | - ARM64_VDSO = 0, |
---|
50 | | -#ifdef CONFIG_COMPAT_VDSO |
---|
51 | | - ARM64_VDSO32 = 1, |
---|
52 | | -#endif /* CONFIG_COMPAT_VDSO */ |
---|
| 35 | +enum vdso_abi { |
---|
| 36 | + VDSO_ABI_AA64, |
---|
| 37 | + VDSO_ABI_AA32, |
---|
53 | 38 | }; |
---|
54 | | -#ifdef CONFIG_COMPAT_VDSO |
---|
55 | | -#define VDSO_TYPES (ARM64_VDSO32 + 1) |
---|
56 | | -#else |
---|
57 | | -#define VDSO_TYPES (ARM64_VDSO + 1) |
---|
58 | | -#endif /* CONFIG_COMPAT_VDSO */ |
---|
59 | 39 | |
---|
60 | | -struct __vdso_abi { |
---|
| 40 | +enum vvar_pages { |
---|
| 41 | + VVAR_DATA_PAGE_OFFSET, |
---|
| 42 | + VVAR_TIMENS_PAGE_OFFSET, |
---|
| 43 | + VVAR_NR_PAGES, |
---|
| 44 | +}; |
---|
| 45 | + |
---|
| 46 | +struct vdso_abi_info { |
---|
61 | 47 | const char *name; |
---|
62 | 48 | const char *vdso_code_start; |
---|
63 | 49 | const char *vdso_code_end; |
---|
.. | .. |
---|
68 | 54 | struct vm_special_mapping *cm; |
---|
69 | 55 | }; |
---|
70 | 56 | |
---|
71 | | -static struct __vdso_abi vdso_lookup[VDSO_TYPES] __ro_after_init = { |
---|
72 | | - { |
---|
| 57 | +static struct vdso_abi_info vdso_info[] __ro_after_init = { |
---|
| 58 | + [VDSO_ABI_AA64] = { |
---|
73 | 59 | .name = "vdso", |
---|
74 | 60 | .vdso_code_start = vdso_start, |
---|
75 | 61 | .vdso_code_end = vdso_end, |
---|
76 | 62 | }, |
---|
77 | 63 | #ifdef CONFIG_COMPAT_VDSO |
---|
78 | | - { |
---|
| 64 | + [VDSO_ABI_AA32] = { |
---|
79 | 65 | .name = "vdso32", |
---|
80 | 66 | .vdso_code_start = vdso32_start, |
---|
81 | 67 | .vdso_code_end = vdso32_end, |
---|
.. | .. |
---|
92 | 78 | } vdso_data_store __page_aligned_data; |
---|
93 | 79 | struct vdso_data *vdso_data = vdso_data_store.data; |
---|
94 | 80 | |
---|
95 | | -static int __vdso_remap(enum arch_vdso_type arch_index, |
---|
| 81 | +static int __vdso_remap(enum vdso_abi abi, |
---|
96 | 82 | const struct vm_special_mapping *sm, |
---|
97 | 83 | struct vm_area_struct *new_vma) |
---|
98 | 84 | { |
---|
99 | 85 | unsigned long new_size = new_vma->vm_end - new_vma->vm_start; |
---|
100 | | - unsigned long vdso_size = vdso_lookup[arch_index].vdso_code_end - |
---|
101 | | - vdso_lookup[arch_index].vdso_code_start; |
---|
| 86 | + unsigned long vdso_size = vdso_info[abi].vdso_code_end - |
---|
| 87 | + vdso_info[abi].vdso_code_start; |
---|
102 | 88 | |
---|
103 | 89 | if (vdso_size != new_size) |
---|
104 | 90 | return -EINVAL; |
---|
.. | .. |
---|
108 | 94 | return 0; |
---|
109 | 95 | } |
---|
110 | 96 | |
---|
111 | | -static int __vdso_init(enum arch_vdso_type arch_index) |
---|
| 97 | +static int __vdso_init(enum vdso_abi abi) |
---|
112 | 98 | { |
---|
113 | 99 | int i; |
---|
114 | 100 | struct page **vdso_pagelist; |
---|
115 | 101 | unsigned long pfn; |
---|
116 | 102 | |
---|
117 | | - if (memcmp(vdso_lookup[arch_index].vdso_code_start, "\177ELF", 4)) { |
---|
| 103 | + if (memcmp(vdso_info[abi].vdso_code_start, "\177ELF", 4)) { |
---|
118 | 104 | pr_err("vDSO is not a valid ELF object!\n"); |
---|
119 | 105 | return -EINVAL; |
---|
120 | 106 | } |
---|
121 | 107 | |
---|
122 | | - vdso_lookup[arch_index].vdso_pages = ( |
---|
123 | | - vdso_lookup[arch_index].vdso_code_end - |
---|
124 | | - vdso_lookup[arch_index].vdso_code_start) >> |
---|
| 108 | + vdso_info[abi].vdso_pages = ( |
---|
| 109 | + vdso_info[abi].vdso_code_end - |
---|
| 110 | + vdso_info[abi].vdso_code_start) >> |
---|
125 | 111 | PAGE_SHIFT; |
---|
126 | 112 | |
---|
127 | | - /* Allocate the vDSO pagelist, plus a page for the data. */ |
---|
128 | | - vdso_pagelist = kcalloc(vdso_lookup[arch_index].vdso_pages + 1, |
---|
| 113 | + vdso_pagelist = kcalloc(vdso_info[abi].vdso_pages, |
---|
129 | 114 | sizeof(struct page *), |
---|
130 | 115 | GFP_KERNEL); |
---|
131 | 116 | if (vdso_pagelist == NULL) |
---|
132 | 117 | return -ENOMEM; |
---|
133 | 118 | |
---|
134 | | - /* Grab the vDSO data page. */ |
---|
135 | | - vdso_pagelist[0] = phys_to_page(__pa_symbol(vdso_data)); |
---|
136 | | - |
---|
137 | | - |
---|
138 | 119 | /* Grab the vDSO code pages. */ |
---|
139 | | - pfn = sym_to_pfn(vdso_lookup[arch_index].vdso_code_start); |
---|
| 120 | + pfn = sym_to_pfn(vdso_info[abi].vdso_code_start); |
---|
140 | 121 | |
---|
141 | | - for (i = 0; i < vdso_lookup[arch_index].vdso_pages; i++) |
---|
142 | | - vdso_pagelist[i + 1] = pfn_to_page(pfn + i); |
---|
| 122 | + for (i = 0; i < vdso_info[abi].vdso_pages; i++) |
---|
| 123 | + vdso_pagelist[i] = pfn_to_page(pfn + i); |
---|
143 | 124 | |
---|
144 | | - vdso_lookup[arch_index].dm->pages = &vdso_pagelist[0]; |
---|
145 | | - vdso_lookup[arch_index].cm->pages = &vdso_pagelist[1]; |
---|
| 125 | + vdso_info[abi].cm->pages = vdso_pagelist; |
---|
146 | 126 | |
---|
147 | 127 | return 0; |
---|
148 | 128 | } |
---|
149 | 129 | |
---|
150 | | -static int __setup_additional_pages(enum arch_vdso_type arch_index, |
---|
| 130 | +#ifdef CONFIG_TIME_NS |
---|
| 131 | +struct vdso_data *arch_get_vdso_data(void *vvar_page) |
---|
| 132 | +{ |
---|
| 133 | + return (struct vdso_data *)(vvar_page); |
---|
| 134 | +} |
---|
| 135 | + |
---|
| 136 | +/* |
---|
| 137 | + * The vvar mapping contains data for a specific time namespace, so when a task |
---|
| 138 | + * changes namespace we must unmap its vvar data for the old namespace. |
---|
| 139 | + * Subsequent faults will map in data for the new namespace. |
---|
| 140 | + * |
---|
| 141 | + * For more details see timens_setup_vdso_data(). |
---|
| 142 | + */ |
---|
| 143 | +int vdso_join_timens(struct task_struct *task, struct time_namespace *ns) |
---|
| 144 | +{ |
---|
| 145 | + struct mm_struct *mm = task->mm; |
---|
| 146 | + struct vm_area_struct *vma; |
---|
| 147 | + |
---|
| 148 | + mmap_read_lock(mm); |
---|
| 149 | + |
---|
| 150 | + for (vma = mm->mmap; vma; vma = vma->vm_next) { |
---|
| 151 | + unsigned long size = vma->vm_end - vma->vm_start; |
---|
| 152 | + |
---|
| 153 | + if (vma_is_special_mapping(vma, vdso_info[VDSO_ABI_AA64].dm)) |
---|
| 154 | + zap_page_range(vma, vma->vm_start, size); |
---|
| 155 | +#ifdef CONFIG_COMPAT_VDSO |
---|
| 156 | + if (vma_is_special_mapping(vma, vdso_info[VDSO_ABI_AA32].dm)) |
---|
| 157 | + zap_page_range(vma, vma->vm_start, size); |
---|
| 158 | +#endif |
---|
| 159 | + } |
---|
| 160 | + |
---|
| 161 | + mmap_read_unlock(mm); |
---|
| 162 | + return 0; |
---|
| 163 | +} |
---|
| 164 | + |
---|
| 165 | +static struct page *find_timens_vvar_page(struct vm_area_struct *vma) |
---|
| 166 | +{ |
---|
| 167 | + if (likely(vma->vm_mm == current->mm)) |
---|
| 168 | + return current->nsproxy->time_ns->vvar_page; |
---|
| 169 | + |
---|
| 170 | + /* |
---|
| 171 | + * VM_PFNMAP | VM_IO protect .fault() handler from being called |
---|
| 172 | + * through interfaces like /proc/$pid/mem or |
---|
| 173 | + * process_vm_{readv,writev}() as long as there's no .access() |
---|
| 174 | + * in special_mapping_vmops. |
---|
| 175 | + * For more details check_vma_flags() and __access_remote_vm() |
---|
| 176 | + */ |
---|
| 177 | + WARN(1, "vvar_page accessed remotely"); |
---|
| 178 | + |
---|
| 179 | + return NULL; |
---|
| 180 | +} |
---|
| 181 | +#else |
---|
| 182 | +static struct page *find_timens_vvar_page(struct vm_area_struct *vma) |
---|
| 183 | +{ |
---|
| 184 | + return NULL; |
---|
| 185 | +} |
---|
| 186 | +#endif |
---|
| 187 | + |
---|
| 188 | +static vm_fault_t vvar_fault(const struct vm_special_mapping *sm, |
---|
| 189 | + struct vm_area_struct *vma, struct vm_fault *vmf) |
---|
| 190 | +{ |
---|
| 191 | + struct page *timens_page = find_timens_vvar_page(vma); |
---|
| 192 | + unsigned long pfn; |
---|
| 193 | + |
---|
| 194 | + switch (vmf->pgoff) { |
---|
| 195 | + case VVAR_DATA_PAGE_OFFSET: |
---|
| 196 | + if (timens_page) |
---|
| 197 | + pfn = page_to_pfn(timens_page); |
---|
| 198 | + else |
---|
| 199 | + pfn = sym_to_pfn(vdso_data); |
---|
| 200 | + break; |
---|
| 201 | +#ifdef CONFIG_TIME_NS |
---|
| 202 | + case VVAR_TIMENS_PAGE_OFFSET: |
---|
| 203 | + /* |
---|
| 204 | + * If a task belongs to a time namespace then a namespace |
---|
| 205 | + * specific VVAR is mapped with the VVAR_DATA_PAGE_OFFSET and |
---|
| 206 | + * the real VVAR page is mapped with the VVAR_TIMENS_PAGE_OFFSET |
---|
| 207 | + * offset. |
---|
| 208 | + * See also the comment near timens_setup_vdso_data(). |
---|
| 209 | + */ |
---|
| 210 | + if (!timens_page) |
---|
| 211 | + return VM_FAULT_SIGBUS; |
---|
| 212 | + pfn = sym_to_pfn(vdso_data); |
---|
| 213 | + break; |
---|
| 214 | +#endif /* CONFIG_TIME_NS */ |
---|
| 215 | + default: |
---|
| 216 | + return VM_FAULT_SIGBUS; |
---|
| 217 | + } |
---|
| 218 | + |
---|
| 219 | + return vmf_insert_pfn(vma, vmf->address, pfn); |
---|
| 220 | +} |
---|
| 221 | + |
---|
| 222 | +static int vvar_mremap(const struct vm_special_mapping *sm, |
---|
| 223 | + struct vm_area_struct *new_vma) |
---|
| 224 | +{ |
---|
| 225 | + unsigned long new_size = new_vma->vm_end - new_vma->vm_start; |
---|
| 226 | + |
---|
| 227 | + if (new_size != VVAR_NR_PAGES * PAGE_SIZE) |
---|
| 228 | + return -EINVAL; |
---|
| 229 | + |
---|
| 230 | + return 0; |
---|
| 231 | +} |
---|
| 232 | + |
---|
| 233 | +static int __setup_additional_pages(enum vdso_abi abi, |
---|
151 | 234 | struct mm_struct *mm, |
---|
152 | 235 | struct linux_binprm *bprm, |
---|
153 | 236 | int uses_interp) |
---|
154 | 237 | { |
---|
155 | 238 | unsigned long vdso_base, vdso_text_len, vdso_mapping_len; |
---|
| 239 | + unsigned long gp_flags = 0; |
---|
156 | 240 | void *ret; |
---|
157 | 241 | |
---|
158 | | - vdso_text_len = vdso_lookup[arch_index].vdso_pages << PAGE_SHIFT; |
---|
| 242 | + BUILD_BUG_ON(VVAR_NR_PAGES != __VVAR_PAGES); |
---|
| 243 | + |
---|
| 244 | + vdso_text_len = vdso_info[abi].vdso_pages << PAGE_SHIFT; |
---|
159 | 245 | /* Be sure to map the data page */ |
---|
160 | | - vdso_mapping_len = vdso_text_len + PAGE_SIZE; |
---|
| 246 | + vdso_mapping_len = vdso_text_len + VVAR_NR_PAGES * PAGE_SIZE; |
---|
161 | 247 | |
---|
162 | 248 | vdso_base = get_unmapped_area(NULL, 0, vdso_mapping_len, 0, 0); |
---|
163 | 249 | if (IS_ERR_VALUE(vdso_base)) { |
---|
.. | .. |
---|
165 | 251 | goto up_fail; |
---|
166 | 252 | } |
---|
167 | 253 | |
---|
168 | | - ret = _install_special_mapping(mm, vdso_base, PAGE_SIZE, |
---|
169 | | - VM_READ|VM_MAYREAD, |
---|
170 | | - vdso_lookup[arch_index].dm); |
---|
| 254 | + ret = _install_special_mapping(mm, vdso_base, VVAR_NR_PAGES * PAGE_SIZE, |
---|
| 255 | + VM_READ|VM_MAYREAD|VM_PFNMAP, |
---|
| 256 | + vdso_info[abi].dm); |
---|
171 | 257 | if (IS_ERR(ret)) |
---|
172 | 258 | goto up_fail; |
---|
173 | 259 | |
---|
174 | | - vdso_base += PAGE_SIZE; |
---|
| 260 | + if (IS_ENABLED(CONFIG_ARM64_BTI_KERNEL) && system_supports_bti()) |
---|
| 261 | + gp_flags = VM_ARM64_BTI; |
---|
| 262 | + |
---|
| 263 | + vdso_base += VVAR_NR_PAGES * PAGE_SIZE; |
---|
175 | 264 | mm->context.vdso = (void *)vdso_base; |
---|
176 | 265 | ret = _install_special_mapping(mm, vdso_base, vdso_text_len, |
---|
177 | | - VM_READ|VM_EXEC| |
---|
| 266 | + VM_READ|VM_EXEC|gp_flags| |
---|
178 | 267 | VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC, |
---|
179 | | - vdso_lookup[arch_index].cm); |
---|
| 268 | + vdso_info[abi].cm); |
---|
180 | 269 | if (IS_ERR(ret)) |
---|
181 | 270 | goto up_fail; |
---|
182 | 271 | |
---|
.. | .. |
---|
191 | 280 | /* |
---|
192 | 281 | * Create and map the vectors page for AArch32 tasks. |
---|
193 | 282 | */ |
---|
194 | | -#ifdef CONFIG_COMPAT_VDSO |
---|
195 | 283 | static int aarch32_vdso_mremap(const struct vm_special_mapping *sm, |
---|
196 | 284 | struct vm_area_struct *new_vma) |
---|
197 | 285 | { |
---|
198 | | - return __vdso_remap(ARM64_VDSO32, sm, new_vma); |
---|
| 286 | + return __vdso_remap(VDSO_ABI_AA32, sm, new_vma); |
---|
199 | 287 | } |
---|
200 | | -#endif /* CONFIG_COMPAT_VDSO */ |
---|
201 | 288 | |
---|
202 | | -/* |
---|
203 | | - * aarch32_vdso_pages: |
---|
204 | | - * 0 - kuser helpers |
---|
205 | | - * 1 - sigreturn code |
---|
206 | | - * or (CONFIG_COMPAT_VDSO): |
---|
207 | | - * 0 - kuser helpers |
---|
208 | | - * 1 - vdso data |
---|
209 | | - * 2 - vdso code |
---|
210 | | - */ |
---|
211 | | -#define C_VECTORS 0 |
---|
212 | | -#ifdef CONFIG_COMPAT_VDSO |
---|
213 | | -#define C_VVAR 1 |
---|
214 | | -#define C_VDSO 2 |
---|
215 | | -#define C_PAGES (C_VDSO + 1) |
---|
216 | | -#else |
---|
217 | | -#define C_SIGPAGE 1 |
---|
218 | | -#define C_PAGES (C_SIGPAGE + 1) |
---|
219 | | -#endif /* CONFIG_COMPAT_VDSO */ |
---|
220 | | -static struct page *aarch32_vdso_pages[C_PAGES] __ro_after_init; |
---|
221 | | -static struct vm_special_mapping aarch32_vdso_spec[C_PAGES] = { |
---|
222 | | - { |
---|
| 289 | +enum aarch32_map { |
---|
| 290 | + AA32_MAP_VECTORS, /* kuser helpers */ |
---|
| 291 | + AA32_MAP_SIGPAGE, |
---|
| 292 | + AA32_MAP_VVAR, |
---|
| 293 | + AA32_MAP_VDSO, |
---|
| 294 | +}; |
---|
| 295 | + |
---|
| 296 | +static struct page *aarch32_vectors_page __ro_after_init; |
---|
| 297 | +static struct page *aarch32_sig_page __ro_after_init; |
---|
| 298 | + |
---|
| 299 | +static struct vm_special_mapping aarch32_vdso_maps[] = { |
---|
| 300 | + [AA32_MAP_VECTORS] = { |
---|
223 | 301 | .name = "[vectors]", /* ABI */ |
---|
224 | | - .pages = &aarch32_vdso_pages[C_VECTORS], |
---|
| 302 | + .pages = &aarch32_vectors_page, |
---|
225 | 303 | }, |
---|
226 | | -#ifdef CONFIG_COMPAT_VDSO |
---|
227 | | - { |
---|
| 304 | + [AA32_MAP_SIGPAGE] = { |
---|
| 305 | + .name = "[sigpage]", /* ABI */ |
---|
| 306 | + .pages = &aarch32_sig_page, |
---|
| 307 | + }, |
---|
| 308 | + [AA32_MAP_VVAR] = { |
---|
228 | 309 | .name = "[vvar]", |
---|
| 310 | + .fault = vvar_fault, |
---|
| 311 | + .mremap = vvar_mremap, |
---|
229 | 312 | }, |
---|
230 | | - { |
---|
| 313 | + [AA32_MAP_VDSO] = { |
---|
231 | 314 | .name = "[vdso]", |
---|
232 | 315 | .mremap = aarch32_vdso_mremap, |
---|
233 | 316 | }, |
---|
234 | | -#else |
---|
235 | | - { |
---|
236 | | - .name = "[sigpage]", /* ABI */ |
---|
237 | | - .pages = &aarch32_vdso_pages[C_SIGPAGE], |
---|
238 | | - }, |
---|
239 | | -#endif /* CONFIG_COMPAT_VDSO */ |
---|
240 | 317 | }; |
---|
241 | 318 | |
---|
242 | 319 | static int aarch32_alloc_kuser_vdso_page(void) |
---|
.. | .. |
---|
254 | 331 | |
---|
255 | 332 | memcpy((void *)(vdso_page + 0x1000 - kuser_sz), __kuser_helper_start, |
---|
256 | 333 | kuser_sz); |
---|
257 | | - aarch32_vdso_pages[C_VECTORS] = virt_to_page(vdso_page); |
---|
258 | | - flush_dcache_page(aarch32_vdso_pages[C_VECTORS]); |
---|
| 334 | + aarch32_vectors_page = virt_to_page(vdso_page); |
---|
| 335 | + flush_dcache_page(aarch32_vectors_page); |
---|
259 | 336 | return 0; |
---|
260 | 337 | } |
---|
261 | 338 | |
---|
262 | | -#ifdef CONFIG_COMPAT_VDSO |
---|
263 | | -static int __aarch32_alloc_vdso_pages(void) |
---|
264 | | -{ |
---|
265 | | - int ret; |
---|
266 | | - |
---|
267 | | - vdso_lookup[ARM64_VDSO32].dm = &aarch32_vdso_spec[C_VVAR]; |
---|
268 | | - vdso_lookup[ARM64_VDSO32].cm = &aarch32_vdso_spec[C_VDSO]; |
---|
269 | | - |
---|
270 | | - ret = __vdso_init(ARM64_VDSO32); |
---|
271 | | - if (ret) |
---|
272 | | - return ret; |
---|
273 | | - |
---|
274 | | - return aarch32_alloc_kuser_vdso_page(); |
---|
275 | | -} |
---|
276 | | -#else |
---|
277 | | -static int __aarch32_alloc_vdso_pages(void) |
---|
| 339 | +static int aarch32_alloc_sigpage(void) |
---|
278 | 340 | { |
---|
279 | 341 | extern char __aarch32_sigret_code_start[], __aarch32_sigret_code_end[]; |
---|
280 | 342 | int sigret_sz = __aarch32_sigret_code_end - __aarch32_sigret_code_start; |
---|
281 | 343 | unsigned long sigpage; |
---|
282 | | - int ret; |
---|
283 | 344 | |
---|
284 | 345 | sigpage = get_zeroed_page(GFP_ATOMIC); |
---|
285 | 346 | if (!sigpage) |
---|
286 | 347 | return -ENOMEM; |
---|
287 | 348 | |
---|
288 | 349 | memcpy((void *)sigpage, __aarch32_sigret_code_start, sigret_sz); |
---|
289 | | - aarch32_vdso_pages[C_SIGPAGE] = virt_to_page(sigpage); |
---|
290 | | - flush_dcache_page(aarch32_vdso_pages[C_SIGPAGE]); |
---|
291 | | - |
---|
292 | | - ret = aarch32_alloc_kuser_vdso_page(); |
---|
293 | | - if (ret) |
---|
294 | | - free_page(sigpage); |
---|
295 | | - |
---|
296 | | - return ret; |
---|
| 350 | + aarch32_sig_page = virt_to_page(sigpage); |
---|
| 351 | + flush_dcache_page(aarch32_sig_page); |
---|
| 352 | + return 0; |
---|
297 | 353 | } |
---|
298 | | -#endif /* CONFIG_COMPAT_VDSO */ |
---|
| 354 | + |
---|
| 355 | +static int __aarch32_alloc_vdso_pages(void) |
---|
| 356 | +{ |
---|
| 357 | + |
---|
| 358 | + if (!IS_ENABLED(CONFIG_COMPAT_VDSO)) |
---|
| 359 | + return 0; |
---|
| 360 | + |
---|
| 361 | + vdso_info[VDSO_ABI_AA32].dm = &aarch32_vdso_maps[AA32_MAP_VVAR]; |
---|
| 362 | + vdso_info[VDSO_ABI_AA32].cm = &aarch32_vdso_maps[AA32_MAP_VDSO]; |
---|
| 363 | + |
---|
| 364 | + return __vdso_init(VDSO_ABI_AA32); |
---|
| 365 | +} |
---|
299 | 366 | |
---|
300 | 367 | static int __init aarch32_alloc_vdso_pages(void) |
---|
301 | 368 | { |
---|
302 | | - return __aarch32_alloc_vdso_pages(); |
---|
| 369 | + int ret; |
---|
| 370 | + |
---|
| 371 | + ret = __aarch32_alloc_vdso_pages(); |
---|
| 372 | + if (ret) |
---|
| 373 | + return ret; |
---|
| 374 | + |
---|
| 375 | + ret = aarch32_alloc_sigpage(); |
---|
| 376 | + if (ret) |
---|
| 377 | + return ret; |
---|
| 378 | + |
---|
| 379 | + return aarch32_alloc_kuser_vdso_page(); |
---|
303 | 380 | } |
---|
304 | 381 | arch_initcall(aarch32_alloc_vdso_pages); |
---|
305 | 382 | |
---|
.. | .. |
---|
317 | 394 | ret = _install_special_mapping(mm, AARCH32_VECTORS_BASE, PAGE_SIZE, |
---|
318 | 395 | VM_READ | VM_EXEC | |
---|
319 | 396 | VM_MAYREAD | VM_MAYEXEC, |
---|
320 | | - &aarch32_vdso_spec[C_VECTORS]); |
---|
| 397 | + &aarch32_vdso_maps[AA32_MAP_VECTORS]); |
---|
321 | 398 | |
---|
322 | 399 | return PTR_ERR_OR_ZERO(ret); |
---|
323 | 400 | } |
---|
324 | 401 | |
---|
325 | | -#ifndef CONFIG_COMPAT_VDSO |
---|
326 | 402 | static int aarch32_sigreturn_setup(struct mm_struct *mm) |
---|
327 | 403 | { |
---|
328 | 404 | unsigned long addr; |
---|
.. | .. |
---|
341 | 417 | ret = _install_special_mapping(mm, addr, PAGE_SIZE, |
---|
342 | 418 | VM_READ | VM_EXEC | VM_MAYREAD | |
---|
343 | 419 | VM_MAYWRITE | VM_MAYEXEC, |
---|
344 | | - &aarch32_vdso_spec[C_SIGPAGE]); |
---|
| 420 | + &aarch32_vdso_maps[AA32_MAP_SIGPAGE]); |
---|
345 | 421 | if (IS_ERR(ret)) |
---|
346 | 422 | goto out; |
---|
347 | 423 | |
---|
348 | | - mm->context.vdso = (void *)addr; |
---|
| 424 | + mm->context.sigpage = (void *)addr; |
---|
349 | 425 | |
---|
350 | 426 | out: |
---|
351 | 427 | return PTR_ERR_OR_ZERO(ret); |
---|
352 | 428 | } |
---|
353 | | -#endif /* !CONFIG_COMPAT_VDSO */ |
---|
354 | 429 | |
---|
355 | 430 | int aarch32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) |
---|
356 | 431 | { |
---|
357 | 432 | struct mm_struct *mm = current->mm; |
---|
358 | 433 | int ret; |
---|
359 | 434 | |
---|
360 | | - if (down_write_killable(&mm->mmap_sem)) |
---|
| 435 | + if (mmap_write_lock_killable(mm)) |
---|
361 | 436 | return -EINTR; |
---|
362 | 437 | |
---|
363 | 438 | ret = aarch32_kuser_helpers_setup(mm); |
---|
364 | 439 | if (ret) |
---|
365 | 440 | goto out; |
---|
366 | 441 | |
---|
367 | | -#ifdef CONFIG_COMPAT_VDSO |
---|
368 | | - ret = __setup_additional_pages(ARM64_VDSO32, |
---|
369 | | - mm, |
---|
370 | | - bprm, |
---|
371 | | - uses_interp); |
---|
372 | | -#else |
---|
373 | | - ret = aarch32_sigreturn_setup(mm); |
---|
374 | | -#endif /* CONFIG_COMPAT_VDSO */ |
---|
| 442 | + if (IS_ENABLED(CONFIG_COMPAT_VDSO)) { |
---|
| 443 | + ret = __setup_additional_pages(VDSO_ABI_AA32, mm, bprm, |
---|
| 444 | + uses_interp); |
---|
| 445 | + if (ret) |
---|
| 446 | + goto out; |
---|
| 447 | + } |
---|
375 | 448 | |
---|
| 449 | + ret = aarch32_sigreturn_setup(mm); |
---|
376 | 450 | out: |
---|
377 | | - up_write(&mm->mmap_sem); |
---|
| 451 | + mmap_write_unlock(mm); |
---|
378 | 452 | return ret; |
---|
379 | 453 | } |
---|
380 | 454 | #endif /* CONFIG_COMPAT */ |
---|
.. | .. |
---|
382 | 456 | static int vdso_mremap(const struct vm_special_mapping *sm, |
---|
383 | 457 | struct vm_area_struct *new_vma) |
---|
384 | 458 | { |
---|
385 | | - return __vdso_remap(ARM64_VDSO, sm, new_vma); |
---|
| 459 | + return __vdso_remap(VDSO_ABI_AA64, sm, new_vma); |
---|
386 | 460 | } |
---|
387 | 461 | |
---|
388 | | -/* |
---|
389 | | - * aarch64_vdso_pages: |
---|
390 | | - * 0 - vvar |
---|
391 | | - * 1 - vdso |
---|
392 | | - */ |
---|
393 | | -#define A_VVAR 0 |
---|
394 | | -#define A_VDSO 1 |
---|
395 | | -#define A_PAGES (A_VDSO + 1) |
---|
396 | | -static struct vm_special_mapping vdso_spec[A_PAGES] __ro_after_init = { |
---|
397 | | - { |
---|
| 462 | +enum aarch64_map { |
---|
| 463 | + AA64_MAP_VVAR, |
---|
| 464 | + AA64_MAP_VDSO, |
---|
| 465 | +}; |
---|
| 466 | + |
---|
| 467 | +static struct vm_special_mapping aarch64_vdso_maps[] __ro_after_init = { |
---|
| 468 | + [AA64_MAP_VVAR] = { |
---|
398 | 469 | .name = "[vvar]", |
---|
| 470 | + .fault = vvar_fault, |
---|
| 471 | + .mremap = vvar_mremap, |
---|
399 | 472 | }, |
---|
400 | | - { |
---|
| 473 | + [AA64_MAP_VDSO] = { |
---|
401 | 474 | .name = "[vdso]", |
---|
402 | 475 | .mremap = vdso_mremap, |
---|
403 | 476 | }, |
---|
.. | .. |
---|
405 | 478 | |
---|
406 | 479 | static int __init vdso_init(void) |
---|
407 | 480 | { |
---|
408 | | - vdso_lookup[ARM64_VDSO].dm = &vdso_spec[A_VVAR]; |
---|
409 | | - vdso_lookup[ARM64_VDSO].cm = &vdso_spec[A_VDSO]; |
---|
| 481 | + vdso_info[VDSO_ABI_AA64].dm = &aarch64_vdso_maps[AA64_MAP_VVAR]; |
---|
| 482 | + vdso_info[VDSO_ABI_AA64].cm = &aarch64_vdso_maps[AA64_MAP_VDSO]; |
---|
410 | 483 | |
---|
411 | | - return __vdso_init(ARM64_VDSO); |
---|
| 484 | + return __vdso_init(VDSO_ABI_AA64); |
---|
412 | 485 | } |
---|
413 | 486 | arch_initcall(vdso_init); |
---|
414 | 487 | |
---|
415 | | -int arch_setup_additional_pages(struct linux_binprm *bprm, |
---|
416 | | - int uses_interp) |
---|
| 488 | +int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) |
---|
417 | 489 | { |
---|
418 | 490 | struct mm_struct *mm = current->mm; |
---|
419 | 491 | int ret; |
---|
420 | 492 | |
---|
421 | | - if (down_write_killable(&mm->mmap_sem)) |
---|
| 493 | + if (mmap_write_lock_killable(mm)) |
---|
422 | 494 | return -EINTR; |
---|
423 | 495 | |
---|
424 | | - ret = __setup_additional_pages(ARM64_VDSO, |
---|
425 | | - mm, |
---|
426 | | - bprm, |
---|
427 | | - uses_interp); |
---|
428 | | - |
---|
429 | | - up_write(&mm->mmap_sem); |
---|
| 496 | + ret = __setup_additional_pages(VDSO_ABI_AA64, mm, bprm, uses_interp); |
---|
| 497 | + mmap_write_unlock(mm); |
---|
430 | 498 | |
---|
431 | 499 | return ret; |
---|
432 | 500 | } |
---|