* [PATCH v10 0/8] linux-user: User support for AArch64 BTI
@ 2020-10-02 21:59 Richard Henderson
2020-10-02 21:59 ` [PATCH v10 1/8] linux-user/aarch64: Reset btype for signals Richard Henderson
` (8 more replies)
0 siblings, 9 replies; 18+ messages in thread
From: Richard Henderson @ 2020-10-02 21:59 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, qemu-arm, alex.bennee, laurent
The kernel abi for this was merged in v5.8, just as the qemu 5.1
merge window was closing, so this slipped to the next dev cycle.
Changes from v9:
* Split what is now patch 7 into 3 more (pmm).
* All prerequisites are now upstream.
r~
Richard Henderson (8):
linux-user/aarch64: Reset btype for signals
linux-user: Set PAGE_TARGET_1 for TARGET_PROT_BTI
include/elf: Add defines related to GNU property notes for AArch64
linux-user/elfload: Fix coding style in load_elf_image
linux-user/elfload: Adjust iteration over phdr
linux-user/elfload: Move PT_INTERP detection to first loop
linux-user/elfload: Parse NT_GNU_PROPERTY_TYPE_0 notes
tests/tcg/aarch64: Add bti smoke test
include/elf.h | 22 +++++
include/exec/cpu-all.h | 2 +
linux-user/qemu.h | 4 +
linux-user/syscall_defs.h | 4 +
target/arm/cpu.h | 5 +
linux-user/aarch64/signal.c | 10 +-
linux-user/elfload.c | 147 ++++++++++++++++++++++--------
linux-user/mmap.c | 16 ++++
target/arm/translate-a64.c | 6 +-
tests/tcg/aarch64/bti-1.c | 62 +++++++++++++
tests/tcg/aarch64/bti-crt.inc.c | 51 +++++++++++
tests/tcg/aarch64/Makefile.target | 7 ++
tests/tcg/configure.sh | 4 +
13 files changed, 298 insertions(+), 42 deletions(-)
create mode 100644 tests/tcg/aarch64/bti-1.c
create mode 100644 tests/tcg/aarch64/bti-crt.inc.c
--
2.25.1
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v10 1/8] linux-user/aarch64: Reset btype for signals
2020-10-02 21:59 [PATCH v10 0/8] linux-user: User support for AArch64 BTI Richard Henderson
@ 2020-10-02 21:59 ` Richard Henderson
2020-10-02 21:59 ` [PATCH v10 2/8] linux-user: Set PAGE_TARGET_1 for TARGET_PROT_BTI Richard Henderson
` (7 subsequent siblings)
8 siblings, 0 replies; 18+ messages in thread
From: Richard Henderson @ 2020-10-02 21:59 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, qemu-arm, alex.bennee, laurent
The kernel sets btype for the signal handler as if for a call.
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/aarch64/signal.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/linux-user/aarch64/signal.c b/linux-user/aarch64/signal.c
index d50c1ae583..b591790c22 100644
--- a/linux-user/aarch64/signal.c
+++ b/linux-user/aarch64/signal.c
@@ -506,10 +506,16 @@ static void target_setup_frame(int usig, struct target_sigaction *ka,
+ offsetof(struct target_rt_frame_record, tramp);
}
env->xregs[0] = usig;
- env->xregs[31] = frame_addr;
env->xregs[29] = frame_addr + fr_ofs;
- env->pc = ka->_sa_handler;
env->xregs[30] = return_addr;
+ env->xregs[31] = frame_addr;
+ env->pc = ka->_sa_handler;
+
+ /* Invoke the signal handler as if by indirect call. */
+ if (cpu_isar_feature(aa64_bti, env_archcpu(env))) {
+ env->btype = 2;
+ }
+
if (info) {
tswap_siginfo(&frame->info, info);
env->xregs[1] = frame_addr + offsetof(struct target_rt_sigframe, info);
--
2.25.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH v10 2/8] linux-user: Set PAGE_TARGET_1 for TARGET_PROT_BTI
2020-10-02 21:59 [PATCH v10 0/8] linux-user: User support for AArch64 BTI Richard Henderson
2020-10-02 21:59 ` [PATCH v10 1/8] linux-user/aarch64: Reset btype for signals Richard Henderson
@ 2020-10-02 21:59 ` Richard Henderson
2020-10-02 21:59 ` [PATCH v10 3/8] include/elf: Add defines related to GNU property notes for AArch64 Richard Henderson
` (6 subsequent siblings)
8 siblings, 0 replies; 18+ messages in thread
From: Richard Henderson @ 2020-10-02 21:59 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, qemu-arm, alex.bennee, laurent
Transform the prot bit to a qemu internal page bit, and save
it in the page tables.
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
v10: Add PAGE_BTI define (pmm).
---
include/exec/cpu-all.h | 2 ++
linux-user/syscall_defs.h | 4 ++++
target/arm/cpu.h | 5 +++++
linux-user/mmap.c | 16 ++++++++++++++++
target/arm/translate-a64.c | 6 +++---
5 files changed, 30 insertions(+), 3 deletions(-)
diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
index f6439c4705..ba80c46c95 100644
--- a/include/exec/cpu-all.h
+++ b/include/exec/cpu-all.h
@@ -274,6 +274,8 @@ extern intptr_t qemu_host_page_mask;
/* FIXME: Code that sets/uses this is broken and needs to go away. */
#define PAGE_RESERVED 0x0020
#endif
+/* Target-specific bits that will be used via page_get_flags(). */
+#define PAGE_TARGET_1 0x0080
#if defined(CONFIG_USER_ONLY)
void page_dump(FILE *f);
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 731c3d5341..cabbfb762d 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -1277,6 +1277,10 @@ struct target_winsize {
#define TARGET_PROT_SEM 0x08
#endif
+#ifdef TARGET_AARCH64
+#define TARGET_PROT_BTI 0x10
+#endif
+
/* Common */
#define TARGET_MAP_SHARED 0x01 /* Share changes */
#define TARGET_MAP_PRIVATE 0x02 /* Changes are private */
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
index e4549a8cc0..a07d605c2f 100644
--- a/target/arm/cpu.h
+++ b/target/arm/cpu.h
@@ -3439,6 +3439,11 @@ static inline MemTxAttrs *typecheck_memtxattrs(MemTxAttrs *x)
#define arm_tlb_bti_gp(x) (typecheck_memtxattrs(x)->target_tlb_bit0)
#define arm_tlb_mte_tagged(x) (typecheck_memtxattrs(x)->target_tlb_bit1)
+/*
+ * AArch64 usage of the PAGE_TARGET_* bits for linux-user.
+ */
+#define PAGE_BTI PAGE_TARGET_1
+
/*
* Naming convention for isar_feature functions:
* Functions which test 32-bit ID registers should have _aa32_ in
diff --git a/linux-user/mmap.c b/linux-user/mmap.c
index f261563420..00c05e6a0f 100644
--- a/linux-user/mmap.c
+++ b/linux-user/mmap.c
@@ -83,6 +83,22 @@ static int validate_prot_to_pageflags(int *host_prot, int prot)
*host_prot = (prot & (PROT_READ | PROT_WRITE))
| (prot & PROT_EXEC ? PROT_READ : 0);
+#ifdef TARGET_AARCH64
+ /*
+ * The PROT_BTI bit is only accepted if the cpu supports the feature.
+ * Since this is the unusual case, don't bother checking unless
+ * the bit has been requested. If set and valid, record the bit
+ * within QEMU's page_flags.
+ */
+ if (prot & TARGET_PROT_BTI) {
+ ARMCPU *cpu = ARM_CPU(thread_cpu);
+ if (cpu_isar_feature(aa64_bti, cpu)) {
+ valid |= TARGET_PROT_BTI;
+ page_flags |= PAGE_BTI;
+ }
+ }
+#endif
+
return prot & ~valid ? 0 : page_flags;
}
diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
index 7188808341..072754fa24 100644
--- a/target/arm/translate-a64.c
+++ b/target/arm/translate-a64.c
@@ -14507,10 +14507,10 @@ static void disas_data_proc_simd_fp(DisasContext *s, uint32_t insn)
*/
static bool is_guarded_page(CPUARMState *env, DisasContext *s)
{
-#ifdef CONFIG_USER_ONLY
- return false; /* FIXME */
-#else
uint64_t addr = s->base.pc_first;
+#ifdef CONFIG_USER_ONLY
+ return page_get_flags(addr) & PAGE_BTI;
+#else
int mmu_idx = arm_to_core_mmu_idx(s->mmu_idx);
unsigned int index = tlb_index(env, mmu_idx, addr);
CPUTLBEntry *entry = tlb_entry(env, mmu_idx, addr);
--
2.25.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH v10 3/8] include/elf: Add defines related to GNU property notes for AArch64
2020-10-02 21:59 [PATCH v10 0/8] linux-user: User support for AArch64 BTI Richard Henderson
2020-10-02 21:59 ` [PATCH v10 1/8] linux-user/aarch64: Reset btype for signals Richard Henderson
2020-10-02 21:59 ` [PATCH v10 2/8] linux-user: Set PAGE_TARGET_1 for TARGET_PROT_BTI Richard Henderson
@ 2020-10-02 21:59 ` Richard Henderson
2020-10-02 21:59 ` [PATCH v10 4/8] linux-user/elfload: Fix coding style in load_elf_image Richard Henderson
` (5 subsequent siblings)
8 siblings, 0 replies; 18+ messages in thread
From: Richard Henderson @ 2020-10-02 21:59 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, qemu-arm, alex.bennee, laurent
These are all of the defines required to parse
GNU_PROPERTY_AARCH64_FEATURE_1_AND, copied from binutils.
Other missing defines related to other GNU program headers
and notes are elided for now.
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/elf.h | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/include/elf.h b/include/elf.h
index c117a4d1ab..10126ff809 100644
--- a/include/elf.h
+++ b/include/elf.h
@@ -26,9 +26,13 @@ typedef int64_t Elf64_Sxword;
#define PT_NOTE 4
#define PT_SHLIB 5
#define PT_PHDR 6
+#define PT_LOOS 0x60000000
+#define PT_HIOS 0x6fffffff
#define PT_LOPROC 0x70000000
#define PT_HIPROC 0x7fffffff
+#define PT_GNU_PROPERTY (PT_LOOS + 0x474e553)
+
#define PT_MIPS_REGINFO 0x70000000
#define PT_MIPS_RTPROC 0x70000001
#define PT_MIPS_OPTIONS 0x70000002
@@ -1657,6 +1661,24 @@ typedef struct elf64_shdr {
#define NT_ARM_SYSTEM_CALL 0x404 /* ARM system call number */
#define NT_ARM_SVE 0x405 /* ARM Scalable Vector Extension regs */
+/* Defined note types for GNU systems. */
+
+#define NT_GNU_PROPERTY_TYPE_0 5 /* Program property */
+
+/* Values used in GNU .note.gnu.property notes (NT_GNU_PROPERTY_TYPE_0). */
+
+#define GNU_PROPERTY_STACK_SIZE 1
+#define GNU_PROPERTY_NO_COPY_ON_PROTECTED 2
+
+#define GNU_PROPERTY_LOPROC 0xc0000000
+#define GNU_PROPERTY_HIPROC 0xdfffffff
+#define GNU_PROPERTY_LOUSER 0xe0000000
+#define GNU_PROPERTY_HIUSER 0xffffffff
+
+#define GNU_PROPERTY_AARCH64_FEATURE_1_AND 0xc0000000
+#define GNU_PROPERTY_AARCH64_FEATURE_1_BTI (1u << 0)
+#define GNU_PROPERTY_AARCH64_FEATURE_1_PAC (1u << 1)
+
/*
* Physical entry point into the kernel.
*
--
2.25.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH v10 4/8] linux-user/elfload: Fix coding style in load_elf_image
2020-10-02 21:59 [PATCH v10 0/8] linux-user: User support for AArch64 BTI Richard Henderson
` (2 preceding siblings ...)
2020-10-02 21:59 ` [PATCH v10 3/8] include/elf: Add defines related to GNU property notes for AArch64 Richard Henderson
@ 2020-10-02 21:59 ` Richard Henderson
2020-10-03 17:34 ` Philippe Mathieu-Daudé
2020-10-08 13:03 ` Peter Maydell
2020-10-02 21:59 ` [PATCH v10 5/8] linux-user/elfload: Adjust iteration over phdr Richard Henderson
` (4 subsequent siblings)
8 siblings, 2 replies; 18+ messages in thread
From: Richard Henderson @ 2020-10-02 21:59 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, qemu-arm, alex.bennee, laurent
Fixing this now will clarify following patches.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/elfload.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index f6022fd704..7572a32a30 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -2531,9 +2531,15 @@ static void load_elf_image(const char *image_name, int image_fd,
abi_ulong vaddr, vaddr_po, vaddr_ps, vaddr_ef, vaddr_em, vaddr_len;
int elf_prot = 0;
- if (eppnt->p_flags & PF_R) elf_prot = PROT_READ;
- if (eppnt->p_flags & PF_W) elf_prot |= PROT_WRITE;
- if (eppnt->p_flags & PF_X) elf_prot |= PROT_EXEC;
+ if (eppnt->p_flags & PF_R) {
+ elf_prot |= PROT_READ;
+ }
+ if (eppnt->p_flags & PF_W) {
+ elf_prot |= PROT_WRITE;
+ }
+ if (eppnt->p_flags & PF_X) {
+ elf_prot |= PROT_EXEC;
+ }
vaddr = load_bias + eppnt->p_vaddr;
vaddr_po = TARGET_ELF_PAGEOFFSET(vaddr);
--
2.25.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH v10 5/8] linux-user/elfload: Adjust iteration over phdr
2020-10-02 21:59 [PATCH v10 0/8] linux-user: User support for AArch64 BTI Richard Henderson
` (3 preceding siblings ...)
2020-10-02 21:59 ` [PATCH v10 4/8] linux-user/elfload: Fix coding style in load_elf_image Richard Henderson
@ 2020-10-02 21:59 ` Richard Henderson
2020-10-03 17:51 ` Philippe Mathieu-Daudé
2020-10-08 13:03 ` Peter Maydell
2020-10-02 21:59 ` [PATCH v10 6/8] linux-user/elfload: Move PT_INTERP detection to first loop Richard Henderson
` (3 subsequent siblings)
8 siblings, 2 replies; 18+ messages in thread
From: Richard Henderson @ 2020-10-02 21:59 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, qemu-arm, alex.bennee, laurent
The second loop uses a loop induction variable, and the first
does not. Transform the first to match the second, to simplify
a following patch moving code between them.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/elfload.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 7572a32a30..735ebfa190 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -2426,17 +2426,18 @@ static void load_elf_image(const char *image_name, int image_fd,
loaddr = -1, hiaddr = 0;
info->alignment = 0;
for (i = 0; i < ehdr->e_phnum; ++i) {
- if (phdr[i].p_type == PT_LOAD) {
- abi_ulong a = phdr[i].p_vaddr - phdr[i].p_offset;
+ struct elf_phdr *eppnt = phdr + i;
+ if (eppnt->p_type == PT_LOAD) {
+ abi_ulong a = eppnt->p_vaddr - eppnt->p_offset;
if (a < loaddr) {
loaddr = a;
}
- a = phdr[i].p_vaddr + phdr[i].p_memsz;
+ a = eppnt->p_vaddr + eppnt->p_memsz;
if (a > hiaddr) {
hiaddr = a;
}
++info->nsegs;
- info->alignment |= phdr[i].p_align;
+ info->alignment |= eppnt->p_align;
}
}
--
2.25.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH v10 6/8] linux-user/elfload: Move PT_INTERP detection to first loop
2020-10-02 21:59 [PATCH v10 0/8] linux-user: User support for AArch64 BTI Richard Henderson
` (4 preceding siblings ...)
2020-10-02 21:59 ` [PATCH v10 5/8] linux-user/elfload: Adjust iteration over phdr Richard Henderson
@ 2020-10-02 21:59 ` Richard Henderson
2020-10-03 17:38 ` Philippe Mathieu-Daudé
2020-10-02 21:59 ` [PATCH v10 7/8] linux-user/elfload: Parse NT_GNU_PROPERTY_TYPE_0 notes Richard Henderson
` (2 subsequent siblings)
8 siblings, 1 reply; 18+ messages in thread
From: Richard Henderson @ 2020-10-02 21:59 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, qemu-arm, alex.bennee, laurent
For BTI, we need to know if the executable is static or dynamic,
which means looking for PT_INTERP earlier.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/elfload.c | 60 +++++++++++++++++++++++---------------------
1 file changed, 31 insertions(+), 29 deletions(-)
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 735ebfa190..6b422990ff 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -2421,8 +2421,10 @@ static void load_elf_image(const char *image_name, int image_fd,
mmap_lock();
- /* Find the maximum size of the image and allocate an appropriate
- amount of memory to handle that. */
+ /*
+ * Find the maximum size of the image and allocate an appropriate
+ * amount of memory to handle that. Locate the interpreter, if any.
+ */
loaddr = -1, hiaddr = 0;
info->alignment = 0;
for (i = 0; i < ehdr->e_phnum; ++i) {
@@ -2438,6 +2440,33 @@ static void load_elf_image(const char *image_name, int image_fd,
}
++info->nsegs;
info->alignment |= eppnt->p_align;
+ } else if (eppnt->p_type == PT_INTERP && pinterp_name) {
+ char *interp_name;
+
+ if (*pinterp_name) {
+ errmsg = "Multiple PT_INTERP entries";
+ goto exit_errmsg;
+ }
+ interp_name = malloc(eppnt->p_filesz);
+ if (!interp_name) {
+ goto exit_perror;
+ }
+
+ if (eppnt->p_offset + eppnt->p_filesz <= BPRM_BUF_SIZE) {
+ memcpy(interp_name, bprm_buf + eppnt->p_offset,
+ eppnt->p_filesz);
+ } else {
+ retval = pread(image_fd, interp_name, eppnt->p_filesz,
+ eppnt->p_offset);
+ if (retval != eppnt->p_filesz) {
+ goto exit_perror;
+ }
+ }
+ if (interp_name[eppnt->p_filesz - 1] != 0) {
+ errmsg = "Invalid PT_INTERP entry";
+ goto exit_errmsg;
+ }
+ *pinterp_name = interp_name;
}
}
@@ -2590,33 +2619,6 @@ static void load_elf_image(const char *image_name, int image_fd,
if (vaddr_em > info->brk) {
info->brk = vaddr_em;
}
- } else if (eppnt->p_type == PT_INTERP && pinterp_name) {
- char *interp_name;
-
- if (*pinterp_name) {
- errmsg = "Multiple PT_INTERP entries";
- goto exit_errmsg;
- }
- interp_name = malloc(eppnt->p_filesz);
- if (!interp_name) {
- goto exit_perror;
- }
-
- if (eppnt->p_offset + eppnt->p_filesz <= BPRM_BUF_SIZE) {
- memcpy(interp_name, bprm_buf + eppnt->p_offset,
- eppnt->p_filesz);
- } else {
- retval = pread(image_fd, interp_name, eppnt->p_filesz,
- eppnt->p_offset);
- if (retval != eppnt->p_filesz) {
- goto exit_perror;
- }
- }
- if (interp_name[eppnt->p_filesz - 1] != 0) {
- errmsg = "Invalid PT_INTERP entry";
- goto exit_errmsg;
- }
- *pinterp_name = interp_name;
#ifdef TARGET_MIPS
} else if (eppnt->p_type == PT_MIPS_ABIFLAGS) {
Mips_elf_abiflags_v0 abiflags;
--
2.25.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH v10 7/8] linux-user/elfload: Parse NT_GNU_PROPERTY_TYPE_0 notes
2020-10-02 21:59 [PATCH v10 0/8] linux-user: User support for AArch64 BTI Richard Henderson
` (5 preceding siblings ...)
2020-10-02 21:59 ` [PATCH v10 6/8] linux-user/elfload: Move PT_INTERP detection to first loop Richard Henderson
@ 2020-10-02 21:59 ` Richard Henderson
2020-10-08 14:02 ` Peter Maydell
2020-10-02 21:59 ` [PATCH v10 8/8] tests/tcg/aarch64: Add bti smoke test Richard Henderson
2020-10-04 1:34 ` [PATCH v10 0/8] linux-user: User support for AArch64 BTI no-reply
8 siblings, 1 reply; 18+ messages in thread
From: Richard Henderson @ 2020-10-02 21:59 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, qemu-arm, alex.bennee, laurent
For aarch64, this includes the GNU_PROPERTY_AARCH64_FEATURE_1_BTI bit,
which indicates that the image should be mapped with guarded pages.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
v9: Only map the startup executable with BTI; anything else must be
handled by the interpreter.
v10: Split out preparatory patches (pmm).
---
linux-user/qemu.h | 4 +++
linux-user/elfload.c | 68 ++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 70 insertions(+), 2 deletions(-)
diff --git a/linux-user/qemu.h b/linux-user/qemu.h
index 941ca99722..534753ca12 100644
--- a/linux-user/qemu.h
+++ b/linux-user/qemu.h
@@ -61,6 +61,10 @@ struct image_info {
abi_ulong interpreter_loadmap_addr;
abi_ulong interpreter_pt_dynamic_addr;
struct image_info *other_info;
+
+ /* For target-specific processing of NT_GNU_PROPERTY_TYPE_0. */
+ uint32_t note_flags;
+
#ifdef TARGET_MIPS
int fp_abi;
int interp_fp_abi;
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 6b422990ff..3c6cbd35c3 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -2391,7 +2391,7 @@ static void load_elf_image(const char *image_name, int image_fd,
struct elfhdr *ehdr = (struct elfhdr *)bprm_buf;
struct elf_phdr *phdr;
abi_ulong load_addr, load_bias, loaddr, hiaddr, error;
- int i, retval;
+ int i, retval, prot_exec;
const char *errmsg;
/* First of all, some simple consistency checks */
@@ -2467,6 +2467,50 @@ static void load_elf_image(const char *image_name, int image_fd,
goto exit_errmsg;
}
*pinterp_name = interp_name;
+ } else if (eppnt->p_type == PT_GNU_PROPERTY) {
+ /* Process NT_GNU_PROPERTY_TYPE_0. */
+ const uint32_t gnu0_magic = const_le32('G' | 'N' << 8 | 'U' << 16);
+ uint32_t note[7];
+
+ /*
+ * The note contents are 7 words, but depending on LP64 vs ILP32
+ * there may be an 8th padding word at the end. Check for and
+ * read the minimum size. Further checks below will validate
+ * that the sizes of everything involved are as we expect.
+ */
+ if (eppnt->p_filesz < sizeof(note)) {
+ continue;
+ }
+ if (eppnt->p_offset + eppnt->p_filesz <= BPRM_BUF_SIZE) {
+ memcpy(note, bprm_buf + eppnt->p_offset, sizeof(note));
+ } else {
+ retval = pread(image_fd, note, sizeof(note), eppnt->p_offset);
+ if (retval != sizeof(note)) {
+ goto exit_perror;
+ }
+ }
+#ifdef BSWAP_NEEDED
+ for (i = 0; i < ARRAY_SIZE(note); ++i) {
+ bswap32s(note + i);
+ }
+#endif
+ /*
+ * Check that this is a NT_GNU_PROPERTY_TYPE_0 note.
+ * Again, descsz includes padding. Full size validation
+ * awaits checking the final payload.
+ */
+ if (note[0] != 4 || /* namesz */
+ note[1] < 12 || /* descsz */
+ note[2] != NT_GNU_PROPERTY_TYPE_0 || /* type */
+ note[3] != gnu0_magic) { /* name */
+ continue;
+ }
+#ifdef TARGET_AARCH64
+ if (note[4] == GNU_PROPERTY_AARCH64_FEATURE_1_AND &&
+ note[5] == 4) {
+ info->note_flags = note[6];
+ }
+#endif /* TARGET_AARCH64 */
}
}
@@ -2555,6 +2599,26 @@ static void load_elf_image(const char *image_name, int image_fd,
info->brk = 0;
info->elf_flags = ehdr->e_flags;
+ prot_exec = PROT_EXEC;
+#ifdef TARGET_AARCH64
+ /*
+ * If the BTI feature is present, this indicates that the executable
+ * pages of the startup binary should be mapped with PROT_BTI, so that
+ * branch targets are enforced.
+ *
+ * The startup binary is either the interpreter or the static executable.
+ * The interpreter is responsible for all pages of a dynamic executable.
+ *
+ * Elf notes are backward compatible to older cpus.
+ * Do not enable BTI unless it is supported.
+ */
+ if ((info->note_flags & GNU_PROPERTY_AARCH64_FEATURE_1_BTI)
+ && (pinterp_name == NULL || *pinterp_name == 0)
+ && cpu_isar_feature(aa64_bti, ARM_CPU(thread_cpu))) {
+ prot_exec |= TARGET_PROT_BTI;
+ }
+#endif
+
for (i = 0; i < ehdr->e_phnum; i++) {
struct elf_phdr *eppnt = phdr + i;
if (eppnt->p_type == PT_LOAD) {
@@ -2568,7 +2632,7 @@ static void load_elf_image(const char *image_name, int image_fd,
elf_prot |= PROT_WRITE;
}
if (eppnt->p_flags & PF_X) {
- elf_prot |= PROT_EXEC;
+ elf_prot |= prot_exec;
}
vaddr = load_bias + eppnt->p_vaddr;
--
2.25.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH v10 8/8] tests/tcg/aarch64: Add bti smoke test
2020-10-02 21:59 [PATCH v10 0/8] linux-user: User support for AArch64 BTI Richard Henderson
` (6 preceding siblings ...)
2020-10-02 21:59 ` [PATCH v10 7/8] linux-user/elfload: Parse NT_GNU_PROPERTY_TYPE_0 notes Richard Henderson
@ 2020-10-02 21:59 ` Richard Henderson
2020-10-04 1:34 ` [PATCH v10 0/8] linux-user: User support for AArch64 BTI no-reply
8 siblings, 0 replies; 18+ messages in thread
From: Richard Henderson @ 2020-10-02 21:59 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, qemu-arm, alex.bennee, laurent
This test requires gcc 10 for -mbranch-protection=standard.
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
v9: Expect and require gcc 10.
---
tests/tcg/aarch64/bti-1.c | 62 +++++++++++++++++++++++++++++++
tests/tcg/aarch64/bti-crt.inc.c | 51 +++++++++++++++++++++++++
tests/tcg/aarch64/Makefile.target | 7 ++++
tests/tcg/configure.sh | 4 ++
4 files changed, 124 insertions(+)
create mode 100644 tests/tcg/aarch64/bti-1.c
create mode 100644 tests/tcg/aarch64/bti-crt.inc.c
diff --git a/tests/tcg/aarch64/bti-1.c b/tests/tcg/aarch64/bti-1.c
new file mode 100644
index 0000000000..61924f0d7a
--- /dev/null
+++ b/tests/tcg/aarch64/bti-1.c
@@ -0,0 +1,62 @@
+/*
+ * Branch target identification, basic notskip cases.
+ */
+
+#include "bti-crt.inc.c"
+
+static void skip2_sigill(int sig, siginfo_t *info, ucontext_t *uc)
+{
+ uc->uc_mcontext.pc += 8;
+ uc->uc_mcontext.pstate = 1;
+}
+
+#define NOP "nop"
+#define BTI_N "hint #32"
+#define BTI_C "hint #34"
+#define BTI_J "hint #36"
+#define BTI_JC "hint #38"
+
+#define BTYPE_1(DEST) \
+ asm("mov %0,#1; adr x16, 1f; br x16; 1: " DEST "; mov %0,#0" \
+ : "=r"(skipped) : : "x16")
+
+#define BTYPE_2(DEST) \
+ asm("mov %0,#1; adr x16, 1f; blr x16; 1: " DEST "; mov %0,#0" \
+ : "=r"(skipped) : : "x16", "x30")
+
+#define BTYPE_3(DEST) \
+ asm("mov %0,#1; adr x15, 1f; br x15; 1: " DEST "; mov %0,#0" \
+ : "=r"(skipped) : : "x15")
+
+#define TEST(WHICH, DEST, EXPECT) \
+ do { WHICH(DEST); fail += skipped ^ EXPECT; } while (0)
+
+
+int main()
+{
+ int fail = 0;
+ int skipped;
+
+ /* Signal-like with SA_SIGINFO. */
+ signal_info(SIGILL, skip2_sigill);
+
+ TEST(BTYPE_1, NOP, 1);
+ TEST(BTYPE_1, BTI_N, 1);
+ TEST(BTYPE_1, BTI_C, 0);
+ TEST(BTYPE_1, BTI_J, 0);
+ TEST(BTYPE_1, BTI_JC, 0);
+
+ TEST(BTYPE_2, NOP, 1);
+ TEST(BTYPE_2, BTI_N, 1);
+ TEST(BTYPE_2, BTI_C, 0);
+ TEST(BTYPE_2, BTI_J, 1);
+ TEST(BTYPE_2, BTI_JC, 0);
+
+ TEST(BTYPE_3, NOP, 1);
+ TEST(BTYPE_3, BTI_N, 1);
+ TEST(BTYPE_3, BTI_C, 1);
+ TEST(BTYPE_3, BTI_J, 0);
+ TEST(BTYPE_3, BTI_JC, 0);
+
+ return fail;
+}
diff --git a/tests/tcg/aarch64/bti-crt.inc.c b/tests/tcg/aarch64/bti-crt.inc.c
new file mode 100644
index 0000000000..47805f4e35
--- /dev/null
+++ b/tests/tcg/aarch64/bti-crt.inc.c
@@ -0,0 +1,51 @@
+/*
+ * Minimal user-environment for testing BTI.
+ *
+ * Normal libc is not (yet) built with BTI support enabled,
+ * and so could generate a BTI TRAP before ever reaching main.
+ */
+
+#include <stdlib.h>
+#include <signal.h>
+#include <ucontext.h>
+#include <asm/unistd.h>
+
+int main(void);
+
+void _start(void)
+{
+ exit(main());
+}
+
+void exit(int ret)
+{
+ register int x0 __asm__("x0") = ret;
+ register int x8 __asm__("x8") = __NR_exit;
+
+ asm volatile("svc #0" : : "r"(x0), "r"(x8));
+ __builtin_unreachable();
+}
+
+/*
+ * Irritatingly, the user API struct sigaction does not match the
+ * kernel API struct sigaction. So for simplicity, isolate the
+ * kernel ABI here, and make this act like signal.
+ */
+void signal_info(int sig, void (*fn)(int, siginfo_t *, ucontext_t *))
+{
+ struct kernel_sigaction {
+ void (*handler)(int, siginfo_t *, ucontext_t *);
+ unsigned long flags;
+ unsigned long restorer;
+ unsigned long mask;
+ } sa = { fn, SA_SIGINFO, 0, 0 };
+
+ register int x0 __asm__("x0") = sig;
+ register void *x1 __asm__("x1") = &sa;
+ register void *x2 __asm__("x2") = 0;
+ register int x3 __asm__("x3") = sizeof(unsigned long);
+ register int x8 __asm__("x8") = __NR_rt_sigaction;
+
+ asm volatile("svc #0"
+ : : "r"(x0), "r"(x1), "r"(x2), "r"(x3), "r"(x8) : "memory");
+}
diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile.target
index e7249915e7..491683e91d 100644
--- a/tests/tcg/aarch64/Makefile.target
+++ b/tests/tcg/aarch64/Makefile.target
@@ -25,6 +25,13 @@ run-pauth-%: QEMU_OPTS += -cpu max
run-plugin-pauth-%: QEMU_OPTS += -cpu max
endif
+# BTI Tests
+ifneq ($(DOCKER_IMAGE)$(CROSS_CC_HAS_ARMV8_BTI),)
+AARCH64_TESTS += bti-1
+bti-%: CFLAGS += -mbranch-protection=standard
+bti-%: LDFLAGS += -nostdlib
+endif
+
# Semihosting smoke test for linux-user
AARCH64_TESTS += semihosting
run-semihosting: semihosting
diff --git a/tests/tcg/configure.sh b/tests/tcg/configure.sh
index be51bdb5a4..e1b70e25f2 100755
--- a/tests/tcg/configure.sh
+++ b/tests/tcg/configure.sh
@@ -240,6 +240,10 @@ for target in $target_list; do
-march=armv8.3-a -o $TMPE $TMPC; then
echo "CROSS_CC_HAS_ARMV8_3=y" >> $config_target_mak
fi
+ if do_compiler "$target_compiler" $target_compiler_cflags \
+ -mbranch-protection=standard -o $TMPE $TMPC; then
+ echo "CROSS_CC_HAS_ARMV8_BTI=y" >> $config_target_mak
+ fi
;;
esac
--
2.25.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: [PATCH v10 4/8] linux-user/elfload: Fix coding style in load_elf_image
2020-10-02 21:59 ` [PATCH v10 4/8] linux-user/elfload: Fix coding style in load_elf_image Richard Henderson
@ 2020-10-03 17:34 ` Philippe Mathieu-Daudé
2020-10-08 13:03 ` Peter Maydell
1 sibling, 0 replies; 18+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-03 17:34 UTC (permalink / raw)
To: Richard Henderson, qemu-devel
Cc: peter.maydell, qemu-arm, alex.bennee, laurent
On 10/2/20 11:59 PM, Richard Henderson wrote:
> Fixing this now will clarify following patches.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
> linux-user/elfload.c | 12 +++++++++---
> 1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/linux-user/elfload.c b/linux-user/elfload.c
> index f6022fd704..7572a32a30 100644
> --- a/linux-user/elfload.c
> +++ b/linux-user/elfload.c
> @@ -2531,9 +2531,15 @@ static void load_elf_image(const char *image_name, int image_fd,
> abi_ulong vaddr, vaddr_po, vaddr_ps, vaddr_ef, vaddr_em, vaddr_len;
> int elf_prot = 0;
>
> - if (eppnt->p_flags & PF_R) elf_prot = PROT_READ;
> - if (eppnt->p_flags & PF_W) elf_prot |= PROT_WRITE;
> - if (eppnt->p_flags & PF_X) elf_prot |= PROT_EXEC;
> + if (eppnt->p_flags & PF_R) {
> + elf_prot |= PROT_READ;
> + }
> + if (eppnt->p_flags & PF_W) {
> + elf_prot |= PROT_WRITE;
> + }
> + if (eppnt->p_flags & PF_X) {
> + elf_prot |= PROT_EXEC;
> + }
>
> vaddr = load_bias + eppnt->p_vaddr;
> vaddr_po = TARGET_ELF_PAGEOFFSET(vaddr);
>
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v10 6/8] linux-user/elfload: Move PT_INTERP detection to first loop
2020-10-02 21:59 ` [PATCH v10 6/8] linux-user/elfload: Move PT_INTERP detection to first loop Richard Henderson
@ 2020-10-03 17:38 ` Philippe Mathieu-Daudé
2020-10-03 18:05 ` Philippe Mathieu-Daudé
0 siblings, 1 reply; 18+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-03 17:38 UTC (permalink / raw)
To: Richard Henderson, qemu-devel
Cc: peter.maydell, qemu-arm, alex.bennee, laurent
On 10/2/20 11:59 PM, Richard Henderson wrote:
> For BTI, we need to know if the executable is static or dynamic,
> which means looking for PT_INTERP earlier.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> linux-user/elfload.c | 60 +++++++++++++++++++++++---------------------
> 1 file changed, 31 insertions(+), 29 deletions(-)
>
> diff --git a/linux-user/elfload.c b/linux-user/elfload.c
> index 735ebfa190..6b422990ff 100644
> --- a/linux-user/elfload.c
> +++ b/linux-user/elfload.c
> @@ -2421,8 +2421,10 @@ static void load_elf_image(const char *image_name, int image_fd,
>
> mmap_lock();
>
> - /* Find the maximum size of the image and allocate an appropriate
> - amount of memory to handle that. */
> + /*
> + * Find the maximum size of the image and allocate an appropriate
> + * amount of memory to handle that. Locate the interpreter, if any.
> + */
> loaddr = -1, hiaddr = 0;
> info->alignment = 0;
> for (i = 0; i < ehdr->e_phnum; ++i) {
> @@ -2438,6 +2440,33 @@ static void load_elf_image(const char *image_name, int image_fd,
> }
> ++info->nsegs;
> info->alignment |= eppnt->p_align;
> + } else if (eppnt->p_type == PT_INTERP && pinterp_name) {
> + char *interp_name;
> +
> + if (*pinterp_name) {
> + errmsg = "Multiple PT_INTERP entries";
> + goto exit_errmsg;
> + }
> + interp_name = malloc(eppnt->p_filesz);
> + if (!interp_name) {
> + goto exit_perror;
> + }
> +
> + if (eppnt->p_offset + eppnt->p_filesz <= BPRM_BUF_SIZE) {
> + memcpy(interp_name, bprm_buf + eppnt->p_offset,
> + eppnt->p_filesz);
> + } else {
> + retval = pread(image_fd, interp_name, eppnt->p_filesz,
> + eppnt->p_offset);
> + if (retval != eppnt->p_filesz) {
Preexisting, free(interp_name)?
> + goto exit_perror;
> + }
> + }
> + if (interp_name[eppnt->p_filesz - 1] != 0) {
> + errmsg = "Invalid PT_INTERP entry";
Ditto, otherwise:
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> + goto exit_errmsg;
> + }
> + *pinterp_name = interp_name;
> }
> }
>
> @@ -2590,33 +2619,6 @@ static void load_elf_image(const char *image_name, int image_fd,
> if (vaddr_em > info->brk) {
> info->brk = vaddr_em;
> }
> - } else if (eppnt->p_type == PT_INTERP && pinterp_name) {
> - char *interp_name;
> -
> - if (*pinterp_name) {
> - errmsg = "Multiple PT_INTERP entries";
> - goto exit_errmsg;
> - }
> - interp_name = malloc(eppnt->p_filesz);
> - if (!interp_name) {
> - goto exit_perror;
> - }
> -
> - if (eppnt->p_offset + eppnt->p_filesz <= BPRM_BUF_SIZE) {
> - memcpy(interp_name, bprm_buf + eppnt->p_offset,
> - eppnt->p_filesz);
> - } else {
> - retval = pread(image_fd, interp_name, eppnt->p_filesz,
> - eppnt->p_offset);
> - if (retval != eppnt->p_filesz) {
> - goto exit_perror;
> - }
> - }
> - if (interp_name[eppnt->p_filesz - 1] != 0) {
> - errmsg = "Invalid PT_INTERP entry";
> - goto exit_errmsg;
> - }
> - *pinterp_name = interp_name;
> #ifdef TARGET_MIPS
> } else if (eppnt->p_type == PT_MIPS_ABIFLAGS) {
> Mips_elf_abiflags_v0 abiflags;
>
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v10 5/8] linux-user/elfload: Adjust iteration over phdr
2020-10-02 21:59 ` [PATCH v10 5/8] linux-user/elfload: Adjust iteration over phdr Richard Henderson
@ 2020-10-03 17:51 ` Philippe Mathieu-Daudé
2020-10-08 13:03 ` Peter Maydell
1 sibling, 0 replies; 18+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-03 17:51 UTC (permalink / raw)
To: Richard Henderson, qemu-devel; +Cc: peter.maydell, qemu-arm, laurent
On 10/2/20 11:59 PM, Richard Henderson wrote:
> The second loop uses a loop induction variable, and the first
> does not. Transform the first to match the second, to simplify
> a following patch moving code between them.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
> linux-user/elfload.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/linux-user/elfload.c b/linux-user/elfload.c
> index 7572a32a30..735ebfa190 100644
> --- a/linux-user/elfload.c
> +++ b/linux-user/elfload.c
> @@ -2426,17 +2426,18 @@ static void load_elf_image(const char *image_name, int image_fd,
> loaddr = -1, hiaddr = 0;
> info->alignment = 0;
> for (i = 0; i < ehdr->e_phnum; ++i) {
> - if (phdr[i].p_type == PT_LOAD) {
> - abi_ulong a = phdr[i].p_vaddr - phdr[i].p_offset;
> + struct elf_phdr *eppnt = phdr + i;
> + if (eppnt->p_type == PT_LOAD) {
> + abi_ulong a = eppnt->p_vaddr - eppnt->p_offset;
> if (a < loaddr) {
> loaddr = a;
> }
> - a = phdr[i].p_vaddr + phdr[i].p_memsz;
> + a = eppnt->p_vaddr + eppnt->p_memsz;
> if (a > hiaddr) {
> hiaddr = a;
> }
> ++info->nsegs;
> - info->alignment |= phdr[i].p_align;
> + info->alignment |= eppnt->p_align;
> }
> }
>
>
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v10 6/8] linux-user/elfload: Move PT_INTERP detection to first loop
2020-10-03 17:38 ` Philippe Mathieu-Daudé
@ 2020-10-03 18:05 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 18+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-03 18:05 UTC (permalink / raw)
To: Richard Henderson, qemu-devel; +Cc: peter.maydell, qemu-arm, laurent
On 10/3/20 7:38 PM, Philippe Mathieu-Daudé wrote:
> On 10/2/20 11:59 PM, Richard Henderson wrote:
>> For BTI, we need to know if the executable is static or dynamic,
>> which means looking for PT_INTERP earlier.
>>
>> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
>> ---
>> linux-user/elfload.c | 60 +++++++++++++++++++++++---------------------
>> 1 file changed, 31 insertions(+), 29 deletions(-)
>>
>> diff --git a/linux-user/elfload.c b/linux-user/elfload.c
>> index 735ebfa190..6b422990ff 100644
>> --- a/linux-user/elfload.c
>> +++ b/linux-user/elfload.c
>> @@ -2421,8 +2421,10 @@ static void load_elf_image(const char *image_name, int image_fd,
>>
>> mmap_lock();
>>
>> - /* Find the maximum size of the image and allocate an appropriate
>> - amount of memory to handle that. */
>> + /*
>> + * Find the maximum size of the image and allocate an appropriate
>> + * amount of memory to handle that. Locate the interpreter, if any.
>> + */
>> loaddr = -1, hiaddr = 0;
>> info->alignment = 0;
>> for (i = 0; i < ehdr->e_phnum; ++i) {
>> @@ -2438,6 +2440,33 @@ static void load_elf_image(const char *image_name, int image_fd,
>> }
>> ++info->nsegs;
>> info->alignment |= eppnt->p_align;
>> + } else if (eppnt->p_type == PT_INTERP && pinterp_name) {
>> + char *interp_name;
>> +
>> + if (*pinterp_name) {
>> + errmsg = "Multiple PT_INTERP entries";
>> + goto exit_errmsg;
>> + }
>> + interp_name = malloc(eppnt->p_filesz);
>> + if (!interp_name) {
>> + goto exit_perror;
>> + }
>> +
>> + if (eppnt->p_offset + eppnt->p_filesz <= BPRM_BUF_SIZE) {
>> + memcpy(interp_name, bprm_buf + eppnt->p_offset,
>> + eppnt->p_filesz);
>> + } else {
>> + retval = pread(image_fd, interp_name, eppnt->p_filesz,
>> + eppnt->p_offset);
>> + if (retval != eppnt->p_filesz) {
>
> Preexisting, free(interp_name)?
I just sent a patch using g_steal_pointer() instead:
https://lists.gnu.org/archive/html/qemu-devel/2020-10/msg00792.html
(Maybe I should have tagged it RFC as this is the first
time I try this API).
>
>> + goto exit_perror;
>> + }
>> + }
>> + if (interp_name[eppnt->p_filesz - 1] != 0) {
>> + errmsg = "Invalid PT_INTERP entry";
>
> Ditto, otherwise:
> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
>
>> + goto exit_errmsg;
>> + }
>> + *pinterp_name = interp_name;
>> }
>> }
>>
>> @@ -2590,33 +2619,6 @@ static void load_elf_image(const char *image_name, int image_fd,
>> if (vaddr_em > info->brk) {
>> info->brk = vaddr_em;
>> }
>> - } else if (eppnt->p_type == PT_INTERP && pinterp_name) {
>> - char *interp_name;
>> -
>> - if (*pinterp_name) {
>> - errmsg = "Multiple PT_INTERP entries";
>> - goto exit_errmsg;
>> - }
>> - interp_name = malloc(eppnt->p_filesz);
>> - if (!interp_name) {
>> - goto exit_perror;
>> - }
>> -
>> - if (eppnt->p_offset + eppnt->p_filesz <= BPRM_BUF_SIZE) {
>> - memcpy(interp_name, bprm_buf + eppnt->p_offset,
>> - eppnt->p_filesz);
>> - } else {
>> - retval = pread(image_fd, interp_name, eppnt->p_filesz,
>> - eppnt->p_offset);
>> - if (retval != eppnt->p_filesz) {
>> - goto exit_perror;
>> - }
>> - }
>> - if (interp_name[eppnt->p_filesz - 1] != 0) {
>> - errmsg = "Invalid PT_INTERP entry";
>> - goto exit_errmsg;
>> - }
>> - *pinterp_name = interp_name;
>> #ifdef TARGET_MIPS
>> } else if (eppnt->p_type == PT_MIPS_ABIFLAGS) {
>> Mips_elf_abiflags_v0 abiflags;
>>
>
>
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v10 0/8] linux-user: User support for AArch64 BTI
2020-10-02 21:59 [PATCH v10 0/8] linux-user: User support for AArch64 BTI Richard Henderson
` (7 preceding siblings ...)
2020-10-02 21:59 ` [PATCH v10 8/8] tests/tcg/aarch64: Add bti smoke test Richard Henderson
@ 2020-10-04 1:34 ` no-reply
8 siblings, 0 replies; 18+ messages in thread
From: no-reply @ 2020-10-04 1:34 UTC (permalink / raw)
To: richard.henderson
Cc: peter.maydell, qemu-arm, alex.bennee, qemu-devel, laurent
Patchew URL: https://patchew.org/QEMU/20201002215955.254866-1-richard.henderson@linaro.org/
Hi,
This series seems to have some coding style problems. See output below for
more information:
Type: series
Message-id: 20201002215955.254866-1-richard.henderson@linaro.org
Subject: [PATCH v10 0/8] linux-user: User support for AArch64 BTI
=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
Switched to a new branch 'test'
eaf5edb tests/tcg/aarch64: Add bti smoke test
c74e202 linux-user/elfload: Parse NT_GNU_PROPERTY_TYPE_0 notes
7e7c534 linux-user/elfload: Move PT_INTERP detection to first loop
1ded2cd linux-user/elfload: Adjust iteration over phdr
9a313b3 linux-user/elfload: Fix coding style in load_elf_image
ddc27b7 include/elf: Add defines related to GNU property notes for AArch64
eca4240 linux-user: Set PAGE_TARGET_1 for TARGET_PROT_BTI
6b3e8e3 linux-user/aarch64: Reset btype for signals
=== OUTPUT BEGIN ===
1/8 Checking commit 6b3e8e369613 (linux-user/aarch64: Reset btype for signals)
2/8 Checking commit eca424067459 (linux-user: Set PAGE_TARGET_1 for TARGET_PROT_BTI)
3/8 Checking commit ddc27b75549d (include/elf: Add defines related to GNU property notes for AArch64)
4/8 Checking commit 9a313b30265c (linux-user/elfload: Fix coding style in load_elf_image)
5/8 Checking commit 1ded2cdcd8ed (linux-user/elfload: Adjust iteration over phdr)
6/8 Checking commit 7e7c5343dde5 (linux-user/elfload: Move PT_INTERP detection to first loop)
7/8 Checking commit c74e202361a9 (linux-user/elfload: Parse NT_GNU_PROPERTY_TYPE_0 notes)
8/8 Checking commit eaf5edb50de6 (tests/tcg/aarch64: Add bti smoke test)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#32:
new file mode 100644
ERROR: externs should be avoided in .c files
#117: FILE: tests/tcg/aarch64/bti-crt.inc.c:13:
+int main(void);
total: 1 errors, 1 warnings, 136 lines checked
Patch 8/8 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===
Test command exited with code: 1
The full log is available at
http://patchew.org/logs/20201002215955.254866-1-richard.henderson@linaro.org/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-devel@redhat.com
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v10 4/8] linux-user/elfload: Fix coding style in load_elf_image
2020-10-02 21:59 ` [PATCH v10 4/8] linux-user/elfload: Fix coding style in load_elf_image Richard Henderson
2020-10-03 17:34 ` Philippe Mathieu-Daudé
@ 2020-10-08 13:03 ` Peter Maydell
1 sibling, 0 replies; 18+ messages in thread
From: Peter Maydell @ 2020-10-08 13:03 UTC (permalink / raw)
To: Richard Henderson
Cc: qemu-arm, Alex Bennée, QEMU Developers, Laurent Vivier
On Fri, 2 Oct 2020 at 23:00, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Fixing this now will clarify following patches.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> linux-user/elfload.c | 12 +++++++++---
> 1 file changed, 9 insertions(+), 3 deletions(-)
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
thanks
-- PMM
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v10 5/8] linux-user/elfload: Adjust iteration over phdr
2020-10-02 21:59 ` [PATCH v10 5/8] linux-user/elfload: Adjust iteration over phdr Richard Henderson
2020-10-03 17:51 ` Philippe Mathieu-Daudé
@ 2020-10-08 13:03 ` Peter Maydell
1 sibling, 0 replies; 18+ messages in thread
From: Peter Maydell @ 2020-10-08 13:03 UTC (permalink / raw)
To: Richard Henderson
Cc: qemu-arm, Alex Bennée, QEMU Developers, Laurent Vivier
On Fri, 2 Oct 2020 at 23:00, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> The second loop uses a loop induction variable, and the first
> does not. Transform the first to match the second, to simplify
> a following patch moving code between them.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> linux-user/elfload.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
thanks
-- PMM
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v10 7/8] linux-user/elfload: Parse NT_GNU_PROPERTY_TYPE_0 notes
2020-10-02 21:59 ` [PATCH v10 7/8] linux-user/elfload: Parse NT_GNU_PROPERTY_TYPE_0 notes Richard Henderson
@ 2020-10-08 14:02 ` Peter Maydell
2020-10-08 17:13 ` Richard Henderson
0 siblings, 1 reply; 18+ messages in thread
From: Peter Maydell @ 2020-10-08 14:02 UTC (permalink / raw)
To: Richard Henderson
Cc: qemu-arm, Alex Bennée, QEMU Developers, Laurent Vivier
On Fri, 2 Oct 2020 at 23:00, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> For aarch64, this includes the GNU_PROPERTY_AARCH64_FEATURE_1_BTI bit,
> which indicates that the image should be mapped with guarded pages.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> v9: Only map the startup executable with BTI; anything else must be
> handled by the interpreter.
> v10: Split out preparatory patches (pmm).
> @@ -2467,6 +2467,50 @@ static void load_elf_image(const char *image_name, int image_fd,
> goto exit_errmsg;
> }
> *pinterp_name = interp_name;
> + } else if (eppnt->p_type == PT_GNU_PROPERTY) {
> + /* Process NT_GNU_PROPERTY_TYPE_0. */
> + const uint32_t gnu0_magic = const_le32('G' | 'N' << 8 | 'U' << 16);
> + uint32_t note[7];
> +
> + /*
> + * The note contents are 7 words, but depending on LP64 vs ILP32
> + * there may be an 8th padding word at the end. Check for and
> + * read the minimum size. Further checks below will validate
> + * that the sizes of everything involved are as we expect.
> + */
> + if (eppnt->p_filesz < sizeof(note)) {
> + continue;
> + }
> + if (eppnt->p_offset + eppnt->p_filesz <= BPRM_BUF_SIZE) {
> + memcpy(note, bprm_buf + eppnt->p_offset, sizeof(note));
> + } else {
> + retval = pread(image_fd, note, sizeof(note), eppnt->p_offset);
> + if (retval != sizeof(note)) {
> + goto exit_perror;
> + }
> + }
> +#ifdef BSWAP_NEEDED
> + for (i = 0; i < ARRAY_SIZE(note); ++i) {
> + bswap32s(note + i);
> + }
> +#endif
> + /*
> + * Check that this is a NT_GNU_PROPERTY_TYPE_0 note.
> + * Again, descsz includes padding. Full size validation
> + * awaits checking the final payload.
> + */
> + if (note[0] != 4 || /* namesz */
> + note[1] < 12 || /* descsz */
> + note[2] != NT_GNU_PROPERTY_TYPE_0 || /* type */
> + note[3] != gnu0_magic) { /* name */
note[2] and note[3] are both basically magic numbers, AIUI.
Why do we have a #define for one but we assemble the other
with a const_le32() expression ?
> + continue;
> + }
> +#ifdef TARGET_AARCH64
> + if (note[4] == GNU_PROPERTY_AARCH64_FEATURE_1_AND &&
> + note[5] == 4) {
> + info->note_flags = note[6];
> + }
The spec for the .note.gnu.property section (which AIUI is
https://raw.githubusercontent.com/wiki/hjl-tools/linux-abi/linux-abi-draft.pdf
) says that the n_desc (words 4 and up) is an array of program
properties. There doesn't seem to be any guarantee that there
is only one entry or that the FEATURE_1_AND entry is the first
in the list. Don't we need to iterate through the array to find
matches? This seems to be how the kernel does it:
https://elixir.bootlin.com/linux/latest/source/fs/binfmt_elf.c#L786
(Is it worth adding the infrastructure to parse notes generically
the way the kernel has? I dunno if we think it's likely we'll
want to do this for more note types and/or other architectures
in future, so it might just be pointless complexity.)
thanks
-- PMM
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v10 7/8] linux-user/elfload: Parse NT_GNU_PROPERTY_TYPE_0 notes
2020-10-08 14:02 ` Peter Maydell
@ 2020-10-08 17:13 ` Richard Henderson
0 siblings, 0 replies; 18+ messages in thread
From: Richard Henderson @ 2020-10-08 17:13 UTC (permalink / raw)
To: Peter Maydell; +Cc: qemu-arm, Alex Bennée, QEMU Developers, Laurent Vivier
On 10/8/20 9:02 AM, Peter Maydell wrote:
>> + if (note[0] != 4 || /* namesz */
>> + note[1] < 12 || /* descsz */
>> + note[2] != NT_GNU_PROPERTY_TYPE_0 || /* type */
>> + note[3] != gnu0_magic) { /* name */
>
> note[2] and note[3] are both basically magic numbers, AIUI.
> Why do we have a #define for one but we assemble the other
> with a const_le32() expression ?
Because one is defined as a number, and the other is defined as a string. And
why *that* is, I don't know. Silliness, perhaps.
> The spec for the .note.gnu.property section (which AIUI is
> https://raw.githubusercontent.com/wiki/hjl-tools/linux-abi/linux-abi-draft.pdf
> ) says that the n_desc (words 4 and up) is an array of program
> properties. There doesn't seem to be any guarantee that there
> is only one entry or that the FEATURE_1_AND entry is the first
> in the list. Don't we need to iterate through the array to find
> matches? This seems to be how the kernel does it:
> https://elixir.bootlin.com/linux/latest/source/fs/binfmt_elf.c#L786
Hmm. I missed that change since the first time I looked at the in-flight patch
set.
> (Is it worth adding the infrastructure to parse notes generically
> the way the kernel has? I dunno if we think it's likely we'll
> want to do this for more note types and/or other architectures
> in future, so it might just be pointless complexity.)
I dunno about that either. I'm not really sure what "generically" would look
like without another exemplar. I'll look at what else
arch_parse_elf_property() is being used for.
r~
^ permalink raw reply [flat|nested] 18+ messages in thread
end of thread, other threads:[~2020-10-08 17:14 UTC | newest]
Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-02 21:59 [PATCH v10 0/8] linux-user: User support for AArch64 BTI Richard Henderson
2020-10-02 21:59 ` [PATCH v10 1/8] linux-user/aarch64: Reset btype for signals Richard Henderson
2020-10-02 21:59 ` [PATCH v10 2/8] linux-user: Set PAGE_TARGET_1 for TARGET_PROT_BTI Richard Henderson
2020-10-02 21:59 ` [PATCH v10 3/8] include/elf: Add defines related to GNU property notes for AArch64 Richard Henderson
2020-10-02 21:59 ` [PATCH v10 4/8] linux-user/elfload: Fix coding style in load_elf_image Richard Henderson
2020-10-03 17:34 ` Philippe Mathieu-Daudé
2020-10-08 13:03 ` Peter Maydell
2020-10-02 21:59 ` [PATCH v10 5/8] linux-user/elfload: Adjust iteration over phdr Richard Henderson
2020-10-03 17:51 ` Philippe Mathieu-Daudé
2020-10-08 13:03 ` Peter Maydell
2020-10-02 21:59 ` [PATCH v10 6/8] linux-user/elfload: Move PT_INTERP detection to first loop Richard Henderson
2020-10-03 17:38 ` Philippe Mathieu-Daudé
2020-10-03 18:05 ` Philippe Mathieu-Daudé
2020-10-02 21:59 ` [PATCH v10 7/8] linux-user/elfload: Parse NT_GNU_PROPERTY_TYPE_0 notes Richard Henderson
2020-10-08 14:02 ` Peter Maydell
2020-10-08 17:13 ` Richard Henderson
2020-10-02 21:59 ` [PATCH v10 8/8] tests/tcg/aarch64: Add bti smoke test Richard Henderson
2020-10-04 1:34 ` [PATCH v10 0/8] linux-user: User support for AArch64 BTI no-reply
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.