mbox series

[v7,0/2] linux-user: add openat2 support in linux-user

Message ID cover.1727119903.git.mvogt@redhat.com (mailing list archive)
Headers show
Series linux-user: add openat2 support in linux-user | expand

Message

Michael Vogt Sept. 23, 2024, 7:37 p.m. UTC
This is v7 of the openat2 support in linux-user. Thanks for the
excellent feedback from Richard on v6, really appreciated.

This version addresses the feedback for v6. The fix for the LTP
failure requires to pass the "resolve" flags to maybe_do_fake_open()
and check for RESOLVE_NO_{MAGIC,SYM}LINKS in /proc/self/exe. This is
the only magic link we support currently via the faked files. The
check is not perfect as dirfd is not honored. But if dirfd is used no
fake open will be performed anyway and the host openat2 call will
honor the resolve flags.

I split adding openat2 support to strace.c into a separate commit
but if a single commit is preferred I'm happy to do this of course.
The second commit keeps copy_struct_from_user() in syscall.c, maybe
uaccess.c is a better place, but to move we would also have to do
something about check_zeroed_user() so I decided to keep the diff
small (but happy to change that too if preferred).

In the second commit I also had to move open_how_v0 so that strace.c
can use it. I moved it into syscall_defs.h but it seems not a great
fit, suggestions for a better place welcome (or a different approach,
I could e.g. always rely on openat2.h in strace.c).

The second diff also gives me an error in checkpatch.pl:
 +UNUSED static const struct flags openat2_resolve_flags[] = {
which looks like a false postive to me as all the structs are
formated this way in strace.c (but maybe I'm missing something?).

Looking forward to your feedback/ideas!

Thanks,
 Michael


v6 -> v7
- use abi_ulong in guest_size
- use TARGET_ABI_FMT_lu to format guest size in qemu_log_mask()
- drop #ifdef for TARGET_NR_openat2
- fix LTP test by checking for RESOLVE_NO_{MAGIC,SYM}LINKS in
  maybe_do_fake_open()
- add support for openat2 in strace.c
- add copy_struct_from_user definition to qemu.h
- add open_how_v0 to syscall_defs.h

v5 -> v6
- do not use get_errno(fd) in do_guest_openat()
- do not put declarations in the middle of the code
- do not return early in do_openat2() when we get a faked file

v4 -> v5
- drop "*use_returned_fd" from maybe_do_fake_open() and use return value
  -2 to signal to the caller to continue
- keep "pathname" in parameter to do_guest_openat() for a cleaner diff
- fix two missing get_errno(fd)

v3 -> v4:
- fix typos in the commit message

v2 -> v3:
- fix coding style (braches)
- improve argument args/naming in do_openat2()
- merge do_openat2/do_guest_openat2
- do size checks first in do_openat2
- add "copy_struct_from_user" and use in "do_openat2()"
- drop using openat2.h and create "struct open_how_v0"
- log if open_how guest struct is bigger than our supported struct

v1 -> v2:
- do not include <sys/syscall.h>
- drop do_guest_openat2 from qemu.h and make static
- drop "safe" from do_guest_openat2
- ensure maybe_do_fake_open() is correct about when the result should
  be used or not
- Extract do_openat2() helper from do_syscall1()
- Call user_unlock* if a lock call fails
- Fix silly incorrect use of "target_open_how" when "open_how" is required
- Fix coding style comments
- Fix validation of arg4 in openat2
- Fix missing zero initialization of open_how
- Define target_open_how with abi_* types
- Warn about unimplemented size if "size" of openat2 is bigger than
  target_open_how


Michael Vogt (2):
  linux-user: add openat2 support in linux-user
  linux-user: add strace support for openat2

 linux-user/qemu.h         |  9 ++++
 linux-user/strace.c       | 40 ++++++++++++++++
 linux-user/strace.list    |  3 ++
 linux-user/syscall.c      | 99 ++++++++++++++++++++++++++++++++++++++-
 linux-user/syscall_defs.h | 18 +++++++
 meson.build               |  1 +
 6 files changed, 168 insertions(+), 2 deletions(-)