bug#50151: Coreutils, aarch64 and chroot

2021-08-25 Thread Assaf Gordon

tag 50151 notabug
close 50151
stop

On 2021-08-25 12:54 p.m., Frans de Boer wrote:

On 8/25/21 10:16 AM, Assaf Gordon wrote:

  qemu-aarch64 -strace -L /newroot \
  /newroot/usr/sbin/chroot /newroot /usr/bin/env --version 2&1 \
  | tee log.txt

@assaf: your suggestions no. 1 and 2, had the predicted results. Thus, 
suggestion no. 3 failed because of suggestion no.2. I followed then 
suggestion 4 and attached the strace output to this message. It seems 
that chroot is working as expected, only env seems to fail with an error.


Not exactly:
The 'chroot' system-call *seems* to succeed,
followed by a failed "execve(2)" system call to execute another binary.
That "execve" system fails - so it is not 'env' per-se,
it is any program that will try to execute another aarch64 binary.

Learning that, searching for "qemu-user", "chroot" and "architecture"
leads to several web pages detailing similar errors (and few suggested
solutions):

https://wiki.gentoo.org/wiki/Crossdev_qemu-static-user-chroot

https://newbedev.com/how-can-i-chroot-into-a-filesystem-with-a-different-architechture

https://ownyourbits.com/2018/06/13/transparently-running-binaries-from-any-architecture-in-linux-with-qemu-and-binfmt_misc/


I hope you have some clue of what is going wrong.


With the above information, we can conclude this is not a bug
in coreutils - it is a limitation of the linux+qemu-user setup.

So I'm closing this item and marking it as "not a bug",
but discussion can continue by replying to this thread.

regards,
 - assaf








bug#50167: fixes for "fmt - -" etc.

2021-08-25 Thread Jim Meyering
On Wed, Aug 25, 2021, 4:37 PM Bernhard Voelker 
wrote:

> On 8/25/21 10:38 AM, Jim Meyering wrote:
> > * cfg.mk (exclude_file_name_regexp--sc_system_h_headers):
> > Add find-mount-point.h to the regexp.
>
> +1
> even better, thanks.
>

Thanks. Pushed.

>


bug#50151: Coreutils, aarch64 and chroot

2021-08-25 Thread Frans de Boer

On 8/25/21 10:16 AM, Assaf Gordon wrote:

Hello,

On 2021-08-24 2:39 a.m., Paul Eggert wrote:
However, I think it'll be a better use of our time for you to debug 
this one yourself. It doesn't sound like a Coreutils problem; it 
sounds like a problem in your virtual machine setup, and you're the 
best expert on that setup.


Few suggestions to check, that might help you and us to troubleshoot:

1. ensure the binaries are indeed for aarch64:

   file /newroot/usr/sbin/chroot
   file /newroot/usr/bin/env
   file /newroot/usr/bin/bash

it should say something like
  "ELF 64-bit LSB pie executable, ARM aarch64"
for all of them.


2. ensure each binary works by itself:

 qemu-aarch64 -L /newroot /newroot/usr/sbin/chroot --version
 qemu-aarch64 -L /newroot /newroot/usr/bin/env --version
 qemu-aarch64 -L /newroot /newroot/usr/bin/bash --version

(the actual version doesn't matter here, the main thing is that
the qemu user-mode emulator was able to run the binaries.)

On 2021-08-21 4:33 a.m., Frans de Boer wrote:


Running 'qemu-aarch64 -L /newroot /newroot/usr/bin/bash -c 
/usr/bin/env> --help' does show the env help text. So, I guess chroot

is to blame?

Note that the above command runs your *host's* /usr/bin/env
because chroot is not used - the binary under qemu
 (/newroot/usr/bin/bash) sees your host's file system.

Observe with:

  qemu-aarch64 -L /newroot /newroot/usr/bin/bash -c /bin/uname -m
  qemu-aarch64 -L /newroot /newroot/usr/bin/env /bin/uname -m

I'm guessing you will see "x86_64", not "aarch64".

3. What you should try is:

  qemu-aarch64 -L /newroot \
 /newroot/usr/bin/bash -c /newroot/usr/bin/env --version
and:
  qemu-aarch64 -L /newroot \
 /newroot/usr/bin/env /newroot/usr/bin/bash --version

In both cases, one aarch64 binary will try to execute another aach64 
binary. Do these work for you, or are you seeing an error?




4. Use qemu's "-strace" to see the syscalls, hopefully
that will help pinpoint the cause:

  qemu-aarch64 -strace -L /newroot \
  /newroot/usr/sbin/chroot /newroot /usr/bin/env --version 2&1 \
  | tee log.txt

If the command results in an error, the "log.txt" file will show
more details about what failed.
If you're not familiar with 'strace' output, post it here as an email 
attachment.



Hope this helps,
 - assaf

P.S.

On 2021-08-24 2:39 a.m., Paul Eggert wrote:

A complete set of instructions for an outsider to reproduce the
problem from scratch.  Assume the outsider is running Fedora 34
x86-64 (since that's what I'm running :-).

I'm not familiar with Fedora, but on Debian/x86_64 the following works:

   apt-get qemu-user
   apt-get install crossbuild-essential-arm64 libc6-arm64-cross

   cd coreutils
   ./configure --host=aarch64-linux-gnu
   make

then:

    $ qemu-aarch64 -L /usr/aarch64-linux-gnu/ ./src/uname -m
    aarch64

Somewhat related:

    $ qemu-aarch64 -L /usr/aarch64-linux-gnu/ ./src/env ./src/uname -m
    /lib/ld-linux-aarch64.so.1: No such file or directory

This fails because once "inside" qemu, the aarch64 searches for
"/lib/ld-linux-aarch64.so.1" but the file is in
"/usr/aarch64-linux-gnu/lib/ld-linux-aarch64.so.1".
One possible work-around is to build static binaries.

I don't want to assume that is the culprit for Frans, so we'll wait 
for the logs...



@assaf: your suggestions no. 1 and 2, had the predicted results. Thus, 
suggestion no. 3 failed because of suggestion no.2. I followed then 
suggestion 4 and attached the strace output to this message. It seems 
that chroot is working as expected, only env seems to fail with an error.


I hope you have some clue of what is going wrong.

--- Frans.

--
A: Yes, just like thatA: Ja, net zo
Q: Oh, Just like reading a book backwards Q: Oh, net als een boek 
achterstevoren lezen
A: Because it upsets the natural flow of a story  A: Omdat het de natuurlijke 
gang uit het verhaal haalt
Q: Why is top-posting annoying?   Q: Waarom is Top-posting zo 
irritant?

1388 brk(NULL) = 0x0041b000
1388 uname(0x55007ff6b8) = 0
1388 faccessat(AT_FDCWD,"/etc/ld.so.preload",R_OK,AT_EACCESS|0x34cc8) = -1 
errno=2 (No such file or directory)
1388 openat(AT_FDCWD,"/etc/ld.so.cache",O_RDONLY|O_CLOEXEC) = 3
1388 newfstatat(3,"",0x0055007fec90,0x1000) = 0
1388 mmap(NULL,78408,PROT_READ,MAP_PRIVATE,3,0) = 0x005500839000
1388 close(3) = 0
1388 
openat(AT_FDCWD,"/usr/lib/tls/aarch64/atomics/libc.so.6",O_RDONLY|O_CLOEXEC) = 
-1 errno=2 (No such file or directory)
1388 newfstatat(AT_FDCWD,"/usr/lib/tls/aarch64/atomics",0x0055007fecc0,0) = 
-1 errno=2 (No such file or directory)
1388 openat(AT_FDCWD,"/usr/lib/tls/aarch64/libc.so.6",O_RDONLY|O_CLOEXEC) = -1 
errno=2 (No such file or directory)
1388 newfstatat(AT_FDCWD,"/usr/lib/tls/aarch64",0x0055007fecc0,0) = -1 
errno=2 (No such file or directory)
1388 openat(AT_FDCWD,"/usr/lib/tls/atomics/libc.so.6",O_RDONLY|O_CLOEXEC) = -1 
errno=2 (No such file or directory)
1388 

bug#50167: fixes for "fmt - -" etc.

2021-08-25 Thread Bernhard Voelker
On 8/25/21 10:38 AM, Jim Meyering wrote:
> * cfg.mk (exclude_file_name_regexp--sc_system_h_headers):
> Add find-mount-point.h to the regexp.

+1
even better, thanks.

Have a nice day,
Berny





bug#50167: fixes for "fmt - -" etc.

2021-08-25 Thread Jim Meyering
On Tue, Aug 24, 2021 at 11:10 PM Paul Eggert  wrote:
> On 8/24/21 12:42 PM, Bernhard Voelker wrote:
> > Was there a particular reason to include stdlib.h?
>
> It's needed to declare 'free', which is used by  _GL_ATTRIBUTE_DEALLOC_FREE.
>
> I added "#include " so that find-mount-point.h would be an
> independent header, potentially useful outside coreutils. If that's the
> intent, we should fix "make syntax-check" to not complain about this
> situation. If it's not the intent then your patch looks good.
>
> Jim, what's your opinion on this?

I propose this change:


0001-maint-avoid-new-syntax-check-failure.patch
Description: Binary data


bug#50151: Coreutils, aarch64 and chroot

2021-08-25 Thread Assaf Gordon

Hello,

On 2021-08-24 2:39 a.m., Paul Eggert wrote:
However, I think it'll be a better use of our time for you to debug this 
one yourself. It doesn't sound like a Coreutils problem; it sounds like 
a problem in your virtual machine setup, and you're the best expert on 
that setup.


Few suggestions to check, that might help you and us to troubleshoot:

1. ensure the binaries are indeed for aarch64:

   file /newroot/usr/sbin/chroot
   file /newroot/usr/bin/env
   file /newroot/usr/bin/bash

it should say something like
  "ELF 64-bit LSB pie executable, ARM aarch64"
for all of them.


2. ensure each binary works by itself:

 qemu-aarch64 -L /newroot /newroot/usr/sbin/chroot --version
 qemu-aarch64 -L /newroot /newroot/usr/bin/env --version
 qemu-aarch64 -L /newroot /newroot/usr/bin/bash --version

(the actual version doesn't matter here, the main thing is that
the qemu user-mode emulator was able to run the binaries.)

On 2021-08-21 4:33 a.m., Frans de Boer wrote:


Running 'qemu-aarch64 -L /newroot /newroot/usr/bin/bash -c 
/usr/bin/env> --help' does show the env help text. So, I guess chroot

is to blame?

Note that the above command runs your *host's* /usr/bin/env
because chroot is not used - the binary under qemu
 (/newroot/usr/bin/bash) sees your host's file system.

Observe with:

  qemu-aarch64 -L /newroot /newroot/usr/bin/bash -c /bin/uname -m
  qemu-aarch64 -L /newroot /newroot/usr/bin/env /bin/uname -m

I'm guessing you will see "x86_64", not "aarch64".

3. What you should try is:

  qemu-aarch64 -L /newroot \
 /newroot/usr/bin/bash -c /newroot/usr/bin/env --version
and:
  qemu-aarch64 -L /newroot \
 /newroot/usr/bin/env /newroot/usr/bin/bash --version

In both cases, one aarch64 binary will try to execute another aach64 
binary. Do these work for you, or are you seeing an error?




4. Use qemu's "-strace" to see the syscalls, hopefully
that will help pinpoint the cause:

  qemu-aarch64 -strace -L /newroot \
  /newroot/usr/sbin/chroot /newroot /usr/bin/env --version 2&1 \
  | tee log.txt

If the command results in an error, the "log.txt" file will show
more details about what failed.
If you're not familiar with 'strace' output, post it here as an email 
attachment.



Hope this helps,
 - assaf

P.S.

On 2021-08-24 2:39 a.m., Paul Eggert wrote:

A complete set of instructions for an outsider to reproduce the
problem from scratch.  Assume the outsider is running Fedora 34
x86-64 (since that's what I'm running :-).

I'm not familiar with Fedora, but on Debian/x86_64 the following works:

   apt-get qemu-user
   apt-get install crossbuild-essential-arm64 libc6-arm64-cross

   cd coreutils
   ./configure --host=aarch64-linux-gnu
   make

then:

$ qemu-aarch64 -L /usr/aarch64-linux-gnu/ ./src/uname -m
aarch64

Somewhat related:

$ qemu-aarch64 -L /usr/aarch64-linux-gnu/ ./src/env ./src/uname -m
/lib/ld-linux-aarch64.so.1: No such file or directory

This fails because once "inside" qemu, the aarch64 searches for
"/lib/ld-linux-aarch64.so.1" but the file is in
"/usr/aarch64-linux-gnu/lib/ld-linux-aarch64.so.1".
One possible work-around is to build static binaries.

I don't want to assume that is the culprit for Frans, so we'll wait for 
the logs...