.. | .. |
---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-only */ |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright (C) 2012 ARM Ltd. |
---|
3 | | - * |
---|
4 | | - * This program is free software; you can redistribute it and/or modify |
---|
5 | | - * it under the terms of the GNU General Public License version 2 as |
---|
6 | | - * published by the Free Software Foundation. |
---|
7 | | - * |
---|
8 | | - * This program is distributed in the hope that it will be useful, |
---|
9 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
10 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
11 | | - * GNU General Public License for more details. |
---|
12 | | - * |
---|
13 | | - * You should have received a copy of the GNU General Public License |
---|
14 | | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
15 | 4 | */ |
---|
16 | 5 | #ifndef __ASM_ELF_H |
---|
17 | 6 | #define __ASM_ELF_H |
---|
.. | .. |
---|
107 | 96 | */ |
---|
108 | 97 | #define elf_check_arch(x) ((x)->e_machine == EM_AARCH64) |
---|
109 | 98 | |
---|
110 | | -#define elf_read_implies_exec(ex,stk) (stk != EXSTACK_DISABLE_X) |
---|
| 99 | +/* |
---|
| 100 | + * An executable for which elf_read_implies_exec() returns TRUE will |
---|
| 101 | + * have the READ_IMPLIES_EXEC personality flag set automatically. |
---|
| 102 | + * |
---|
| 103 | + * The decision process for determining the results are: |
---|
| 104 | + * |
---|
| 105 | + * CPU*: | arm32 | arm64 | |
---|
| 106 | + * ELF: | | | |
---|
| 107 | + * ---------------------|------------|------------| |
---|
| 108 | + * missing PT_GNU_STACK | exec-all | exec-none | |
---|
| 109 | + * PT_GNU_STACK == RWX | exec-stack | exec-stack | |
---|
| 110 | + * PT_GNU_STACK == RW | exec-none | exec-none | |
---|
| 111 | + * |
---|
| 112 | + * exec-all : all PROT_READ user mappings are executable, except when |
---|
| 113 | + * backed by files on a noexec-filesystem. |
---|
| 114 | + * exec-none : only PROT_EXEC user mappings are executable. |
---|
| 115 | + * exec-stack: only the stack and PROT_EXEC user mappings are executable. |
---|
| 116 | + * |
---|
| 117 | + * *all arm64 CPUs support NX, so there is no "lacks NX" column. |
---|
| 118 | + * |
---|
| 119 | + */ |
---|
| 120 | +#define compat_elf_read_implies_exec(ex, stk) (stk == EXSTACK_DEFAULT) |
---|
111 | 121 | |
---|
112 | 122 | #define CORE_DUMP_USE_REGSET |
---|
113 | 123 | #define ELF_EXEC_PAGESIZE PAGE_SIZE |
---|
.. | .. |
---|
117 | 127 | * 64-bit, this is above 4GB to leave the entire 32-bit address |
---|
118 | 128 | * space open for things that want to use the area for 32-bit pointers. |
---|
119 | 129 | */ |
---|
| 130 | +#ifdef CONFIG_ARM64_FORCE_52BIT |
---|
120 | 131 | #define ELF_ET_DYN_BASE (2 * TASK_SIZE_64 / 3) |
---|
| 132 | +#else |
---|
| 133 | +#define ELF_ET_DYN_BASE (2 * DEFAULT_MAP_WINDOW_64 / 3) |
---|
| 134 | +#endif /* CONFIG_ARM64_FORCE_52BIT */ |
---|
121 | 135 | |
---|
122 | 136 | #ifndef __ASSEMBLY__ |
---|
123 | 137 | |
---|
| 138 | +#include <uapi/linux/elf.h> |
---|
124 | 139 | #include <linux/bug.h> |
---|
| 140 | +#include <linux/errno.h> |
---|
| 141 | +#include <linux/fs.h> |
---|
| 142 | +#include <linux/types.h> |
---|
125 | 143 | #include <asm/processor.h> /* for signal_minsigstksz, used by ARCH_DLINFO */ |
---|
126 | 144 | |
---|
127 | 145 | typedef unsigned long elf_greg_t; |
---|
.. | .. |
---|
231 | 249 | |
---|
232 | 250 | #endif /* CONFIG_COMPAT */ |
---|
233 | 251 | |
---|
| 252 | +struct arch_elf_state { |
---|
| 253 | + int flags; |
---|
| 254 | +}; |
---|
| 255 | + |
---|
| 256 | +#define ARM64_ELF_BTI (1 << 0) |
---|
| 257 | + |
---|
| 258 | +#define INIT_ARCH_ELF_STATE { \ |
---|
| 259 | + .flags = 0, \ |
---|
| 260 | +} |
---|
| 261 | + |
---|
| 262 | +static inline int arch_parse_elf_property(u32 type, const void *data, |
---|
| 263 | + size_t datasz, bool compat, |
---|
| 264 | + struct arch_elf_state *arch) |
---|
| 265 | +{ |
---|
| 266 | + /* No known properties for AArch32 yet */ |
---|
| 267 | + if (IS_ENABLED(CONFIG_COMPAT) && compat) |
---|
| 268 | + return 0; |
---|
| 269 | + |
---|
| 270 | + if (type == GNU_PROPERTY_AARCH64_FEATURE_1_AND) { |
---|
| 271 | + const u32 *p = data; |
---|
| 272 | + |
---|
| 273 | + if (datasz != sizeof(*p)) |
---|
| 274 | + return -ENOEXEC; |
---|
| 275 | + |
---|
| 276 | + if (system_supports_bti() && |
---|
| 277 | + (*p & GNU_PROPERTY_AARCH64_FEATURE_1_BTI)) |
---|
| 278 | + arch->flags |= ARM64_ELF_BTI; |
---|
| 279 | + } |
---|
| 280 | + |
---|
| 281 | + return 0; |
---|
| 282 | +} |
---|
| 283 | + |
---|
| 284 | +static inline int arch_elf_pt_proc(void *ehdr, void *phdr, |
---|
| 285 | + struct file *f, bool is_interp, |
---|
| 286 | + struct arch_elf_state *state) |
---|
| 287 | +{ |
---|
| 288 | + return 0; |
---|
| 289 | +} |
---|
| 290 | + |
---|
| 291 | +static inline int arch_check_elf(void *ehdr, bool has_interp, |
---|
| 292 | + void *interp_ehdr, |
---|
| 293 | + struct arch_elf_state *state) |
---|
| 294 | +{ |
---|
| 295 | + return 0; |
---|
| 296 | +} |
---|
| 297 | + |
---|
234 | 298 | #endif /* !__ASSEMBLY__ */ |
---|
235 | 299 | |
---|
236 | 300 | #endif |
---|