fcntl: Add 32bit filesystem mode
It was brought to my attention that this bug from 2018 was
still unresolved: 32 bit emulators like QEMU were given
64 bit hashes when running 32 bit emulation on 64 bit systems.
This adds a flag to the fcntl() F_GETFD and F_SETFD operations
to set the underlying filesystem into 32bit mode even if the
file handle was opened using 64bit mode without the compat
syscalls.
Programs that need the 32 bit file system behavior need to
issue a fcntl() system call such as in this example:
#define FD_32BIT_MODE 2
int main(int argc, char** argv) {
DIR* dir;
int err;
int mode;
int fd;
dir = opendir("/boot");
fd = dirfd(dir);
mode = fcntl(fd, F_GETFD);
mode |= FD_32BIT_MODE;
err = fcntl(fd, F_SETFD, mode);
if (err) {
printf("fcntl() failed! err=%d\n", err);
return 1;
}
printf("dir=%p\n", dir);
printf("readdir(dir)=%p\n", readdir(dir));
printf("errno=%d: %s\n", errno, strerror(errno));
return 0;
}
This can be pretty hard to test since C libraries and linux
userspace security extensions aggressively filter the parameters
that are passed down and allowed to commit into actual system
calls.
Cc: Florian Weimer <fw@deneb.enyo.de>
Cc: Peter Maydell <peter.maydell@linaro.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Eric Blake <eblake@redhat.com>
Reported-by: 罗勇刚(Yonggang Luo) <luoyonggang@gmail.com>
Suggested-by: Theodore Ts'o <tytso@mit.edu>
Link: https://bugs.launchpad.net/qemu/+bug/1805913
Link: https://lore.kernel.org/lkml/87bm56vqg4.fsf@mid.deneb.enyo.de/
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=205957
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2 files changed