From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
Subject: [PATCH v4 03/18] linux-user: Do not clobber bprm_buf swapping ehdr
Date: Wed, 16 Aug 2023 11:03:23 -0700 [thread overview]
Message-ID: <20230816180338.572576-4-richard.henderson@linaro.org> (raw)
In-Reply-To: <20230816180338.572576-1-richard.henderson@linaro.org>
Rearrange the allocation of storage for ehdr between load_elf_image
and load_elf_binary. The same set of copies are done, but we don't
modify bprm_buf, which will be important later.
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/elfload.c | 25 ++++++++++++++-----------
1 file changed, 14 insertions(+), 11 deletions(-)
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index ac03beb01b..11bbf4e99b 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -3019,16 +3019,17 @@ static bool parse_elf_properties(int image_fd,
On return: INFO values will be filled in, as necessary or available. */
static void load_elf_image(const char *image_name, int image_fd,
- struct image_info *info, char **pinterp_name,
+ struct image_info *info, struct elfhdr *ehdr,
+ char **pinterp_name,
char bprm_buf[BPRM_BUF_SIZE])
{
- struct elfhdr *ehdr = (struct elfhdr *)bprm_buf;
struct elf_phdr *phdr;
abi_ulong load_addr, load_bias, loaddr, hiaddr, error;
int i, retval, prot_exec;
Error *err = NULL;
/* First of all, some simple consistency checks */
+ memcpy(ehdr, bprm_buf, sizeof(*ehdr));
if (!elf_check_ident(ehdr)) {
error_setg(&err, "Invalid ELF image for this architecture");
goto exit_errmsg;
@@ -3343,6 +3344,7 @@ static void load_elf_image(const char *image_name, int image_fd,
static void load_elf_interp(const char *filename, struct image_info *info,
char bprm_buf[BPRM_BUF_SIZE])
{
+ struct elfhdr ehdr;
int fd, retval;
Error *err = NULL;
@@ -3364,7 +3366,7 @@ static void load_elf_interp(const char *filename, struct image_info *info,
memset(bprm_buf + retval, 0, BPRM_BUF_SIZE - retval);
}
- load_elf_image(filename, fd, info, NULL, bprm_buf);
+ load_elf_image(filename, fd, info, &ehdr, NULL, bprm_buf);
}
static int symfind(const void *s0, const void *s1)
@@ -3557,8 +3559,14 @@ uint32_t get_elf_eflags(int fd)
int load_elf_binary(struct linux_binprm *bprm, struct image_info *info)
{
+ /*
+ * We need a copy of the elf header for passing to create_elf_tables.
+ * We will have overwritten the original when we re-use bprm->buf
+ * while loading the interpreter. Allocate the storage for this now
+ * and let elf_load_image do any swapping that may be required.
+ */
+ struct elfhdr ehdr;
struct image_info interp_info;
- struct elfhdr elf_ex;
char *elf_interpreter = NULL;
char *scratch;
@@ -3570,12 +3578,7 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info)
info->start_mmap = (abi_ulong)ELF_START_MMAP;
load_elf_image(bprm->filename, bprm->fd, info,
- &elf_interpreter, bprm->buf);
-
- /* ??? We need a copy of the elf header for passing to create_elf_tables.
- If we do nothing, we'll have overwritten this when we re-use bprm->buf
- when we load the interpreter. */
- elf_ex = *(struct elfhdr *)bprm->buf;
+ &ehdr, &elf_interpreter, bprm->buf);
/* Do this so that we can load the interpreter, if need be. We will
change some of these later */
@@ -3662,7 +3665,7 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info)
target_mprotect(tramp_page, TARGET_PAGE_SIZE, PROT_READ | PROT_EXEC);
}
- bprm->p = create_elf_tables(bprm->p, bprm->argc, bprm->envc, &elf_ex,
+ bprm->p = create_elf_tables(bprm->p, bprm->argc, bprm->envc, &ehdr,
info, (elf_interpreter ? &interp_info : NULL));
info->start_stack = bprm->p;
--
2.34.1
next prev parent reply other threads:[~2023-08-16 18:06 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-16 18:03 [PATCH v4 00/18] linux-user: Implement VDSOs Richard Henderson
2023-08-16 18:03 ` [PATCH v4 01/18] linux-user: Introduce imgsrc_read, imgsrc_read_alloc Richard Henderson
2023-08-16 22:48 ` Philippe Mathieu-Daudé
2023-08-16 18:03 ` [PATCH v4 02/18] linux-user: Tidy loader_exec Richard Henderson
2023-08-16 18:03 ` Richard Henderson [this message]
2023-08-16 18:03 ` [PATCH v4 04/18] linux-user: Use ImageSource in load_elf_image Richard Henderson
2023-08-16 18:03 ` [PATCH v4 05/18] linux-user: Use ImageSource in load_symbols Richard Henderson
2023-08-16 22:51 ` Philippe Mathieu-Daudé
2023-08-16 18:03 ` [PATCH v4 06/18] linux-user: Replace bprm->fd with bprm->src.fd Richard Henderson
2023-08-16 18:03 ` [PATCH v4 07/18] linux-user: Load vdso image if available Richard Henderson
2023-08-18 7:28 ` gaosong
2023-08-18 15:38 ` Richard Henderson
2023-08-16 18:03 ` [PATCH v4 08/18] linux-user: Add gen-vdso tool Richard Henderson
2023-08-16 18:03 ` [PATCH v4 09/18] linux-user/i386: Add vdso Richard Henderson
2023-08-16 18:03 ` [PATCH v4 10/18] linux-user/x86_64: " Richard Henderson
2023-08-16 18:03 ` [PATCH v4 11/18] linux-user/aarch64: " Richard Henderson
2023-08-16 18:03 ` [PATCH v4 12/18] linux-user/arm: " Richard Henderson
2023-08-16 18:03 ` [PATCH v4 13/18] linux-user/hppa: " Richard Henderson
2023-08-16 18:03 ` [PATCH v4 14/18] linux-user/riscv: " Richard Henderson
2023-08-16 18:03 ` [PATCH v4 15/18] linux-user/loongarch64: " Richard Henderson
2023-08-18 7:28 ` gaosong
2023-08-16 18:03 ` [PATCH v4 16/18] linux-user/ppc: " Richard Henderson
2023-08-16 18:03 ` [PATCH v4 17/18] linux-user/s390x: Rename __SIGNAL_FRAMESIZE to STACK_FRAME_OVERHEAD Richard Henderson
2023-08-16 18:03 ` [PATCH v4 18/18] linux-user/s390x: Add vdso Richard Henderson
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=20230816180338.572576-4-richard.henderson@linaro.org \
--to=richard.henderson@linaro.org \
--cc=f4bug@amsat.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).