Commit 3121ad67 authored by Ramon Nou's avatar Ramon Nou
Browse files

Merge branch 'rnou/java-syscall' into 'master'

Resolve "using std::string inside some hook functions may lead to deadlocks"

Closes #361

Closes #361

See merge request !255
parents c589f725 84d4e286
Loading
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -38,6 +38,9 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
  - gkfs_do_write uses int instead of ssize_t causing overflow ([!229](https://storage.bsc.es/gitlab/hpc/gekkofs/-/merge_requests/229))
  - proxy remove metadata has inverted return values ([!237](https://storage.bsc.es/gitlab/hpc/gekkofs/-/merge_requests/237))
  - Rename and symlink support leveraged ([!246](https://storage.bsc.es/gitlab/hpc/gekkofs/-/merge_requests/246))
  - Java with syscalls deadlocks as it try to resolve paths (malloc) in a locking situation ([!255](https://storage.bsc.es/gitlab/hpc/gekkofs/-/merge_requests/255))
    - It also solves flock missing implementation when we are ouside gekkofs
    - Some features in syscall_intercept still hangs if we do not lower the debug information.

## [0.9.4] - 2025-03
### New
+2 −0
Original line number Diff line number Diff line
@@ -42,6 +42,8 @@

namespace gkfs::path {

static const std::string excluded_paths[2] = {"sys/", "proc/"};

unsigned int
match_components(const std::string& path, unsigned int& path_components,
                 const std::vector<std::string>& components);
+92 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <linux/sched.h>
#include <sched.h>
#include <syscall.h>
#include <unistd.h>
@@ -76,6 +77,7 @@ enum class type {
    mmap_prot     = ::arg_type_t::mmap_prot,
    mmap_flags    = ::arg_type_t::mmap_flags,
    clone_flags   = ::arg_type_t::clone_flags,
    clone3_args   = ::arg_type_t::clone3_args,
    signum        = ::arg_type_t::signum,
    sigproc_how   = ::arg_type_t::sigproc_how,
    generic       = ::arg_type_t::arg,
@@ -96,6 +98,7 @@ static constexpr auto whence = type::whence;
static constexpr auto mmap_prot     = type::mmap_prot;
static constexpr auto mmap_flags    = type::mmap_flags;
static constexpr auto clone_flags   = type::clone_flags;
static constexpr auto clone3_args   = type::clone3_args;
static constexpr auto signum        = type::signum;
static constexpr auto sigproc_how   = type::sigproc_how;
static constexpr auto generic       = type::generic;
@@ -154,6 +157,9 @@ format_mmap_flags_arg_to(FmtBuffer& buffer, const printable_arg& parg);
template <typename FmtBuffer> inline void
format_clone_flags_arg_to(FmtBuffer& buffer, const printable_arg& parg);

template <typename FmtBuffer> inline void
format_clone3_args_arg_to(FmtBuffer& buffer, const printable_arg& parg);

template <typename FmtBuffer> inline void
format_signum_arg_to(FmtBuffer& buffer, const printable_arg& parg);

@@ -182,6 +188,7 @@ std::array<formatter<FmtBuffer>, arg_type_max> formatters = {
    /* [mmap_prot]     = */ format_mmap_prot_arg_to,
    /* [mmap_flags]    = */ format_mmap_flags_arg_to,
    /* [clone_flags]   = */ format_clone_flags_arg_to,
    /* [clone3_args]   = */ format_clone3_args_arg_to,
    /* [signum]        = */ format_signum_arg_to,
    /* [sigproc_how]   = */ format_sigproc_how_arg_to,
    /* [arg]           = */ format_arg_to,
@@ -444,6 +451,91 @@ format_clone_flags_arg_to(FmtBuffer& buffer, const printable_arg& parg) {
    return;
}

/**
 * format_clone3_args_arg_to - format a 'args' argument
 *
 * Format a 'args' argument (such as those passed to clone3())
 * and append the resulting string to the provided buffer.
 */
template <typename FmtBuffer>
inline void
format_clone3_args_arg_to(FmtBuffer& buffer, const printable_arg& parg) {

    //  struct clone_args {
    //            u64 flags;        /* Flags bit mask */
    //            u64 pidfd;        /* Where to store PID file descriptor
    //                                 (int *) */
    //            u64 child_tid;    /* Where to store child TID,
    //                                 in child's memory (pid_t *) */
    //            u64 parent_tid;   /* Where to store child TID,
    //                                 in parent's memory (pid_t *) */
    //            u64 exit_signal;  /* Signal to deliver to parent on
    //                                 child termination */
    //            u64 stack;        /* Pointer to lowest byte of stack */
    //            u64 stack_size;   /* Size of stack */
    //            u64 tls;          /* Location of new TLS */
    //            u64 set_tid;      /* Pointer to a pid_t array
    //                                 (since Linux 5.5) */
    //            u64 set_tid_size; /* Number of elements in set_tid
    //                                 (since Linux 5.5) */
    //            u64 cgroup;       /* File descriptor for target cgroup
    //                                 of child (since Linux 5.7) */
    //        };


    struct clone_args* ca = reinterpret_cast<clone_args*>(parg.value);
    /* Names for clone3() args arg */
        const auto flag_names =
            utils::make_array(
            FLAG_ENTRY(CLONE_VM),
            FLAG_ENTRY(CLONE_FS),
            FLAG_ENTRY(CLONE_FILES),
            FLAG_ENTRY(CLONE_SIGHAND),
            FLAG_ENTRY(CLONE_PTRACE),
            FLAG_ENTRY(CLONE_VFORK),
            FLAG_ENTRY(CLONE_PARENT),
            FLAG_ENTRY(CLONE_THREAD),
            FLAG_ENTRY(CLONE_NEWNS),
            FLAG_ENTRY(CLONE_SYSVSEM),
            FLAG_ENTRY(CLONE_SETTLS),
            FLAG_ENTRY(CLONE_PARENT_SETTID),
            FLAG_ENTRY(CLONE_CHILD_CLEARTID),
            FLAG_ENTRY(CLONE_DETACHED),
            FLAG_ENTRY(CLONE_UNTRACED),
            FLAG_ENTRY(CLONE_CHILD_SETTID),
#ifdef CLONE_NEWCGROUP
            FLAG_ENTRY(CLONE_NEWCGROUP),
#endif
            FLAG_ENTRY(CLONE_NEWUTS),
            FLAG_ENTRY(CLONE_NEWIPC),
            FLAG_ENTRY(CLONE_NEWUSER),
            FLAG_ENTRY(CLONE_NEWPID),
            FLAG_ENTRY(CLONE_NEWNET),
            FLAG_ENTRY(CLONE_IO));

    fmt::format_to(std::back_inserter(buffer), "{}=", "flags");
    format_flag_set(buffer, ca->flags, flag_names);
   
    fmt::format_to(std::back_inserter(buffer), "|", "signal");
    format_signum_arg_to(buffer, {"", ca->exit_signal});

    fmt::format_to(std::back_inserter(buffer), ",{}={}", "pidfd", (void*)ca->pidfd);
    fmt::format_to(std::back_inserter(buffer), ",{}={}", "child_tid", (void*)ca->child_tid);
    fmt::format_to(std::back_inserter(buffer), ",{}={}", "parent_tid", (void*)ca->parent_tid);
    fmt::format_to(std::back_inserter(buffer), ",{}={}", "stack", (void*)ca->stack);
    fmt::format_to(std::back_inserter(buffer), ",{}={}", "stack_size", ca->stack_size);
    fmt::format_to(std::back_inserter(buffer), ",{}={}", "tls", (void*)ca->tls);
    fmt::format_to(std::back_inserter(buffer), ",{}={}", "set_tid", (void*)ca->set_tid);
    // set_tid size and cgroup
    fmt::format_to(std::back_inserter(buffer), ",{}={}", "set_tid_size", ca->set_tid_size);
    fmt::format_to(std::back_inserter(buffer), ",{}={}", "cgroup", ca->cgroup);
    
    return;      


}


/**
 * format_signum_arg_to - format a 'signum' argument
 *
+1 −0
Original line number Diff line number Diff line
@@ -64,6 +64,7 @@ typedef enum {
    mmap_prot,      /* protections for the mmap() family of syscalls */
    mmap_flags,     /* flags for the mmap() family of syscalls */
    clone_flags,    /* flags for the clone() syscall */
    clone3_args,    /* args for the clone3() syscall */
    signum,         /* signal numbers */
    sigproc_how,    /* sigprocmask argument */
    arg,            /* generic argument, no special formatting */
+2 −2
Original line number Diff line number Diff line
@@ -114,8 +114,8 @@ constexpr auto dir = "metadata";
// which metadata should be considered apart from size and mode
// Blocks are used to store the rename status (-1 is a renamed file)
constexpr auto use_atime = false;
constexpr auto use_ctime = false;
constexpr auto use_mtime = false;
constexpr auto use_ctime = true;
constexpr auto use_mtime = true;
constexpr auto use_link_cnt = false;
#ifdef HAS_RENAME
constexpr auto use_blocks = true;
Loading