Loading include/client/gkfs_libc.hpp +0 −6 Original line number Diff line number Diff line Loading @@ -276,12 +276,6 @@ off_t lseek(int fd, off_t offset, int whence) __THROW; off64_t lseek64(int fd, off64_t offset, int whence) __THROW; // statvfs int statvfs(const char* path, struct statvfs* buf); int fstatvfs(int fd, struct statvfs* buf); int fstat(int fd, struct stat* buf); Loading include/client/preload.hpp +6 −0 Original line number Diff line number Diff line Loading @@ -57,4 +57,10 @@ void destroy_libc() __attribute__((destructor)); #endif void at_fork(); void at_child(); void at_parent(); #endif // IOINTERCEPT_PRELOAD_HPP src/client/CMakeLists.txt +52 −1 Original line number Diff line number Diff line Loading @@ -35,7 +35,7 @@ add_library(gkfs_intercept SHARED) add_library(gkfs_user_lib SHARED) add_library(gkfs_libc_intercept SHARED) add_library(gkfs_user_lib_autoinit SHARED) target_sources(gkfs_intercept PRIVATE gkfs_functions.cpp Loading Loading @@ -81,6 +81,30 @@ target_sources( syscalls/detail/syscall_info.c syscalls/util.S ) target_sources( gkfs_user_lib_autoinit PRIVATE gkfs_functions.cpp intercept.cpp hooks.cpp logging.cpp open_file_map.cpp open_dir.cpp path.cpp preload.cpp preload_context.cpp preload_util.cpp malleability.cpp cache.cpp rpc/rpc_types.cpp rpc/forward_data.cpp rpc/forward_data_proxy.cpp rpc/forward_management.cpp rpc/forward_metadata.cpp rpc/forward_metadata_proxy.cpp rpc/forward_malleability.cpp syscalls/detail/syscall_info.c syscalls/util.S ) target_sources( gkfs_libc_intercept PRIVATE gkfs_functions.cpp Loading Loading @@ -110,6 +134,9 @@ target_sources( target_compile_definitions(gkfs_user_lib PUBLIC BYPASS_SYSCALL) target_link_options(gkfs_user_lib PRIVATE -z noexecstack) target_compile_definitions(gkfs_user_lib_autoinit PUBLIC BYPASS_SYSCALL ENABLE_INIT) target_link_options(gkfs_user_lib_autoinit PRIVATE -z noexecstack) target_compile_definitions(gkfs_libc_intercept PUBLIC BYPASS_SYSCALL ENABLE_INIT) target_link_options(gkfs_libc_intercept PRIVATE -z noexecstack) Loading Loading @@ -150,6 +177,17 @@ target_link_libraries( Microsoft.GSL::GSL ) target_link_libraries( gkfs_user_lib_autoinit PRIVATE metadata distributor env_util arithmetic path_util rpc_utils PUBLIC dl Mercury::Mercury hermes fmt::fmt Threads::Threads Microsoft.GSL::GSL ) target_link_libraries( gkfs_libc_intercept PRIVATE metadata distributor env_util arithmetic path_util rpc_utils Loading @@ -176,6 +214,12 @@ set_target_properties(gkfs_user_lib PUBLIC_HEADER "../../include/client/user_functions.hpp" ) set_target_properties(gkfs_user_lib_autoinit PROPERTIES PUBLIC_HEADER "../../include/client/void_syscall_intercept.hpp" PUBLIC_HEADER "../../include/client/user_functions.hpp" ) install( TARGETS gkfs_user_lib Loading @@ -184,6 +228,13 @@ install( PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/gkfs ) install( TARGETS gkfs_user_lib_autoinit LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/gkfs ) set_target_properties(gkfs_libc_intercept PROPERTIES PUBLIC_HEADER "../../include/client/void_syscall_intercept.hpp" Loading src/client/gkfs_libc.cpp +30 −66 Original line number Diff line number Diff line Loading @@ -45,10 +45,10 @@ #include <linux/const.h> std::atomic<bool> activated{false}; std::atomic<bool> initializing{false}; //#define debug_info printf #define debug_info(...) #define debug_info printf // #define debug_info(...) thread_local std::atomic<bool> reentrant = false; int (*real_open)(char*, int, mode_t) = NULL; int (*real_open64)(char*, int, mode_t) = NULL; int (*real___open_2)(char*, int) = NULL; Loading Loading @@ -114,14 +114,13 @@ initializeGekko() { // if the activated is false call init // Create a global mutex /* if(!activated and !initializing) { debug_info("[BYPASS] >> DEACTIVATED GEKKOFS.... \n"); initializing = true; init_libc(); activated = true; if(!activated and !initializing) { /* debug_info("%d [BYPASS] >> DEACTIVATED GEKKOFS.... \n", getpid()); initializing = true; init_libc(); activated = true; initializing = false; debug_info("[BYPASS] >> ACTIVATED GEKKOFS.... \n"); } */ debug_info("%d [BYPASS] >> ACTIVATED GEKKOFS.... \n", getpid()); */ } } int dlsym_open(char* path, int flags) { Loading Loading @@ -636,7 +635,7 @@ dlsym_telldir(DIR* dirp) { // Proccess API int dlsym_fork(void) { debug_info("[SYSCALL_PROXIES] [dlsym_fork] >> Begin\n"); if(real_fork == NULL) { real_fork = (int (*)()) dlsym(RTLD_NEXT, "fork"); Loading @@ -644,7 +643,6 @@ dlsym_fork(void) { int ret = real_fork(); debug_info("[SYSCALL_PROXIES] [dlsym_fork] >> End\n"); return ret; } Loading Loading @@ -799,7 +797,6 @@ dlsym_access(const char* path, int mode) { char* dlsym_realpath(const char* path, char* resolved_path) { debug_info("[SYSCALL_PROXIES] [dlsym_realpath] >> Begin\n"); if(real_realpath == NULL) { real_realpath = Loading @@ -808,7 +805,6 @@ dlsym_realpath(const char* path, char* resolved_path) { char* ret = real_realpath((char*) path, (char*) resolved_path); debug_info("[SYSCALL_PROXIES] [dlsym_realpath] >> End\n"); return ret; } Loading Loading @@ -1146,7 +1142,7 @@ ssize_t write(int fd, const void* buf, size_t nbyte) { initializeGekko(); if(CTX->file_map()->exist(fd)) { debug_info("[WRITE from GKFS]....%d \n", fd); debug_info("%d [WRITE from GKFS]....%d \n", gettid(), fd); return gkfs::syscall::gkfs_write(fd, buf, nbyte); } Loading Loading @@ -1401,10 +1397,6 @@ __xstat(int ver, const char* path, struct stat* buf) { // Try normal open. break; } } else { std::string p = path; debug_info("[BYPASS] >> Begin stat. ERROR...%s\n", path); } Loading Loading @@ -1658,41 +1650,6 @@ __xstat64(int ver, const char* path, struct stat64* buf) { } int statvfs(const char* path, struct statvfs* buf) { debug_info("[BYPASS] >> Begin statvfs....%s\n", path); buf->f_bsize = 4096; buf->f_blocks = 1024; buf->f_bfree = 1024; buf->f_bavail = 1024; buf->f_files = 0; buf->f_ffree = 0; buf->f_favail = 0; buf->f_fsid = 0; buf->f_namemax = 4096; buf->f_frsize = 0; buf->f_flag = 0; return 0; } int fstatvfs(int fd, struct statvfs* buf) { debug_info("[BYPASS] >> Begin fstatvfs....%d\n", fd); buf->f_bsize = 4096; buf->f_blocks = 1024; buf->f_bfree = 1024; buf->f_bavail = 1024; buf->f_files = 0; buf->f_ffree = 0; buf->f_favail = 0; buf->f_fsid = 0; buf->f_namemax = 4096; buf->f_frsize = 0; buf->f_flag = 0; return 0; } int stat(const char* path, struct stat* buf) { Loading @@ -1715,13 +1672,8 @@ stat(const char* path, struct stat* buf) { // Try normal open. break; } } else { std::string p = path; debug_info("[BYPASS] >> Begin stat. ERROR...%s\n", path); } int ret = dlsym_stat(_STAT_VER, path, buf); return ret; Loading Loading @@ -1796,18 +1748,30 @@ rename(const char* oldpath, const char* newpath) { pid_t fork(void) { int ret = -1; initializeGekko(); debug_info("[BYPASS] >> Begin fork()\n"); debug_info("[BYPASS] >> Begin fork() %p\n", (void*) &activated); // destroy gekkofs // initializing = true; // destroy_libc(); // activated = false; ret = dlsym_fork(); if(0 == ret) { // We want the children to be initialized debug_info("I am the child\n"); debug_info("%d -> %d I am the child %p\n", ret, getpid(), (void*) &activated); initializeGekko(); debug_info("[BYPASS] >> ACTIVATED GEKKOFS (child).... \n"); // initializing = false; // init_libc(); debug_info("%d -> %d [BYPASS] << After fork(child)\n", ret, getpid()); return ret; } // initializing = false; // init_libc(); debug_info("%d -> %d [BYPASS] << After fork()\n", ret, gettid()); debug_info("%d -> %d [BYPASS] << After fork() %p\n", ret, getpid(), (void*) &activated); return ret; } Loading Loading @@ -2034,7 +1998,7 @@ access(const char* path, int mode) { char* realpath(const char* path, char* resolved_path) { debug_info("[BYPASS] >> Begin realpath... %s\n", path); // is gekkofs initializeGekko(); if(CTX->interception_enabled()) { Loading src/client/preload.cpp +26 −4 Original line number Diff line number Diff line Loading @@ -466,23 +466,24 @@ gkfs_end() { /** * @brief Automatically launch init/destroy * TODO: Check if this works with the user library! * NOTES: this is not called, in the child of a fork */ void init_libc() { printf("%d -> %p At init GEKKOFS\n", gettid(), (void*) CTX); // fork does CTX->init_logging(); // from here ownwards it is safe to print messages LOG(DEBUG, "Logging subsystem initialized"); pthread_atfork(&at_fork, &at_parent, &at_child); gkfs::preload::init_environment(); CTX->enable_interception(); } void destroy_libc() { printf("%d At close library GEKKOFS\n", gettid()); CTX->disable_interception(); CTX->clear_hosts(); LOG(DEBUG, "Peer information deleted"); Loading @@ -491,3 +492,24 @@ destroy_libc() { LOG(INFO, "All subsystems shut down. Client shutdown complete."); } void at_fork() { printf("%d ->At fork, %d\n", gettid(), CTX->interception_enabled()); destroy_libc(); } void at_parent() { printf("%d ->At fork parent %d\n", gettid(), CTX->interception_enabled()); init_libc(); printf("%d -> x At fork parent %d\n", gettid(), CTX->interception_enabled()); } void at_child() { printf("%d ->At fork child %d\n", gettid(), CTX->interception_enabled()); init_libc(); printf("%d -> x At fork child %d\n", gettid(), CTX->interception_enabled()); } Loading
include/client/gkfs_libc.hpp +0 −6 Original line number Diff line number Diff line Loading @@ -276,12 +276,6 @@ off_t lseek(int fd, off_t offset, int whence) __THROW; off64_t lseek64(int fd, off64_t offset, int whence) __THROW; // statvfs int statvfs(const char* path, struct statvfs* buf); int fstatvfs(int fd, struct statvfs* buf); int fstat(int fd, struct stat* buf); Loading
include/client/preload.hpp +6 −0 Original line number Diff line number Diff line Loading @@ -57,4 +57,10 @@ void destroy_libc() __attribute__((destructor)); #endif void at_fork(); void at_child(); void at_parent(); #endif // IOINTERCEPT_PRELOAD_HPP
src/client/CMakeLists.txt +52 −1 Original line number Diff line number Diff line Loading @@ -35,7 +35,7 @@ add_library(gkfs_intercept SHARED) add_library(gkfs_user_lib SHARED) add_library(gkfs_libc_intercept SHARED) add_library(gkfs_user_lib_autoinit SHARED) target_sources(gkfs_intercept PRIVATE gkfs_functions.cpp Loading Loading @@ -81,6 +81,30 @@ target_sources( syscalls/detail/syscall_info.c syscalls/util.S ) target_sources( gkfs_user_lib_autoinit PRIVATE gkfs_functions.cpp intercept.cpp hooks.cpp logging.cpp open_file_map.cpp open_dir.cpp path.cpp preload.cpp preload_context.cpp preload_util.cpp malleability.cpp cache.cpp rpc/rpc_types.cpp rpc/forward_data.cpp rpc/forward_data_proxy.cpp rpc/forward_management.cpp rpc/forward_metadata.cpp rpc/forward_metadata_proxy.cpp rpc/forward_malleability.cpp syscalls/detail/syscall_info.c syscalls/util.S ) target_sources( gkfs_libc_intercept PRIVATE gkfs_functions.cpp Loading Loading @@ -110,6 +134,9 @@ target_sources( target_compile_definitions(gkfs_user_lib PUBLIC BYPASS_SYSCALL) target_link_options(gkfs_user_lib PRIVATE -z noexecstack) target_compile_definitions(gkfs_user_lib_autoinit PUBLIC BYPASS_SYSCALL ENABLE_INIT) target_link_options(gkfs_user_lib_autoinit PRIVATE -z noexecstack) target_compile_definitions(gkfs_libc_intercept PUBLIC BYPASS_SYSCALL ENABLE_INIT) target_link_options(gkfs_libc_intercept PRIVATE -z noexecstack) Loading Loading @@ -150,6 +177,17 @@ target_link_libraries( Microsoft.GSL::GSL ) target_link_libraries( gkfs_user_lib_autoinit PRIVATE metadata distributor env_util arithmetic path_util rpc_utils PUBLIC dl Mercury::Mercury hermes fmt::fmt Threads::Threads Microsoft.GSL::GSL ) target_link_libraries( gkfs_libc_intercept PRIVATE metadata distributor env_util arithmetic path_util rpc_utils Loading @@ -176,6 +214,12 @@ set_target_properties(gkfs_user_lib PUBLIC_HEADER "../../include/client/user_functions.hpp" ) set_target_properties(gkfs_user_lib_autoinit PROPERTIES PUBLIC_HEADER "../../include/client/void_syscall_intercept.hpp" PUBLIC_HEADER "../../include/client/user_functions.hpp" ) install( TARGETS gkfs_user_lib Loading @@ -184,6 +228,13 @@ install( PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/gkfs ) install( TARGETS gkfs_user_lib_autoinit LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/gkfs ) set_target_properties(gkfs_libc_intercept PROPERTIES PUBLIC_HEADER "../../include/client/void_syscall_intercept.hpp" Loading
src/client/gkfs_libc.cpp +30 −66 Original line number Diff line number Diff line Loading @@ -45,10 +45,10 @@ #include <linux/const.h> std::atomic<bool> activated{false}; std::atomic<bool> initializing{false}; //#define debug_info printf #define debug_info(...) #define debug_info printf // #define debug_info(...) thread_local std::atomic<bool> reentrant = false; int (*real_open)(char*, int, mode_t) = NULL; int (*real_open64)(char*, int, mode_t) = NULL; int (*real___open_2)(char*, int) = NULL; Loading Loading @@ -114,14 +114,13 @@ initializeGekko() { // if the activated is false call init // Create a global mutex /* if(!activated and !initializing) { debug_info("[BYPASS] >> DEACTIVATED GEKKOFS.... \n"); initializing = true; init_libc(); activated = true; if(!activated and !initializing) { /* debug_info("%d [BYPASS] >> DEACTIVATED GEKKOFS.... \n", getpid()); initializing = true; init_libc(); activated = true; initializing = false; debug_info("[BYPASS] >> ACTIVATED GEKKOFS.... \n"); } */ debug_info("%d [BYPASS] >> ACTIVATED GEKKOFS.... \n", getpid()); */ } } int dlsym_open(char* path, int flags) { Loading Loading @@ -636,7 +635,7 @@ dlsym_telldir(DIR* dirp) { // Proccess API int dlsym_fork(void) { debug_info("[SYSCALL_PROXIES] [dlsym_fork] >> Begin\n"); if(real_fork == NULL) { real_fork = (int (*)()) dlsym(RTLD_NEXT, "fork"); Loading @@ -644,7 +643,6 @@ dlsym_fork(void) { int ret = real_fork(); debug_info("[SYSCALL_PROXIES] [dlsym_fork] >> End\n"); return ret; } Loading Loading @@ -799,7 +797,6 @@ dlsym_access(const char* path, int mode) { char* dlsym_realpath(const char* path, char* resolved_path) { debug_info("[SYSCALL_PROXIES] [dlsym_realpath] >> Begin\n"); if(real_realpath == NULL) { real_realpath = Loading @@ -808,7 +805,6 @@ dlsym_realpath(const char* path, char* resolved_path) { char* ret = real_realpath((char*) path, (char*) resolved_path); debug_info("[SYSCALL_PROXIES] [dlsym_realpath] >> End\n"); return ret; } Loading Loading @@ -1146,7 +1142,7 @@ ssize_t write(int fd, const void* buf, size_t nbyte) { initializeGekko(); if(CTX->file_map()->exist(fd)) { debug_info("[WRITE from GKFS]....%d \n", fd); debug_info("%d [WRITE from GKFS]....%d \n", gettid(), fd); return gkfs::syscall::gkfs_write(fd, buf, nbyte); } Loading Loading @@ -1401,10 +1397,6 @@ __xstat(int ver, const char* path, struct stat* buf) { // Try normal open. break; } } else { std::string p = path; debug_info("[BYPASS] >> Begin stat. ERROR...%s\n", path); } Loading Loading @@ -1658,41 +1650,6 @@ __xstat64(int ver, const char* path, struct stat64* buf) { } int statvfs(const char* path, struct statvfs* buf) { debug_info("[BYPASS] >> Begin statvfs....%s\n", path); buf->f_bsize = 4096; buf->f_blocks = 1024; buf->f_bfree = 1024; buf->f_bavail = 1024; buf->f_files = 0; buf->f_ffree = 0; buf->f_favail = 0; buf->f_fsid = 0; buf->f_namemax = 4096; buf->f_frsize = 0; buf->f_flag = 0; return 0; } int fstatvfs(int fd, struct statvfs* buf) { debug_info("[BYPASS] >> Begin fstatvfs....%d\n", fd); buf->f_bsize = 4096; buf->f_blocks = 1024; buf->f_bfree = 1024; buf->f_bavail = 1024; buf->f_files = 0; buf->f_ffree = 0; buf->f_favail = 0; buf->f_fsid = 0; buf->f_namemax = 4096; buf->f_frsize = 0; buf->f_flag = 0; return 0; } int stat(const char* path, struct stat* buf) { Loading @@ -1715,13 +1672,8 @@ stat(const char* path, struct stat* buf) { // Try normal open. break; } } else { std::string p = path; debug_info("[BYPASS] >> Begin stat. ERROR...%s\n", path); } int ret = dlsym_stat(_STAT_VER, path, buf); return ret; Loading Loading @@ -1796,18 +1748,30 @@ rename(const char* oldpath, const char* newpath) { pid_t fork(void) { int ret = -1; initializeGekko(); debug_info("[BYPASS] >> Begin fork()\n"); debug_info("[BYPASS] >> Begin fork() %p\n", (void*) &activated); // destroy gekkofs // initializing = true; // destroy_libc(); // activated = false; ret = dlsym_fork(); if(0 == ret) { // We want the children to be initialized debug_info("I am the child\n"); debug_info("%d -> %d I am the child %p\n", ret, getpid(), (void*) &activated); initializeGekko(); debug_info("[BYPASS] >> ACTIVATED GEKKOFS (child).... \n"); // initializing = false; // init_libc(); debug_info("%d -> %d [BYPASS] << After fork(child)\n", ret, getpid()); return ret; } // initializing = false; // init_libc(); debug_info("%d -> %d [BYPASS] << After fork()\n", ret, gettid()); debug_info("%d -> %d [BYPASS] << After fork() %p\n", ret, getpid(), (void*) &activated); return ret; } Loading Loading @@ -2034,7 +1998,7 @@ access(const char* path, int mode) { char* realpath(const char* path, char* resolved_path) { debug_info("[BYPASS] >> Begin realpath... %s\n", path); // is gekkofs initializeGekko(); if(CTX->interception_enabled()) { Loading
src/client/preload.cpp +26 −4 Original line number Diff line number Diff line Loading @@ -466,23 +466,24 @@ gkfs_end() { /** * @brief Automatically launch init/destroy * TODO: Check if this works with the user library! * NOTES: this is not called, in the child of a fork */ void init_libc() { printf("%d -> %p At init GEKKOFS\n", gettid(), (void*) CTX); // fork does CTX->init_logging(); // from here ownwards it is safe to print messages LOG(DEBUG, "Logging subsystem initialized"); pthread_atfork(&at_fork, &at_parent, &at_child); gkfs::preload::init_environment(); CTX->enable_interception(); } void destroy_libc() { printf("%d At close library GEKKOFS\n", gettid()); CTX->disable_interception(); CTX->clear_hosts(); LOG(DEBUG, "Peer information deleted"); Loading @@ -491,3 +492,24 @@ destroy_libc() { LOG(INFO, "All subsystems shut down. Client shutdown complete."); } void at_fork() { printf("%d ->At fork, %d\n", gettid(), CTX->interception_enabled()); destroy_libc(); } void at_parent() { printf("%d ->At fork parent %d\n", gettid(), CTX->interception_enabled()); init_libc(); printf("%d -> x At fork parent %d\n", gettid(), CTX->interception_enabled()); } void at_child() { printf("%d ->At fork child %d\n", gettid(), CTX->interception_enabled()); init_libc(); printf("%d -> x At fork child %d\n", gettid(), CTX->interception_enabled()); }