Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions capio-common/capio/filesystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,16 @@ inline bool is_capio_path(const std::filesystem::path &path_to_check) {
START_LOG(capio_syscall(SYS_gettid), "call(path_to_check=%s)", path_to_check.c_str());

// check if path_to_check begins with CAPIO_DIR
const auto res =
is_prefix(get_capio_dir(), path_to_check) && !is_forbidden_path(path_to_check.string());
LOG("is_capio_path:%s", res ? "yes" : "no");
return res;
const auto is_prefix_res = is_prefix(get_capio_dir(), path_to_check);

LOG("IS PREFIX=%s", is_prefix_res ? "TRUE" : "FALSE");

const auto is_forbidden_res = is_forbidden_path(path_to_check.string());

LOG("IS FORBIDDEN=%s", is_forbidden_res ? "TRUE" : "FALSE");

LOG("is_capio_path:%s", is_prefix_res && !is_forbidden_res ? "yes" : "no");
return is_prefix_res && !is_forbidden_res;
}

/**
Expand Down
22 changes: 10 additions & 12 deletions capio-posix/handlers/open.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,16 @@ int creat_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long ar
mode_t mode = static_cast<int>(arg2);
START_LOG(tid, "call(path=%s, flags=%d, mode=%d)", pathname.data(), flags, mode);

if (!is_capio_path(pathname)) {
LOG("Path %s is forbidden: skip", pathname.data());
return CAPIO_POSIX_SYSCALL_REQUEST_SKIP;
}

std::string path = compute_abs_path(pathname.data(), -1);

if (is_capio_path(path)) {
create_request(-1, path.data(), tid);
LOG("Create request sent");
if (!is_capio_path(path)) {
LOG("Path %s is forbidden: skip", path.data());
return CAPIO_POSIX_SYSCALL_REQUEST_SKIP;
}

create_request(-1, path.data(), tid);
LOG("Create request sent");

const int fd =
static_cast<int>(syscall_no_intercept(SYS_creat, arg0, arg1, arg2, arg3, arg4, arg5));

Expand Down Expand Up @@ -80,8 +78,8 @@ int open_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg

std::string path = compute_abs_path(pathname.data(), -1);

if (!is_capio_path(pathname)) {
LOG("Path %s is not a capio path: skip", pathname.data());
if (!is_capio_path(path)) {
LOG("Path %s is not a capio path: skip", path.data());
return CAPIO_POSIX_SYSCALL_REQUEST_SKIP;
}

Expand Down Expand Up @@ -122,8 +120,8 @@ int openat_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long a
mode);

std::string path = compute_abs_path(pathname.data(), dirfd);
if (!is_capio_path(pathname)) {
LOG("Path %s is not a capio path: skip", pathname.data());
if (!is_capio_path(path)) {
LOG("Path %s is not a capio path: skip", path.data());
return CAPIO_POSIX_SYSCALL_REQUEST_SKIP;
}

Expand Down