On 9/2/21 11:35, Manfred Hollstein wrote:
On Thu, 02 Sep 2021, 11:15:00 +0200, Frans de Boer wrote:
It took me some time, but somehow bash is not behaving as expected within a
qemu-aarch64 chroot jail.

If I do the following:
  if test -r <some file>; then echo ok; fi
Then the reply is 'ok' under normal x86_64 TW.
Please show all details about <some file> within the chroot. The "-r"
flag checks "FILE exists and read permission is granted".
I used <some file> because you can pick ANY file with their read permission set. Of course I checked that.
However, when I started a chroot jail using qemu-aarch64 the reply stays empty.
Only when I execute
  if test !  -r <some file>; then echo ok; fi
the response is 'ok'. And <some file> is always the same.

I start the jail with the next command:
/usr/bin/qemu-aarch64 -strace -cpu cortex-a53 -L /newroot  /newroot/usr/sbin/
chroot  "/newroot" \
  /usr/bin/env -i \
    HOME=/root \
    TERM="$TERM" \
    PS1='(lfs chroot) \u:\w\$ ' \
    PS4='(${BASH_SOURCE}:${LINENO}: ${FUNCNAME[0]} - [${SHLVL},$
{BASH_SUBSHELL}, $?] ' \
    PATH=/usr/bin:/usr/sbin \
    /usr/bin/bash --login +h

Also, I copied a static version of qemu-aarch64 and qemu_binfmt into /newroot/
usr/bin - I also tried my own compiled version of qemu-aarch64-static, with the
same result.
Programs run, but bash seems to have this specific issue with the -r test.
Other flags I tested -f, -s, -x etc. are working correctly.
These flags don't check the _read_ permission for the executing user.
I never said that it would. And as a bonus, it is all at UID 0 level.
The -r flags is the only flag which - I presume - really does a reading test,
while others test availability and some file flags. Maybe binfmt is to blame??

It is blocking me from compiling programs under aarch64 because the configure
script is using these tests. If I change the ´-r´ flag within configure into a
´-s´, everything does work well.

Regards, Frans.
HTH, cheers.

l8er
manfred
--- Frans