All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andreas Kemnade <andreas@kemnade.info>
To: Helge Deller <deller@gmx.de>
Cc: qemu-devel@nongnu.org, sre@kernel.org
Subject: Re: [PATCH] linux-user: fix issues with mmap on 4K guest on 16K host and library load
Date: Sat, 8 Aug 2026 15:40:00 +0200	[thread overview]
Message-ID: <20260808154000.149b159f@kemnade.info> (raw)
In-Reply-To: <6f98eb42-54ae-4909-b4f1-4ff683d3d6f9@gmx.de>

On Fri, 7 Aug 2026 23:26:07 +0200
Helge Deller <deller@gmx.de> wrote:

> On 8/5/26 18:40, Andreas Kemnade wrote:
> > Strace in qemu:
> > 198005 openat(AT_FDCWD,"/lib/arm-linux-gnueabihf/libselinux.so.1",O_RDONLY|O_LARGEFILE|O_CLOEXEC) = 3
> > 198005 read(3,0x40802570,512) = 512
> > 198005 statx(3,"",AT_EMPTY_PATH|AT_NO_AUTOMOUNT|AT_STATX_SYNC_AS_STAT,STATX_BASIC_STATS,0x408022a8) = 0
> > 198005 mmap2(NULL,269428,PROT_NONE,MAP_PRIVATE|MAP_ANONYMOUS|MAP_DENYWRITE,-1,0) = 0x40868000
> > 198005 mmap2(0x40870000,203892,PROT_EXEC|PROT_READ,MAP_PRIVATE|MAP_DENYWRITE|MAP_FIXED,3,0) = 0x40870000

Size of the file: 132612: allocated: 203892

End address: 0x408a1c74

> > 198005 munmap(0x40868000,32768) = 0
> > 198005 munmap(0x408a2000,31860) = 0
> > 198005 mprotect(0x40890000,61440,PROT_NONE) = 0
which just ends at 0x4089f000 (not 16K aligned)

> > 198005 mmap2(0x4089f000,8192,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_DENYWRITE|MAP_FIXED,3,0x1f) = -1 errno=14 (Bad address)
> > 
mmap2 sitting in that area mapping a part of the same file.

> > strace outside qemu:
> > [pid 195331] readlinkat(AT_FDCWD, "/usr/lib", 0x7fffd1a7fd00, 1023) = -1 EINVAL (Invalid argument)
> > [pid 195331] readlinkat(AT_FDCWD, "/usr/lib/arm-linux-gnueabihf", 0x7fffd1a7fd00, 1023) = -1 EINVAL (Invalid argument)
> > [pid 195331] readlinkat(AT_FDCWD, "/usr/lib/arm-linux-gnueabihf/libselinux.so.1", 0x7fffd1a7fd00, 1023) = -1 EINVAL (Invalid argument)
> > [pid 195331] faccessat(AT_FDCWD, "/usr/gnemul/qemu-arm/lib/arm-linux-gnueabihf/libselinux.so.1", F_OK) = -1 ENOENT (No such file or directory)
> > [pid 195331] openat(AT_FDCWD, "/lib/arm-linux-gnueabihf/libselinux.so.1", O_RDONLY|O_CLOEXEC) = 3
> > [pid 195331] read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\0\0\0\0004\0\0\0"..., 512) = 512
> > [pid 195331] statx(3, "", AT_STATX_SYNC_AS_STAT|AT_NO_AUTOMOUNT|AT_EMPTY_PATH, STATX_BASIC_STATS, {stx_mask=STATX_ALL|STATX_MNT_ID|STATX_SUBVOL, stx_attributes=0, stx_mode=S_IFREG|0644, stx_size=132612, ...}) = 0
> > [pid 195331] mmap(0x408a8000, 16384, PROT_NONE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS|MAP_DENYWRITE, -1, 0) = 0x408a8000
> > [pid 195331] mprotect(0x408a8000, 16384, PROT_WRITE) = 0
> > [pid 195331] mprotect(0x408a8000, 16384, PROT_NONE) = 0
> > [pid 195331] mmap(0x40868000, 262144, PROT_NONE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS|MAP_DENYWRITE, -1, 0) = 0x40868000
> > [pid 195331] mprotect(0x408a0000, 16384, PROT_WRITE) = 0
> > [pid 195331] pread64(3, "", 8192, 196608) = 0
> > [pid 195331] mprotect(0x408a0000, 16384, PROT_READ) = 0
> > [pid 195331] mmap(0x40870000, 196608, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0) = 0x40870000
> > [pid 195331] mmap(0x40868000, 32768, PROT_NONE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0) = 0x40868000
> > [pid 195331] mmap(0x408a4000, 32768, PROT_NONE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0) = 0x408a4000
> > [pid 195331] mprotect(0x4089c000, 16384, PROT_READ) = 0
> > [pid 195331] mprotect(0x40890000, 49152, PROT_NONE) = 0

ends at 0x4089c000

> > [pid 195331] mprotect(0x4089c000, 16384, PROT_WRITE) = 0
> > [pid 195331] pread64(3, 0x4089f000, 4096, 126976) = -1 EFAULT (Bad address)
> > 
reads from write-only area created by the mprotect before. 

> > That makes simple commands like ls --version to fail.
> > Tested was arm32 on a arm64 only host.
> > 
> > Fix that issue by truncating file mapping and replacing out-of-file
> > mappings by anonymous mappings.  
> 
> Could you please explain "the issue" and not just referring to the strace?
> It's not that easy to see the problem.
> 
> Thanks!
> Helge
> 
> Btw: you patch might fix this problem, but you may run into other problems too,
> see e.g.: https://gitlab.com/qemu-project/qemu/-/work_items/3410
> 
That is correct, but at least increases the amount of platforms to be
debootstrappable. Or maybe some better chances for same bitbake run
to get through.

Regards,
Andreas


      parent reply	other threads:[~2026-08-08 13:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-05 16:40 [PATCH] linux-user: fix issues with mmap on 4K guest on 16K host and library load Andreas Kemnade
2026-08-07 21:26 ` Helge Deller
2026-08-08  1:59   ` Richard Henderson
2026-08-08 13:40   ` Andreas Kemnade [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=20260808154000.149b159f@kemnade.info \
    --to=andreas@kemnade.info \
    --cc=deller@gmx.de \
    --cc=qemu-devel@nongnu.org \
    --cc=sre@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.