Skip to content

Commit 9549fb3

Browse files
Greg Ungererpalmer-dabbelt
authored andcommitted
riscv: support the elf-fdpic binfmt loader
Add support for enabling and using the binfmt_elf_fdpic program loader on RISC-V platforms. The most important change is to setup registers during program load to pass the mapping addresses to the new process. One of the interesting features of the elf-fdpic loader is that it also allows appropriately compiled ELF format binaries to be loaded on nommu systems. Appropriate being those compiled with -pie. Signed-off-by: Greg Ungerer <gerg@kernel.org> Acked-by: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/r/20230711130754.481209-3-gerg@kernel.org Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
1 parent b922bf0 commit 9549fb3

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

arch/riscv/include/asm/elf.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ extern bool compat_elf_check_arch(Elf32_Ehdr *hdr);
4141
#define compat_elf_check_arch compat_elf_check_arch
4242

4343
#define CORE_DUMP_USE_REGSET
44+
#define ELF_FDPIC_CORE_EFLAGS 0
4445
#define ELF_EXEC_PAGESIZE (PAGE_SIZE)
4546

4647
/*
@@ -69,6 +70,13 @@ extern bool compat_elf_check_arch(Elf32_Ehdr *hdr);
6970
#define ELF_HWCAP riscv_get_elf_hwcap()
7071
extern unsigned long elf_hwcap;
7172

73+
#define ELF_FDPIC_PLAT_INIT(_r, _exec_map_addr, _interp_map_addr, dynamic_addr) \
74+
do { \
75+
(_r)->a1 = _exec_map_addr; \
76+
(_r)->a2 = _interp_map_addr; \
77+
(_r)->a3 = dynamic_addr; \
78+
} while (0)
79+
7280
/*
7381
* This yields a string that ld.so will use to load implementation
7482
* specific libraries for optimization. This is more specific in
@@ -78,7 +86,6 @@ extern unsigned long elf_hwcap;
7886

7987
#define COMPAT_ELF_PLATFORM (NULL)
8088

81-
#ifdef CONFIG_MMU
8289
#define ARCH_DLINFO \
8390
do { \
8491
/* \
@@ -115,6 +122,8 @@ do { \
115122
else \
116123
NEW_AUX_ENT(AT_IGNORE, 0); \
117124
} while (0)
125+
126+
#ifdef CONFIG_MMU
118127
#define ARCH_HAS_SETUP_ADDITIONAL_PAGES
119128
struct linux_binprm;
120129
extern int arch_setup_additional_pages(struct linux_binprm *bprm,

arch/riscv/include/asm/mmu.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ typedef struct {
2020
/* A local icache flush is needed before user execution can resume. */
2121
cpumask_t icache_stale_mask;
2222
#endif
23+
#ifdef CONFIG_BINFMT_ELF_FDPIC
24+
unsigned long exec_fdpic_loadmap;
25+
unsigned long interp_fdpic_loadmap;
26+
#endif
2327
} mm_context_t;
2428

2529
void __init create_pgd_mapping(pgd_t *pgdp, uintptr_t va, phys_addr_t pa,

arch/riscv/include/uapi/asm/ptrace.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010

1111
#include <linux/types.h>
1212

13+
#define PTRACE_GETFDPIC 33
14+
15+
#define PTRACE_GETFDPIC_EXEC 0
16+
#define PTRACE_GETFDPIC_INTERP 1
17+
1318
/*
1419
* User-mode register state for core dumps, ptrace, sigcontext
1520
*

fs/Kconfig.binfmt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ config ARCH_USE_GNU_PROPERTY
5858
config BINFMT_ELF_FDPIC
5959
bool "Kernel support for FDPIC ELF binaries"
6060
default y if !BINFMT_ELF
61-
depends on ARM || ((M68K || SUPERH || XTENSA) && !MMU)
61+
depends on ARM || ((M68K || RISCV || SUPERH || XTENSA) && !MMU)
6262
select ELFCORE
6363
help
6464
ELF FDPIC binaries are based on ELF, but allow the individual load

0 commit comments

Comments
 (0)