From 0e83e30aa7a47b3303e4a9b1e002b786ef7eb340 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Bidar?= Date: Sun, 10 Sep 2023 13:39:49 +0300 Subject: [PATCH] [preload] Adapt glibc in open ignore 'mode' with O_TMPFILE in flags MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Both open and openat load their last argument 'mode' lazily, using va_arg() only if O_CREAT is found in oflag. This is wrong, mode is also necessary if O_TMPFILE is in oflag. Adapt __OPEN_NEEDS_MODE(oflag) present since glibc 2.22 to solve the issue. Read more down below: https://sourceware.org/git/?p=glibc.git;a=commit;h=65f6f938cd562a614a68e15d0581a34b177ec29d Signed-off-by: Björn Bidar --- preload/interface.master | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/preload/interface.master b/preload/interface.master index b12160d1..9ebdcefc 100644 --- a/preload/interface.master +++ b/preload/interface.master @@ -185,30 +185,30 @@ GATE: pid_t waitpid(pid_t pid, int *status, int options) GATE: int __open(const char *pathname, int flags, ...) : \ dont_resolve_final_symlink_if(flags&O_NOFOLLOW) \ - map(pathname) optional_arg_is_create_mode(flags&O_CREAT) \ + map(pathname) optional_arg_is_create_mode(__OPEN_NEEDS_MODE(flags)) \ postprocess(pathname) \ check_and_fail_if_readonly(flags&OPEN_FLAGS_RW_MODE,pathname,-1,EROFS) \ - class(OPEN) conditionally_class(flags&O_CREAT,CREAT) + class(OPEN) conditionally_class(__OPEN_NEEDS_MODE(flags),CREAT) GATE: int __open64(const char *pathname, int flags, ...) : \ dont_resolve_final_symlink_if(flags&O_NOFOLLOW) \ - map(pathname) optional_arg_is_create_mode(flags&O_CREAT) \ + map(pathname) optional_arg_is_create_mode(__OPEN_NEEDS_MODE(flags)) \ postprocess(pathname) \ check_and_fail_if_readonly(flags&OPEN_FLAGS_RW_MODE,pathname,-1,EROFS) \ - class(OPEN) conditionally_class(flags&O_CREAT,CREAT) + class(OPEN) conditionally_class(__OPEN_NEEDS_MODE(flags),CREAT) GATE: int open(const char *pathname, int flags, ...) : \ dont_resolve_final_symlink_if(flags&O_NOFOLLOW) \ - map(pathname) optional_arg_is_create_mode(flags&O_CREAT) \ + map(pathname) optional_arg_is_create_mode(__OPEN_NEEDS_MODE(flags)) \ postprocess(pathname) \ create_nomap_nolog_version \ check_and_fail_if_readonly(flags&OPEN_FLAGS_RW_MODE,pathname,-1,EROFS) \ - class(OPEN) conditionally_class(flags&O_CREAT,CREAT) + class(OPEN) conditionally_class(__OPEN_NEEDS_MODE(flags),CREAT) GATE: int open64(const char *pathname, int flags, ...) : \ dont_resolve_final_symlink_if(flags&O_NOFOLLOW) \ - map(pathname) optional_arg_is_create_mode(flags&O_CREAT) \ + map(pathname) optional_arg_is_create_mode(__OPEN_NEEDS_MODE(flags)) \ postprocess(pathname) \ check_and_fail_if_readonly(flags&OPEN_FLAGS_RW_MODE,pathname,-1,EROFS) \ - class(OPEN) conditionally_class(flags&O_CREAT,CREAT) + class(OPEN) conditionally_class(__OPEN_NEEDS_MODE(flags),CREAT) -- open; variants witout varargs GATE: int __open_2(const char *pathname, int flags) : \ @@ -216,29 +216,29 @@ GATE: int __open_2(const char *pathname, int flags) : \ map(pathname) \ postprocess(pathname) \ check_and_fail_if_readonly(flags&OPEN_FLAGS_RW_MODE,pathname,-1,EROFS) \ - class(OPEN) conditionally_class(flags&O_CREAT,CREAT) + class(OPEN) conditionally_class(__OPEN_NEEDS_MODE(flags),CREAT) GATE: int __open64_2(const char *pathname, int flags) : \ dont_resolve_final_symlink_if(flags&O_NOFOLLOW) \ map(pathname) \ postprocess(pathname) \ check_and_fail_if_readonly(flags&OPEN_FLAGS_RW_MODE,pathname,-1,EROFS) \ - class(OPEN) conditionally_class(flags&O_CREAT,CREAT) + class(OPEN) conditionally_class(__OPEN_NEEDS_MODE(flags),CREAT) -- openat: GATE: int openat(int dirfd, const char *pathname, int flags, ...) : \ dont_resolve_final_symlink_if(flags&O_NOFOLLOW) \ - map_at(dirfd,pathname) optional_arg_is_create_mode(flags&O_CREAT) \ + map_at(dirfd,pathname) optional_arg_is_create_mode(__OPEN_NEEDS_MODE(flags)) \ create_nomap_nolog_version \ postprocess(pathname) \ check_and_fail_if_readonly(flags&OPEN_FLAGS_RW_MODE,pathname,-1,EROFS) \ - class(OPEN) conditionally_class(flags&O_CREAT,CREAT) + class(OPEN) conditionally_class(__OPEN_NEEDS_MODE(flags),CREAT) GATE: int openat64(int dirfd, const char *pathname, int flags, ...) : \ dont_resolve_final_symlink_if(flags&O_NOFOLLOW) \ - map_at(dirfd,pathname) optional_arg_is_create_mode(flags&O_CREAT) \ + map_at(dirfd,pathname) optional_arg_is_create_mode(__OPEN_NEEDS_MODE(flags)) \ postprocess(pathname) \ check_and_fail_if_readonly(flags&OPEN_FLAGS_RW_MODE,pathname,-1,EROFS) \ - class(OPEN) conditionally_class(flags&O_CREAT,CREAT) + class(OPEN) conditionally_class(__OPEN_NEEDS_MODE(flags),CREAT) -- openat; variants witout varargs GATE: int __openat_2(int dirfd, const char *pathname, int flags) : \ @@ -246,13 +246,13 @@ GATE: int __openat_2(int dirfd, const char *pathname, int flags) : \ map_at(dirfd,pathname) \ postprocess(pathname) \ check_and_fail_if_readonly(flags&OPEN_FLAGS_RW_MODE,pathname,-1,EROFS) \ - class(OPEN) conditionally_class(flags&O_CREAT,CREAT) + class(OPEN) conditionally_class(__OPEN_NEEDS_MODE(flags),CREAT) GATE: int __openat64_2(int dirfd, const char *pathname, int flags) : \ dont_resolve_final_symlink_if(flags&O_NOFOLLOW) \ map_at(dirfd,pathname) \ postprocess(pathname) \ check_and_fail_if_readonly(flags&OPEN_FLAGS_RW_MODE,pathname,-1,EROFS) \ - class(OPEN) conditionally_class(flags&O_CREAT,CREAT) + class(OPEN) conditionally_class(__OPEN_NEEDS_MODE(flags),CREAT) -- close: WRAP: int close(int fd) : \