linux-user/aarch64: Reset btype for syscalls and signals
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
Peter Maydell
Reviewed-byQuoted 10 lines · Richard Henderson
The value of btype for syscalls is CONSTRAINED UNPREDICTABLE, so we need to make sure that the value is 0 before clone, fork, or syscall return.
The value of btype for signals is defined, but it does not make sense for a SIGILL handler to enter with the btype set as for the indirect branch that caused the SIGILL.
Signed-off-by Richard Henderson <[email protected]>
thanks
-- PMM
A message that is not in the archive (sent off-list or not yet received): [email protected]
Peter Maydell
Reviewed-byRe: [Qemu-devel] [PATCH v4 3/4] linux-user: Parse NT_GNU_PROPERTY_TYPE_0 notes
Quoted 47 lines · Richard Henderson
For aarch64, this includes the
GNU_PROPERTY_AARCH64_FEATURE_1_BTIbit, which indicates that the image should be mapped with guarded pages.Signed-off-by Richard Henderson <[email protected]>--- linux-user/elfload.c | 79 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 68 insertions(+), 11 deletions(-)linux-user/elfload.c +9
-1@@ -116,6 +116,10 @@ typedef abi_uint target_gid_t;#endif typedef abi_int target_pid_t ; + +#define TARGET_NT_GNU_PROPERTY_TYPE_0 5 + +#ifdef TARGET_I386 #define ELF_PLATFORM get_elf_platform()@@ -543,6 +547,10 @@ static const char *get_elf_platform(void)# define ELF_PLATFORM "aarch64"#endif +#define TARGET_GNU_PROPERTY_AARCH64_FEATURE_1_AND 0xc0000000 +#define TARGET_GNU_PROPERTY_AARCH64_FEATURE_1_BTI (1u << 0) +#define TARGET_GNU_PROPERTY_AARCH64_FEATURE_1_PAC (1u << 1) +static inline void init_thread (struct target_pt_regs *regs,struct image_info *infop) {@@ -2252,7 +2260,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 =PROT_EXEC ;const char *errmsg;/* First of all, some simple consistency checks */ @@ -2287,17 +2295,66 @@ static void load_elf_image(const char *image_name, int image_fd, loaddr =-1 , hiaddr =0 ; info->alignment =0 ;
linux-user/elfload.c static void load_elf_image(const char *image_name, int image_fd, · line 2302
Quoted 10 lines
linux-user/elfload.c +5
-4for (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; -if (a < loaddr) { - loaddr = a; +struct elf_phdr *eppnt = phdr + i; + +switch (eppnt->p_type) { +case PT_LOAD : + {
I think you have an extra layer of indent here that we usually don't do for switch statement cases.
linux-user/elfload.c static void load_elf_image(const char *image_name, int image_fd, · line 2312
Quoted 10 lines
linux-user/elfload.c +10
-0+#ifdef BSWAP_NEEDED +for (i =0 ; i <ARRAY_SIZE (note); ++i) { +bswap32s (note + i); + } +#endif +#ifdef HOST_WORDS_BIGENDIAN + gnu0 ='G' <<24 |'N' <<16 |'U' <<8 ; +#else + gnu0 ='G' |'N' <<8 |'U' <<16 ; +#endif
#define GNU0_MAGIC const_le32('G' | 'N' << 8 | 'U' << 16)
and then you can avoid the #ifdef HOST_WORDS_BIGENDIAN?
Quoted 31 lines
linux-user/elfload.c +16
-4+ +if (note[0 ] !=4 ||/* namesz */ + note[1 ] <12 ||/* descsz -- may include padding */ + note[2 ] !=TARGET_NT_GNU_PROPERTY_TYPE_0 ||/* type */ + note[3 ] != gnu0) {/* name */ +break ; + } +#ifdef TARGET_AARCH64 +if (note[4 ] ==TARGET_GNU_PROPERTY_AARCH64_FEATURE_1_AND && + note[5 ] ==4 && + (note[6 ] &TARGET_GNU_PROPERTY_AARCH64_FEATURE_1_BTI )) { + prot_exec |=TARGET_PROT_BTI ; + } +#endif } - ++info->nsegs; - info->alignment |= phdr[i].p_align; +break ; } }@@ -2359,7 +2416,7 @@ static void load_elf_image(const char *image_name, int image_fd,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_X ) elf_prot |= prot_exec; vaddr = load_bias + eppnt->p_vaddr; vaddr_po =TARGET_ELF_PAGEOFFSET (vaddr); --
Quoted 1 line
2.17.1
Otherwise
thanks
-- PMM
Re: [Qemu-devel] [PATCH v4 3/4] linux-user: Parse NT_GNU_PROPERTY_TYPE_0 notes
Quoted 8 lines · Peter Maydell
Review
Quoted 5 lines
(quoted diff) +5
-0+ struct elf_phdr *eppnt = phdr + i; + + switch (eppnt->p_type) { + case PT_LOAD: + {I think you have an extra layer of indent here that we usually don't do for switch statement cases.
No, that indent is exactly right for a compound statement not associated with an if/while/whatnot.
Quoted 3 lines
#define
GNU0_MAGICconst_le32('G' | 'N' << 8 | 'U' << 16)and then you can avoid the #ifdef
HOST_WORDS_BIGENDIAN?
Sure.
r~
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [Qemu-devel] [PATCH v4 2/4] linux-user: Set PAGE_TARGET_1 for TARGET_PROT_BTI
Quoted 9 lines · Richard Henderson
There is agreement that there will be a mmap/mprotect bit,
although no word yet on the value or the name. Invent a
name to make forward progress.The
PAGE_TARGET_1bit, is qemu internal, and allows the target something to query from the guest page tables.Signed-off-by Richard Henderson <[email protected]>
This looks ok code-wise, but we'd need to hide it behind a defaults-to-off x-something property if we wanted to commit it before the kernel ABI is fixed.
Do we also need to handle this in mprotect() ?
thanks
-- PMM
Re: [Qemu-devel] [PATCH v4 2/4] linux-user: Set PAGE_TARGET_1 for TARGET_PROT_BTI
Quoted 3 lines · Peter Maydell
This looks ok code-wise, but we'd need to hide it behind a defaults-to-off x-something property if we wanted to commit it before the kernel ABI is fixed.
I'm not intending to change the user-level abi, only the internal abi within qemu, for handling of the elf notes.
You think this should be done differently, so that there's zero possibility of a user-level setting the relevant bit?
Quoted 1 line
Do we also need to handle this in
mprotect()?
Not until there's a kernel abi.
r~
Re: [Qemu-devel] [PATCH v4 2/4] linux-user: Set PAGE_TARGET_1 for TARGET_PROT_BTI
Quoted 8 lines · Richard Henderson
Quoted 3 lines · Peter Maydell
This looks ok code-wise, but we'd need to hide it behind a defaults-to-off x-something property if we wanted to commit it before the kernel ABI is fixed.
I'm not intending to change the user-level abi, only the internal abi within qemu, for handling of the elf notes.
You're changing target_mmap(), which is used by the guest mmap syscall, though, right?
Quoted 2 lines
You think this should be done differently, so that there's zero possibility of a user-level setting the relevant bit?
I think that we shouldn't allow guest binaries written to the ad-hoc TARGET_PROT_BTI ABI to work without an explicit x-something command line argument to QEMU, to indicate that the user knows they're doing something odd and that these binaries won't always continue to work in future QEMU versions.
thanks
-- PMM
Re: [Qemu-devel] [PATCH v4 2/4] linux-user: Set PAGE_TARGET_1 for TARGET_PROT_BTI
Quoted 8 lines · Peter Maydell
Quoted 6 lines · Richard Henderson
Quoted 3 lines · Peter Maydell
This looks ok code-wise, but we'd need to hide it behind a defaults-to-off x-something property if we wanted to commit it before the kernel ABI is fixed.
Quoted 5 lines
Quoted 2 lines
I'm not intending to change the user-level abi, only the internal abi within qemu, for handling of the elf notes.
You're changing
target_mmap(), which is used by the guest mmap syscall, though, right?
Yes, but it's also used by elfload.c to map the executable.
Quoted 3 lines
I think that we shouldn't allow guest binaries written to the ad-hoc
TARGET_PROT_BTIABI to work without an explicit x-something command line argument to QEMU...
The guest binary is not written to an ad-hoc abi.
It is written to the finalized ELF note abi, which I am trying to implement with a *private* QEMU abi.
r~