[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Stable-9.1.1 34/49] linux-user: Fix parse_elf_properties GNU0_MAGIC che
From: |
Michael Tokarev |
Subject: |
[Stable-9.1.1 34/49] linux-user: Fix parse_elf_properties GNU0_MAGIC check |
Date: |
Wed, 16 Oct 2024 23:09:53 +0300 |
From: Richard Henderson <richard.henderson@linaro.org>
Comparing a string of 4 bytes only works in little-endian.
Adjust bulk bswap to only apply to the note payload.
Perform swapping of the note header manually; the magic
is defined so that it does not need a runtime swap.
Fixes: 83f990eb5adb ("linux-user/elfload: Parse NT_GNU_PROPERTY_TYPE_0 notes")
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2596
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Michael Tokarev <mjt@tls.msk.ru>
(cherry picked from commit 2884596f5f385b5712c356310dd4125a089888a8)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index b27dd01734..0b1c230b1c 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -3136,11 +3136,11 @@ static bool parse_elf_properties(const ImageSource *src,
}
/*
- * The contents of a valid PT_GNU_PROPERTY is a sequence
- * of uint32_t -- swap them all now.
+ * The contents of a valid PT_GNU_PROPERTY is a sequence of uint32_t.
+ * Swap most of them now, beyond the header and namesz.
*/
#ifdef BSWAP_NEEDED
- for (int i = 0; i < n / 4; i++) {
+ for (int i = 4; i < n / 4; i++) {
bswap32s(note.data + i);
}
#endif
@@ -3150,15 +3150,15 @@ static bool parse_elf_properties(const ImageSource *src,
* immediately follows nhdr and is thus at the 4th word. Further, all
* of the inputs to the kernel's round_up are multiples of 4.
*/
- if (note.nhdr.n_type != NT_GNU_PROPERTY_TYPE_0 ||
- note.nhdr.n_namesz != NOTE_NAME_SZ ||
+ if (tswap32(note.nhdr.n_type) != NT_GNU_PROPERTY_TYPE_0 ||
+ tswap32(note.nhdr.n_namesz) != NOTE_NAME_SZ ||
note.data[3] != GNU0_MAGIC) {
error_setg(errp, "Invalid note in PT_GNU_PROPERTY");
return false;
}
off = sizeof(note.nhdr) + NOTE_NAME_SZ;
- datasz = note.nhdr.n_descsz + off;
+ datasz = tswap32(note.nhdr.n_descsz) + off;
if (datasz > n) {
error_setg(errp, "Invalid note size in PT_GNU_PROPERTY");
return false;
--
2.39.5
- [Stable-9.1.1 00/49] Patch Round-up for stable 9.1.1, freeze on 2024-10-16 (frozen), Michael Tokarev, 2024/10/16
- [Stable-9.1.1 33/49] linux-user/flatload: Take mmap_lock in load_flt_binary(), Michael Tokarev, 2024/10/16
- [Stable-9.1.1 34/49] linux-user: Fix parse_elf_properties GNU0_MAGIC check,
Michael Tokarev <=
- [Stable-9.1.1 35/49] tcg/ppc: Use TCG_REG_TMP2 for scratch tcg_out_qemu_st, Michael Tokarev, 2024/10/16
- [Stable-9.1.1 36/49] tcg/ppc: Use TCG_REG_TMP2 for scratch index in prepare_host_addr, Michael Tokarev, 2024/10/16
- [Stable-9.1.1 37/49] target/m68k: Always return a temporary from gen_lea_mode, Michael Tokarev, 2024/10/16
- [Stable-9.1.1 38/49] meson: fix machine option for x86_version, Michael Tokarev, 2024/10/16
- [Stable-9.1.1 39/49] meson: define qemu_isa_flags, Michael Tokarev, 2024/10/16
- [Stable-9.1.1 40/49] meson: ensure -mcx16 is passed when detecting ATOMIC128, Michael Tokarev, 2024/10/16
- [Stable-9.1.1 41/49] hw/intc/arm_gicv3: Add cast to match the documentation, Michael Tokarev, 2024/10/16
- [Stable-9.1.1 42/49] hw/intc/arm_gicv3: Add cast to match the documentation, Michael Tokarev, 2024/10/16
- [Stable-9.1.1 43/49] hw/intc/arm_gicv3_cpuif: Add cast to match the documentation, Michael Tokarev, 2024/10/16
- [Stable-9.1.1 44/49] hw/char/pl011: Use correct masks for IBRD and FBRD, Michael Tokarev, 2024/10/16