qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Tobias Koch <tobias.koch@nonterra.com>
To: Laurent Vivier <laurent@vivier.eu>, qemu-devel@nongnu.org
Subject: Re: [PATCH] linux-user: mremap fails with EFAULT if address range overlaps with stack guard
Date: Mon, 15 Jun 2020 23:28:02 +0300	[thread overview]
Message-ID: <d58a375c-42a0-a1a6-8970-e4aefa5a646b@nonterra.com> (raw)
In-Reply-To: <3c9dffdf-b4be-d17c-730d-5a65665b3eac@nonterra.com>

Hm, I see I need to have another look at this :)

On 6/15/20 10:17 AM, Tobias Koch wrote:
> Hi Laurent,
>
> the code in musl libc probing the stack is in
>
>     https://git.musl-libc.org/cgit/musl/plain/src/thread/pthread_getattr_np.c
>
> The setup in elfload.c does work, but only when reserved_va is not set. In that case, any stack guard violation is
> handled by the host kernel and thus results in the expected EFAULT.
>
> However, in case of e.g. a 32bit target being emulated on a 64bit host, reserved_va is set and the current code in
> mmap.c will only produce a more generic ENOMEM, deviating from the kernel's behavior.
>
>
> On 5/7/20 5:35 PM, Laurent Vivier wrote:
>> Le 05/03/2020 à 22:05, Tobias Koch a écrit :
>>> If the address range starting at old_address overlaps with the stack guard it
>>> is invalid and mremap must fail with EFAULT. The musl c library relies on this
>>> behavior to detect the stack size, which it does by doing consecutive mremaps
>>> until it hits the stack guard. Without this patch, software (such as the Ruby
>>> interpreter) that calls pthread_getattr_np under musl will crash on 32 bit
>>> targets emulated on a 64 bit host.
>> Could you share some pointers to the code that is doing this?
>>
>> We have already this kind of code in linux-user/elfload.c,
>> setup_arg_pages(): could you check why it doesn't work?
>>
>> Thanks,
>> Laurent


  reply	other threads:[~2020-06-15 20:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-05 21:05 [PATCH] linux-user: mremap fails with EFAULT if address range overlaps with stack guard Tobias Koch
2020-05-07 14:35 ` Laurent Vivier
2020-06-15  7:17   ` Tobias Koch
2020-06-15 20:28     ` Tobias Koch [this message]
2020-06-15 21:10       ` Tobias Koch
2020-07-04 14:44         ` Tobias Koch

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=d58a375c-42a0-a1a6-8970-e4aefa5a646b@nonterra.com \
    --to=tobias.koch@nonterra.com \
    --cc=laurent@vivier.eu \
    --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).