From 632cc66ba52eb6aa7fd3e457c64d9186389a20b4 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Fri, 5 Nov 2021 23:14:42 -0400 Subject: change FS calls to use 64-bit interfaces explicitly Make sure we use 64-bit FS interfaces when accessing the FS. This is needed not only to stat or open large files, but even files with 64-bit inodes. Bug: https://bugs.gentoo.org/583282 Signed-off-by: Mike Frysinger --- libsandbox/canonicalize.c | 8 ++++---- libsandbox/libsandbox.c | 14 +++++++------- libsandbox/pre_check_mkdirat.c | 6 +++--- libsandbox/trace.c | 2 +- libsandbox/wrapper-funcs/__wrapper_exec.c | 4 ++-- 5 files changed, 17 insertions(+), 17 deletions(-) (limited to 'libsandbox') diff --git a/libsandbox/canonicalize.c b/libsandbox/canonicalize.c index 6519340..f742ed4 100644 --- a/libsandbox/canonicalize.c +++ b/libsandbox/canonicalize.c @@ -92,7 +92,7 @@ erealpath(const char *name, char *resolved) goto error; } - /* This stat() business uses relative paths atm */ + /* This stat business uses relative paths atm. */ if (trace_pid) goto no_recover; @@ -100,14 +100,14 @@ erealpath(const char *name, char *resolved) * If not, try a little harder to consume this path in * case it has symlinks out into a better world ... */ - struct stat st; - if (lstat(rpath, &st) == -1 && errno == EACCES) { + struct stat64 st; + if (lstat64(rpath, &st) == -1 && errno == EACCES) { char *p = rpath; strcpy(rpath, name); do { p = strchr(p, '/'); if (p) *p = '\0'; - if (lstat(rpath, &st)) + if (lstat64(rpath, &st)) break; if (S_ISLNK(st.st_mode)) { ssize_t cnt = readlink(rpath, rpath, path_max); diff --git a/libsandbox/libsandbox.c b/libsandbox/libsandbox.c index b4db9ba..0ca2bc9 100644 --- a/libsandbox/libsandbox.c +++ b/libsandbox/libsandbox.c @@ -333,7 +333,7 @@ static char *resolve_path(const char *path, int follow_link) char *egetcwd(char *buf, size_t size) { - struct stat st; + struct stat64 st; char *tmpbuf; /* We can't let the C lib allocate memory for us since we have our @@ -376,12 +376,12 @@ char *egetcwd(char *buf, size_t size) */ if ((tmpbuf) && (errno == 0)) { save_errno(); - if (!lstat(buf, &st)) + if (!lstat64(buf, &st)) /* errno is set only on failure */ errno = 0; if (errno == ENOENT) - /* If lstat() failed with eerror = ENOENT, then its + /* If lstat failed with eerror = ENOENT, then its * possible that we are running on an older kernel * which had issues with returning invalid paths if * they got too long. Return with errno = ENAMETOOLONG, @@ -396,8 +396,8 @@ char *egetcwd(char *buf, size_t size) free(buf); /* Not sure if we should quit here, but I guess if - * lstat() fails, getcwd could have messed up. Not - * sure what to do about errno - use lstat()'s for + * lstat fails, getcwd could have messed up. Not + * sure what to do about errno - use lstat's for * now. */ return NULL; @@ -435,12 +435,12 @@ void __sb_dump_backtrace(void) static bool write_logfile(const char *logfile, const char *func, const char *path, const char *apath, const char *rpath, bool access) { - struct stat log_stat; + struct stat64 log_stat; int stat_ret; int logfd; bool ret = false; - stat_ret = lstat(logfile, &log_stat); + stat_ret = lstat64(logfile, &log_stat); /* Do not care about failure */ errno = 0; if (stat_ret == 0 && S_ISREG(log_stat.st_mode) == 0) diff --git a/libsandbox/pre_check_mkdirat.c b/libsandbox/pre_check_mkdirat.c index 8fb38bb..b1e86cf 100644 --- a/libsandbox/pre_check_mkdirat.c +++ b/libsandbox/pre_check_mkdirat.c @@ -36,8 +36,8 @@ bool sb_mkdirat_pre_check(const char *func, const char *pathname, int dirfd) * not want to pass this attempt up to the higher levels as those * will trigger a sandbox violation. */ - struct stat st; - if (0 == lstat(canonic, &st)) { + struct stat64 st; + if (0 == lstat64(canonic, &st)) { int new_errno; sb_debug_dyn("EARLY FAIL: %s(%s[%s]) @ lstat: %s\n", func, pathname, canonic, strerror(errno)); @@ -45,7 +45,7 @@ bool sb_mkdirat_pre_check(const char *func, const char *pathname, int dirfd) new_errno = EEXIST; /* Hmm, is this a broken symlink we're trying to extend ? */ - if (S_ISLNK(st.st_mode) && stat(pathname, &st) != 0) { + if (S_ISLNK(st.st_mode) && stat64(pathname, &st) != 0) { /* XXX: This awful hack should probably be turned into a * common func that does a better job. For now, we have * enough crap to catch gnulib tests #297026. diff --git a/libsandbox/trace.c b/libsandbox/trace.c index 036d57f..d70f3bc 100644 --- a/libsandbox/trace.c +++ b/libsandbox/trace.c @@ -51,7 +51,7 @@ static int trace_yama_level(void) char ch; int fd, level; - fd = open("/proc/sys/kernel/yama/ptrace_scope", O_RDONLY | O_CLOEXEC); + fd = open64("/proc/sys/kernel/yama/ptrace_scope", O_RDONLY | O_CLOEXEC); if (fd == -1) return 0; diff --git a/libsandbox/wrapper-funcs/__wrapper_exec.c b/libsandbox/wrapper-funcs/__wrapper_exec.c index d66e3a0..f603257 100644 --- a/libsandbox/wrapper-funcs/__wrapper_exec.c +++ b/libsandbox/wrapper-funcs/__wrapper_exec.c @@ -27,7 +27,7 @@ static bool sb_check_exec(const char *filename, char *const argv[]) { int fd; unsigned char *elf; - struct stat st; + struct stat64 st; bool do_trace = false; bool run_in_process = true; sandbox_method_t method = get_sandbox_method(); @@ -38,7 +38,7 @@ static bool sb_check_exec(const char *filename, char *const argv[]) fd = sb_unwrapped_open_DEFAULT(filename, O_RDONLY|O_CLOEXEC, 0); if (fd == -1) return true; - if (fstat(fd, &st)) + if (fstat64(fd, &st)) goto out_fd; if (st.st_size < sizeof(Elf64_Ehdr)) goto out_fd; -- cgit v1.2.3-65-gdbad