mbox series

[v10,0/8] linux-user: User support for AArch64 BTI

Message ID 20201002215955.254866-1-richard.henderson@linaro.org
Headers show
Series linux-user: User support for AArch64 BTI | expand

Message

Richard Henderson Oct. 2, 2020, 9:59 p.m. UTC
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

Comments

Philippe Mathieu-Daudé Oct. 3, 2020, 6:05 p.m. UTC | #1
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;
>>
> 
>
no-reply@patchew.org Oct. 4, 2020, 1:34 a.m. UTC | #2
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