Unverified Commit 7091baf0 authored by Tommaso Tocci's avatar Tommaso Tocci
Browse files

intercept chmod,fchmod,fchmodat

parent e77d0fce
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -40,6 +40,8 @@ int hook_dup2(unsigned int oldfd, unsigned int newfd);
int hook_dup3(unsigned int oldfd, unsigned int newfd, int flags);
int hook_getdents(unsigned int fd, struct linux_dirent *dirp, unsigned int count);
int hook_mkdirat(int dirfd, const char * cpath, mode_t mode);
int hook_fchmodat(int dirfd, const char* path, mode_t mode);
int hook_fchmod(unsigned int dirfd, mode_t mode);
int hook_chdir(const char* path);
int hook_fchdir(unsigned int fd);
int hook_getcwd(char * buf, unsigned long size);
+33 −0
Original line number Diff line number Diff line
@@ -314,7 +314,40 @@ int hook_mkdirat(int dirfd, const char * cpath, mode_t mode) {
    }
}

int hook_fchmodat(int dirfd, const char * cpath, mode_t mode) {
    CTX->log()->trace("{}() called dirfd {}, path '{}', mode {}", __func__, dirfd, cpath, mode);

    std::string resolved;
    auto rstatus = CTX->relativize_fd_path(dirfd, cpath, resolved);
    switch(rstatus) {
        case RelativizeStatus::fd_unknown:
            return syscall_no_intercept(SYS_fchmodat, dirfd, cpath, mode);

        case RelativizeStatus::external:
            return syscall_no_intercept(SYS_fchmodat, dirfd, resolved.c_str(), mode);

        case RelativizeStatus::fd_not_a_dir:
            return -ENOTDIR;

        case RelativizeStatus::internal:
            CTX->log()->warn("{}() operation not supported", __func__);
            return -ENOTSUP;

        default:
            CTX->log()->error("{}() relativize status unknown: {}", __func__);
            return -EINVAL;
    }
}

int hook_fchmod(unsigned int fd, mode_t mode) {
    CTX->log()->trace("{}() called with fd {}, mode {}", __func__, fd, mode);
    if (CTX->file_map()->exist(fd)) {
        CTX->log()->warn("{}() operation not supported", __func__);
        return -ENOTSUP;
    }
    return syscall_no_intercept(SYS_fchmod, fd, mode);
}

int hook_chdir(const char * path) {
    CTX->log()->trace("{}() called with path '{}'", __func__, path);
    std::string rel_path;
+17 −0
Original line number Diff line number Diff line
@@ -181,6 +181,23 @@ static inline int hook(long syscall_number,
                               static_cast<mode_t>(arg1));
        break;

    case SYS_chmod:
        *result = hook_fchmodat(AT_FDCWD,
                                reinterpret_cast<char*>(arg0),
                                static_cast<mode_t>(arg1));
        break;

    case SYS_fchmod:
        *result = hook_fchmod(static_cast<unsigned int>(arg0),
                              static_cast<mode_t>(arg1));
        break;

    case SYS_fchmodat:
        *result = hook_fchmodat(static_cast<unsigned int>(arg0),
                                reinterpret_cast<char*>(arg1),
                                static_cast<mode_t>(arg2));
        break;

    case SYS_chdir:
        *result = hook_chdir(reinterpret_cast<const char *>(arg0));
        break;