ports/linux: Add wrapper for fstatat/fstatat64 in glibc 2.33
PATCH 1/2 ports/linux: Add wrapper for fstatat/fstatat64 in glibc 2.33
Signed-off-by Richard Purdie <[email protected]>
--- ports/linux/guts/fstatat.c | 15 +++++++++++++++ ports/linux/guts/fstatat64.c | 15 +++++++++++++++ ports/linux/wrapfuncs.in | 2 ++ 3 files changed, 32 insertions(+) create mode 100644 ports/linux/guts/fstatat.c create mode 100644 ports/linux/guts/fstatat64.c
ports/linux/guts/fstatat.c new file +15 -0
@@ -0,0 +1,15 @@ +/* +* Copyright (c) 2021 Linux Foundation; see +* guts/COPYRIGHT for information. +* +* SPDX-License-Identifier: LGPL-2.1-only +* +* int fstatat(int dirfd, const char *path, struct stat *buf, int flags) +* int rc = -1; +*/ + + rc =wrap___fxstatat (_STAT_VER, dirfd, path, buf, flags); + +/* return rc; +* } +*/
ports/linux/guts/fstatat64.c new file +15 -0
@@ -0,0 +1,15 @@ +/* +* Copyright (c) 2021 Linux Foundation; see +* guts/COPYRIGHT for information. +* +* SPDX-License-Identifier: LGPL-2.1-only +* +* int fstatat64(int dirfd, const char *path, struct stat64 *buf, int flags) +* int rc = -1; +*/ + + rc =wrap___fxstatat64 (_STAT_VER, dirfd, path, buf, flags); + +/* return rc; +* } +*/
ports/linux/wrapfuncs.in +2 -0
@@ -23,9 +23,11 @@ int creat64(const char *path, mode_t mode); int stat(const char *path, struct stat *buf); /* real_func=pseudo_stat */ int lstat(const char *path, struct stat *buf); /* real_func=pseudo_lstat, flags=AT_SYMLINK_NOFOLLOW */ int fstat(int fd, struct stat *buf); /* real_func=pseudo_fstat */ +int fstatat(int dirfd, const char *path, struct stat *buf, int flags); int stat64(const char *path, struct stat64 *buf); /* real_func=pseudo_stat64 */ int lstat64(const char *path, struct stat64 *buf); /* real_func=pseudo_lstat64, flags=AT_SYMLINK_NOFOLLOW */ int fstat64(int fd, struct stat64 *buf); /* real_func=pseudo_fstat64 */ +int fstatat64(int dirfd, const char *path, struct stat64 *buf, int flags); int __xstat64(int ver, const char *path, struct stat64 *buf); int __lxstat64(int ver, const char *path, struct stat64 *buf); /* flags=AT_SYMLINK_NOFOLLOW */ int __fxstat64(int ver, int fd, struct stat64 *buf);
Signature · 1 line
2.27.0
PATCH 2/2 makewrappers: Fix glibc 2.33 fstatat usage issues
In glibc 2.33 it makes calls like:
fstatat64 (pathfd, "", &st, AT_EMPTY_PATH);
where pathfd may be a symlink. This interacts badly with pseudo_root_path() since the empty path is replaced with a pathname from the open fd but AT_SYMLINK_NOFOLLOW is not set, hence the link is resolved and pseudo throws an abort() due to inode mismatch.
Where the path is empty, an fd is passed and AT_EMPTY_PATH is set, we can imply that AT_SYMLINK_NOFOLLOW is also effectly set. Adjust the wrapper functions to ensure this, allowing the functions to behave correctly in the AT_EMPTY_PATH case.
Signed-off-by Richard Purdie <[email protected]>
--- makewrappers | 5 +++++ 1 file changed, 5 insertions(+)
makewrappers +5 -0
@@ -372,6 +372,11 @@ class Function: prefix = path[:-4] if prefix not in self.specific_dirfds: prefix = '' + if self.dirfd != "AT_FDCWD" and "flags" in self.flags \ + and "AT_SYMLINK_NOFOLLOW" in self.flags: + fix_paths.append( + "if (%s && !*%s && (flags & AT_EMPTY_PATH))\n" + "\t\t\tflags |= AT_SYMLINK_NOFOLLOW;" % (path, path)) fix_paths.append( "%s = pseudo_root_path(__func__, __LINE__, %s%s, %s, %s);" % (path, prefix, self.dirfd, path, self.flags))
Signature · 1 line
2.27.0