Skip to content

do_guest_openat /proc interposition doesn't work for openat

Hello,

Host environment

  • Operating system: All
  • OS/kernel version: Linux
  • Architecture: All
  • QEMU flavor: All
  • QEMU version: 8.1.2
  • QEMU command line: e.g. qemu-hppa-static ./test running on x86

Using this program compiled with an hppa compiler test.c

Emulated/Virtualized environment

  • Operating system: Linux
  • OS/kernel version: All
  • Architecture: All

Description of problem

For instance, trying with hppa emulated on top of x86:

$ hppa-linux-gnu-gcc test.c -o test
$ qemu-hppa-static ./test

One gets the host cpu information:

processor	: 0
vendor_id	: GenuineIntel
cpu family	: 6
model		: 142
model name	: Intel(R) Core(TM) i5-10210U CPU @ 1.60GHz
[...]

while we would want to see the guest cpu information, like the test program does when #if 0 is turned into #if 1:

processor	: 0            
cpu family	: PA-RISC 1.1e
cpu		: PA7300LC (PCX-L2)
capabilities	: os32
model		: 9000/778/B160L - Merlin L2 160 QEMU (9000/778/B160L)

This is because do_guest_openat only checks for the path, and does not look at dirfd, so it doesn't recognize that openat(dirfd, "cpuinfo", O_RDONLY) is actually opening a file in /proc.

We could probably, when dirfd is not AT_FDCWD, try to fstat() it, open /proc with O_DIRECTORY and fstat() that too, and compare their st_dev and st_ino?

Edited by Samuel Thibault
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information