qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: malc <av1474@comtv.ru>
To: Alexander Graf <agraf@suse.de>
Cc: Peter Maydell <peter.maydell@linaro.org>,
	paul@codesourcery.com, riku.voipio@iki.fi, qemu-devel@nongnu.org,
	"Bernhard M. Wiedemann" <bwiedemann@suse.de>
Subject: Re: [Qemu-devel] ARM brk bug
Date: Sun, 4 Mar 2012 01:23:09 +0400 (MSK)	[thread overview]
Message-ID: <alpine.LNX.2.00.1203040117490.3760@linmac> (raw)
In-Reply-To: <93FCCE39-FC5B-43F1-B581-76D2AD1660A6@suse.de>

On Sat, 3 Mar 2012, Alexander Graf wrote:

> 
> On 02.03.2012, at 18:49, Peter Maydell wrote:
> 
> > On 27 February 2012 15:16, Bernhard M. Wiedemann <bwiedemann@suse.de> wrote:
> >> I found that running a debian arm5 bash with qemu runs into varying
> >> problems with -R but works without.
> > 
> > So I had a look at this this afternoon, and what seems to be happening
> > is that with -R, the call to target_mmap() in elfload.c:setup_arg_pages()
> > (which creates the stack) is putting the stack immediately after the
> > bash BSS segment in the address space. This means that brk() will
> > never be able to expand, and it looks like something in either bash
> > or libc's locale code isn't correctly handling the failure, so we
> > crash. (The segfault is from a strlen(NULL) from setlocale() I think.)
> > 
> > We should probably try to put the stack somewhere more sensible than
> > where it currently ends up...
> 
> I wrote a small test case to reproduce the breakage as far as I understood it at least:
> 
> #include <stdio.h>
> #include <stdlib.h>
> #include <unistd.h>
> #include <sys/mman.h>
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <sys/fcntl.h>
> 
> int main(int argc, char **argv)
> {
>     void *curbrk;
>     void *tmp;
>     char buf[1024];
>     int fd, r;
> 
>     tmp = mmap((void*)0x5000UL, 0x10000, PROT_READ|PROT_WRITE,
>                MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);

You are setting a bad example here (not that i know if that makes a
dent of a practical difference in this case): passing 0 as an fd even
in MAP_ANONYMOUS case is unsafe.

[..snip..]

-- 
mailto:av1474@comtv.ru

      parent reply	other threads:[~2012-03-03 21:23 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-27 15:16 [Qemu-devel] ARM brk bug Bernhard M. Wiedemann
2012-02-27 15:32 ` Peter Maydell
2012-02-27 17:03   ` Bernhard M. Wiedemann
2012-02-27 17:04     ` Peter Maydell
2012-03-02 17:49 ` Peter Maydell
2012-03-03  1:42   ` Alexander Graf
2012-03-03 21:02   ` Alexander Graf
2012-03-03 21:05     ` Alexander Graf
2012-03-03 21:17     ` Paul Brook
2012-03-03 22:08       ` Andreas Schwab
2012-03-03 21:23     ` malc [this message]

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=alpine.LNX.2.00.1203040117490.3760@linmac \
    --to=av1474@comtv.ru \
    --cc=agraf@suse.de \
    --cc=bwiedemann@suse.de \
    --cc=paul@codesourcery.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=riku.voipio@iki.fi \
    /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).