From: Ard Biesheuvel <ardb@kernel.org>
To: qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, Ard Biesheuvel <ardb@kernel.org>
Subject: [PATCH v2 1/2] hw/elf_ops: Implement missing endian swabbing for ELF notes
Date: Sun, 29 Sep 2024 20:06:57 +0200 [thread overview]
Message-ID: <20240929180659.3598-2-ardb@kernel.org> (raw)
In-Reply-To: <20240929180659.3598-1-ardb@kernel.org>
ELF notes have type and size fields in the elf_note header that need to
be swabbed before use if the host endianness differs from the endianness
of the ELF binary.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
include/hw/elf_ops.h.inc | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/include/hw/elf_ops.h.inc b/include/hw/elf_ops.h.inc
index 9c35d1b9da..8b563db2a3 100644
--- a/include/hw/elf_ops.h.inc
+++ b/include/hw/elf_ops.h.inc
@@ -41,6 +41,13 @@ static void glue(bswap_shdr, SZ)(struct elf_shdr *shdr)
bswapSZs(&shdr->sh_entsize);
}
+static void glue(bswap_nhdr, SZ)(struct elf_note *nhdr)
+{
+ bswap32s(&nhdr->n_namesz);
+ bswap32s(&nhdr->n_descsz);
+ bswap32s(&nhdr->n_type);
+}
+
static void glue(bswap_sym, SZ)(struct elf_sym *sym)
{
bswap32s(&sym->st_name);
@@ -275,7 +282,8 @@ fail:
static struct elf_note *glue(get_elf_note_type, SZ)(struct elf_note *nhdr,
elf_word note_size,
elf_word phdr_align,
- elf_word elf_note_type)
+ elf_word elf_note_type,
+ int must_swab)
{
elf_word nhdr_size = sizeof(struct elf_note);
elf_word elf_note_entry_offset = 0;
@@ -287,6 +295,9 @@ static struct elf_note *glue(get_elf_note_type, SZ)(struct elf_note *nhdr,
return NULL;
}
+ if (must_swab) {
+ glue(bswap_nhdr, SZ)(nhdr);
+ }
note_type = nhdr->n_type;
while (note_type != elf_note_type) {
nhdr_namesz = nhdr->n_namesz;
@@ -306,6 +317,9 @@ static struct elf_note *glue(get_elf_note_type, SZ)(struct elf_note *nhdr,
/* skip to the next ELF Note entry */
nhdr = (void *)nhdr + elf_note_entry_offset;
+ if (must_swab) {
+ glue(bswap_nhdr, SZ)(nhdr);
+ }
note_type = nhdr->n_type;
}
@@ -603,7 +617,8 @@ static ssize_t glue(load_elf, SZ)(const char *name, int fd,
nhdr = (struct elf_note *)data;
assert(translate_opaque != NULL);
nhdr = glue(get_elf_note_type, SZ)(nhdr, file_size, ph->p_align,
- *(uint64_t *)translate_opaque);
+ *(uint64_t *)translate_opaque,
+ must_swab);
if (nhdr != NULL) {
elf_note_fn((void *)nhdr, (void *)&ph->p_align, SZ == 64);
}
--
2.39.5
next prev parent reply other threads:[~2024-09-29 18:08 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-29 18:06 [PATCH v2 0/2] Fix PVH entrypoint parsing Ard Biesheuvel
2024-09-29 18:06 ` Ard Biesheuvel [this message]
2024-09-29 18:06 ` [PATCH v2 2/2] hw/x86: Always treat the PVH entrypoint as a 32-bit LE field Ard Biesheuvel
2024-11-21 8:08 ` [PATCH v2 0/2] Fix PVH entrypoint parsing Ard Biesheuvel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240929180659.3598-2-ardb@kernel.org \
--to=ardb@kernel.org \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.