From: Richard Henderson <richard.henderson@linaro.org>
To: "Ilya Leoshkevich" <iii@linux.ibm.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Alex Bennée" <alex.bennee@linaro.org>,
philmd@linaro.org
Cc: qemu-devel@nongnu.org
Subject: Re: [PATCH RFC] linux-user: Allow gdbstub to ignore page protection
Date: Thu, 21 Dec 2023 10:33:51 +1100 [thread overview]
Message-ID: <7f2c38bc-d3d8-4d22-867e-74330dcb2ab8@linaro.org> (raw)
In-Reply-To: <20231215232908.1040209-1-iii@linux.ibm.com>
On 12/16/23 10:24, Ilya Leoshkevich wrote:
> @@ -377,22 +379,42 @@ int cpu_memory_rw_debug(CPUState *cpu, vaddr addr,
> flags = page_get_flags(page);
> if (!(flags & PAGE_VALID))
> return -1;
> + prot = ((flags & PAGE_READ) ? PROT_READ : 0) |
> + ((flags & PAGE_WRITE) ? PROT_WRITE : 0) |
> + ((flags & PAGE_EXEC) ? PROT_EXEC : 0);
See target_to_host_prot where guest PROT_EXEC is mapped to host PROT_READ.
This should be
flags & (PAGE_READ | PAGE_EXEC) ? PROT_READ
> + if (!(prot & PROT_WRITE)) {
> + if (target_mprotect(page, TARGET_PAGE_SIZE,
> + prot | PROT_WRITE)) {
> + return -1;
> + }
> + }
> /* XXX: this code should not depend on lock_user */
> - if (!(p = lock_user(VERIFY_WRITE, addr, l, 0)))
> + if (!(p = lock_user(VERIFY_NONE, addr, l, 0)))
> return -1;
> memcpy(p, buf, l);
> unlock_user(p, addr, l);
> + if (!(prot & PROT_WRITE)) {
> + if (target_mprotect(page, TARGET_PAGE_SIZE, prot)) {
> + return -1;
> + }
> + }
Is the mmap lock held here? You're opening up a window in which a page may be modified
but we don't catch the modification to translation blocks.
> + if (!(prot & PROT_READ)) {
> + if (target_mprotect(page, TARGET_PAGE_SIZE, prot | PROT_READ)) {
> + return -1;
> + }
> + }
I really really doubt you need to do this. The page is not accessible, so why expose it
at all? If you want to do this, I wonder if we should instead be interacting with ptrace?
r~
next prev parent reply other threads:[~2023-12-20 23:35 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-15 23:24 [PATCH RFC] linux-user: Allow gdbstub to ignore page protection Ilya Leoshkevich
2023-12-20 23:33 ` Richard Henderson [this message]
2023-12-21 12:26 ` Ilya Leoshkevich
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=7f2c38bc-d3d8-4d22-867e-74330dcb2ab8@linaro.org \
--to=richard.henderson@linaro.org \
--cc=alex.bennee@linaro.org \
--cc=iii@linux.ibm.com \
--cc=pbonzini@redhat.com \
--cc=philmd@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).