This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug libc/23960] [2.28 Regression]: New getdents{64} implementation breaks qemu-user
- From: "aladjev.andrew at gmail dot com" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sourceware dot org
- Date: Thu, 09 Jan 2020 21:21:22 +0000
- Subject: [Bug libc/23960] [2.28 Regression]: New getdents{64} implementation breaks qemu-user
- Auto-submitted: auto-generated
- References: <bug-23960-131@http.sourceware.org/bugzilla/>
https://sourceware.org/bugzilla/show_bug.cgi?id=23960
--- Comment #53 from Aladjev Andrew <aladjev.andrew at gmail dot com> ---
Please review getdents function once again:
https://github.com/bminor/glibc/blob/master/sysdeps/unix/sysv/linux/getdents.c#L21
What does it mean "!_DIRENT_MATCHES_DIRENT64"?
https://github.com/bminor/glibc/blob/master/sysdeps/unix/sysv/linux/bits/dirent.h#L54
#if defined __OFF_T_MATCHES_OFF64_T && defined __INO_T_MATCHES_INO64_T
# define _DIRENT_MATCHES_DIRENT64 1
#else
# define _DIRENT_MATCHES_DIRENT64 0
#endif
>From architecture perspective "!_DIRENT_MATCHES_DIRENT64" means "we need to
emulate getdents using getdents64".
So this issue can be titled correctly as "getdents emulation using getdents64
is not working in several cases".
/* Pack the dirent64 struct down into 32-bit offset/inode fields, and ensure
that no overflow occurs. */
The main assumption is wrong. Packing "dirent64" down to "dirent" is not
possible in general case. This issue is very popular. Musl libc has the same
issue.
https://github.com/ifduyue/musl/blob/master/src/internal/syscall.h#L131-L134
/* fixup legacy 32-bit-vs-lfs64 junk */
#define SYS_getdents SYS_getdents64
Only UClibc (and uclibc-ng) works almost correctly with "getdents"
https://github.com/wbx-github/uclibc-ng/blob/master/libc/sysdeps/linux/common/getdents.c#L94-L116
You can enable "ARCH_HAS_DEPRECATED_SYSCALLS" config option and "getdents"
won't be emulated with "getdents64", it will use regular "getdents" syscall.
Is it possible to fix "getdents" emulation? Yes, we need to replace
"getdents64" syscall with "__X32_SYSCALL_BIT + __NR_getdents64". This syscall
guarantees that packing "dirent64" down to "dirent" is possible. This
replacement requires "CONFIG_X86_X32=y" in your host kernel config.
If I were glibc/musl core developer I will rewrite "getdents" in the following
way:
1. If x32 syscall is available - use "__X32_SYSCALL_BIT + __NR_getdents64".
2. Otherwise do not try to emulate "getdents" using "getdents64", use regular
"getdents" syscall.
--
You are receiving this mail because:
You are on the CC list for the bug.