From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: alex.bennee@linaro.org
Subject: [PATCH 12/14] linux-user/elfload: Simplify vma_dump_size
Date: Tue, 27 Feb 2024 08:48:31 -1000 [thread overview]
Message-ID: <20240227184833.193836-13-richard.henderson@linaro.org> (raw)
In-Reply-To: <20240227184833.193836-1-richard.henderson@linaro.org>
Use the flags that we've already saved in order to test
accessibility. Use g2h_untagged and compare guest memory
directly instead of copy_from_user.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/elfload.c | 34 ++++++++++------------------------
1 file changed, 10 insertions(+), 24 deletions(-)
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 491e754f72..47b5ce3005 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -4166,37 +4166,23 @@ static int vma_get_mapping_count(const struct mm_struct *mm)
*/
static abi_ulong vma_dump_size(const struct vm_area_struct *vma)
{
- /* if we cannot even read the first page, skip it */
- if (!access_ok_untagged(VERIFY_READ, vma->vma_start, TARGET_PAGE_SIZE))
- return (0);
+ /* The area must be readable. */
+ if (!(vma->vma_flags & PROT_READ)) {
+ return 0;
+ }
/*
* Usually we don't dump executable pages as they contain
* non-writable code that debugger can read directly from
- * target library etc. However, thread stacks are marked
- * also executable so we read in first page of given region
- * and check whether it contains elf header. If there is
- * no elf header, we dump it.
+ * target library etc. If there is no elf header, we dump it.
*/
- if (vma->vma_flags & PROT_EXEC) {
- char page[TARGET_PAGE_SIZE];
-
- if (copy_from_user(page, vma->vma_start, sizeof (page))) {
- return 0;
- }
- if ((page[EI_MAG0] == ELFMAG0) &&
- (page[EI_MAG1] == ELFMAG1) &&
- (page[EI_MAG2] == ELFMAG2) &&
- (page[EI_MAG3] == ELFMAG3)) {
- /*
- * Mappings are possibly from ELF binary. Don't dump
- * them.
- */
- return (0);
- }
+ if (!(vma->vma_flags & PROT_WRITE) &&
+ (vma->vma_flags & PROT_EXEC) &&
+ memcmp(g2h_untagged(vma->vma_start), ELFMAG, SELFMAG) == 0) {
+ return 0;
}
- return (vma->vma_end - vma->vma_start);
+ return vma->vma_end - vma->vma_start;
}
static int vma_walker(void *priv, target_ulong start, target_ulong end,
--
2.34.1
next prev parent reply other threads:[~2024-02-27 18:50 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-27 18:48 [PATCH 00/14] linux-user: Rewrite core dump Richard Henderson
2024-02-27 18:48 ` [PATCH 01/14] linux-user/elfload: Disable core dump if getrlimit fails Richard Henderson
2024-02-27 19:40 ` Alex Bennée
2024-02-27 18:48 ` [PATCH 02/14] linux-user/elfload: Merge init_note_info and fill_note_info Richard Henderson
2024-02-27 19:42 ` Alex Bennée
2024-02-27 18:48 ` [PATCH 03/14] linux-user/elfload: Tidy fill_note_info and struct elf_note_info Richard Henderson
2024-02-27 18:48 ` [PATCH 04/14] linux-user/elfload: Stack allocate struct mm_struct Richard Henderson
2024-02-27 18:48 ` [PATCH 05/14] linux-user/elfload: Latch errno before cleanup in elf_core_dump Richard Henderson
2024-02-27 18:48 ` [PATCH 06/14] linux-user/elfload: Open core file after vma_init Richard Henderson
2024-02-27 18:48 ` [PATCH 07/14] linux-user/elfload: Truncate core file on open Richard Henderson
2024-02-27 18:48 ` [PATCH 08/14] linux-user/elfload: Lock cpu list and mmap during elf_core_dump Richard Henderson
2024-02-27 21:06 ` Alex Bennée
2024-02-27 18:48 ` [PATCH 09/14] linux-user/elfload: Size corefile before opening Richard Henderson
2024-02-27 18:48 ` [PATCH 10/14] linux-user/elfload: Write corefile elf header in one block Richard Henderson
2024-02-27 18:48 ` [PATCH 11/14] linux-user/elfload: Write process memory to core file in larger chunks Richard Henderson
2024-02-27 18:48 ` Richard Henderson [this message]
2024-02-27 18:48 ` [PATCH 13/14] linux-user/elfload: Rely on walk_memory_regions for vmas Richard Henderson
2024-02-27 18:48 ` [PATCH 14/14] linux-user/elfload: Unprotect regions before core dump 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=20240227184833.193836-13-richard.henderson@linaro.org \
--to=richard.henderson@linaro.org \
--cc=alex.bennee@linaro.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).