Skip to content

Commit

Permalink
[preload] Adapt glibc in open ignore 'mode' with O_TMPFILE in flags
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Thaodan committed Apr 26, 2024
1 parent c1b6d26 commit 0e83e30
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions preload/interface.master
Original file line number Diff line number Diff line change
Expand Up @@ -185,74 +185,74 @@ 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) : \
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)
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) : \
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)
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) : \
Expand Down

0 comments on commit 0e83e30

Please sign in to comment.