From ec345c477a83dcf4d8f2e668b615da3ff79e2354 Mon Sep 17 00:00:00 2001 From: jorge Date: Wed, 8 Nov 2017 23:23:52 +0000 Subject: [PATCH 01/12] patches for udocker-1.1.1 --- src/GNUmakefile | 4 +- src/path/temp.c | 24 +++- src/tracee/event.c | 266 ++++++++++++++++++++++++++++++++++++++++++++- src/tracee/event.h | 1 + 4 files changed, 291 insertions(+), 4 deletions(-) diff --git a/src/GNUmakefile b/src/GNUmakefile index a7b995042..a79259030 100644 --- a/src/GNUmakefile +++ b/src/GNUmakefile @@ -16,9 +16,9 @@ OBJDUMP = $(CROSS_COMPILE)objdump CPPFLAGS += -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -I. -I$(VPATH) CFLAGS += -Wall -Wextra -O2 -LDFLAGS += -ltalloc -Wl,-z,noexecstack +LDFLAGS += -L. -ltalloc -Wl,-z,noexecstack -static -CARE_LDFLAGS = -larchive +CARE_LDFLAGS = -larchive -static OBJECTS += \ cli/cli.o \ diff --git a/src/path/temp.c b/src/path/temp.c index 965beb17e..1cfb67478 100644 --- a/src/path/temp.c +++ b/src/path/temp.c @@ -47,6 +47,28 @@ const char *get_temp_directory() return temp_directory; } +/** + * Handle the return of d_type = DT_UNKNOWN by readdir(3) + * Not all filesystems support returning d_type in readdir(3) + */ +static int get_dtype(struct dirent *de) +{ + int dtype = de ? de->d_type : DT_UNKNOWN; + struct stat st; + + if (dtype != DT_UNKNOWN) + return dtype; + if (lstat(de->d_name, &st)) + return dtype; + if (S_ISREG(st.st_mode)) + return DT_REG; + if (S_ISDIR(st.st_mode)) + return DT_DIR; + if (S_ISLNK(st.st_mode)) + return DT_LNK; + return dtype; +} + /** * Remove recursively the content of the current working directory. * This latter has to lie in temp_directory (ie. "/tmp" on most @@ -117,7 +139,7 @@ static int clean_temp_cwd() continue; } - if (entry->d_type == DT_DIR) { + if (get_dtype(entry) == DT_DIR) { status = chdir(entry->d_name); if (status < 0) { note(NULL, WARNING, SYSTEM, "can't chdir '%s'", entry->d_name); diff --git a/src/tracee/event.c b/src/tracee/event.c index b1de18549..fa6861527 100644 --- a/src/tracee/event.c +++ b/src/tracee/event.c @@ -20,6 +20,7 @@ * 02110-1301 USA. */ +#include #include /* CLONE_*, */ #include /* pid_t, */ #include /* ptrace(1), PTRACE_*, */ @@ -48,6 +49,7 @@ #include "attribute.h" #include "compat.h" + /** * Start @tracee->exe with the given @argv[]. This function * returns -errno if an error occurred, otherwise 0. @@ -205,6 +207,29 @@ static void print_talloc_hierarchy(int signum, siginfo_t *siginfo UNUSED, void * static int last_exit_status = -1; +/** + * Check if kernel >= 4.8 + */ +bool is_kernel_4_8(void) { + static int version_48 = -1; + static int major = 0; + static int minor = 0; + + if (version_48 != -1) + return version_48; + + version_48 = false; + struct utsname utsname; + if (uname(&utsname) < 0) + return false; + + sscanf(utsname.release, "%d.%d", &major, &minor); + if (major >= 4) + if (minor >= 8) + version_48 = true; + return version_48; +} + /** * Check if this instance of PRoot can *technically* handle @tracee. */ @@ -255,6 +280,9 @@ int event_loop() struct sigaction signal_action; long status; int signum; + int kernel_4_8; + + kernel_4_8 = is_kernel_4_8(); /* Kill all tracees when exiting. */ status = atexit(kill_all_tracees); @@ -348,7 +376,12 @@ int event_loop() continue; } - signal = handle_tracee_event(tracee, tracee_status); + if (kernel_4_8) { + signal = handle_tracee_event_kernel_4_8(tracee, tracee_status); + } + else { + signal = handle_tracee_event(tracee, tracee_status); + } (void) restart_tracee(tracee, signal); } @@ -356,6 +389,236 @@ int event_loop() } /** + * For kernels >= 4.8.0 + * Handle the current event (@tracee_status) of the given @tracee. + * This function returns the "computed" signal that should be used to + * restart the given @tracee. + */ +int handle_tracee_event_kernel_4_8(Tracee *tracee, int tracee_status) +{ + static bool seccomp_detected = false; + static bool seccomp_enabled = false; /* added for 4.8.0 */ + long status; + int signal; + + /* Don't overwrite restart_how if it is explicitly set + * elsewhere, i.e in the ptrace emulation when single + * stepping. */ + if (tracee->restart_how == 0) { + /* When seccomp is enabled, all events are restarted in + * non-stop mode, but this default choice could be overwritten + * later if necessary. The check against "sysexit_pending" + * ensures PTRACE_SYSCALL (used to hit the exit stage under + * seccomp) is not cleared due to an event that would happen + * before the exit stage, eg. PTRACE_EVENT_EXEC for the exit + * stage of execve(2). */ + if (tracee->seccomp == ENABLED && !tracee->sysexit_pending) + tracee->restart_how = PTRACE_CONT; + else + tracee->restart_how = PTRACE_SYSCALL; + } + + /* Not a signal-stop by default. */ + signal = 0; + + if (WIFEXITED(tracee_status)) { + last_exit_status = WEXITSTATUS(tracee_status); + VERBOSE(tracee, 1, + "vpid %" PRIu64 ": exited with status %d", + tracee->vpid, last_exit_status); + terminate_tracee(tracee); + } + else if (WIFSIGNALED(tracee_status)) { + check_architecture(tracee); + VERBOSE(tracee, (int) (last_exit_status != -1), + "vpid %" PRIu64 ": terminated with signal %d", + tracee->vpid, WTERMSIG(tracee_status)); + terminate_tracee(tracee); + } + else if (WIFSTOPPED(tracee_status)) { + /* Don't use WSTOPSIG() to extract the signal + * since it clears the PTRACE_EVENT_* bits. */ + signal = (tracee_status & 0xfff00) >> 8; + + switch (signal) { + static bool deliver_sigtrap = false; + + case SIGTRAP: { + const unsigned long default_ptrace_options = ( + PTRACE_O_TRACESYSGOOD | + PTRACE_O_TRACEFORK | + PTRACE_O_TRACEVFORK | + PTRACE_O_TRACEVFORKDONE | + PTRACE_O_TRACEEXEC | + PTRACE_O_TRACECLONE | + PTRACE_O_TRACEEXIT); + + /* Distinguish some events from others and + * automatically trace each new process with + * the same options. + * + * Note that only the first bare SIGTRAP is + * related to the tracing loop, others SIGTRAP + * carry tracing information because of + * TRACE*FORK/CLONE/EXEC. */ + if (deliver_sigtrap) + break; /* Deliver this signal as-is. */ + + deliver_sigtrap = true; + + /* Try to enable seccomp mode 2... */ + status = ptrace(PTRACE_SETOPTIONS, tracee->pid, NULL, + default_ptrace_options | PTRACE_O_TRACESECCOMP); + if (status < 0) { + seccomp_enabled = false; + /* ... otherwise use default options only. */ + status = ptrace(PTRACE_SETOPTIONS, tracee->pid, NULL, + default_ptrace_options); + if (status < 0) { + note(tracee, ERROR, SYSTEM, "ptrace(PTRACE_SETOPTIONS)"); + exit(EXIT_FAILURE); + } + } + else { + if (getenv("PROOT_NO_SECCOMP") == NULL) + seccomp_enabled = true; + } + } + /* Fall through. */ + case SIGTRAP | PTRACE_EVENT_SECCOMP2 << 8: + case SIGTRAP | PTRACE_EVENT_SECCOMP << 8: + + if (!seccomp_detected && seccomp_enabled) { + VERBOSE(tracee, 1, "ptrace acceleration (seccomp mode 2) enabled"); + tracee->seccomp = ENABLED; + seccomp_detected = true; + } + + if (signal == (SIGTRAP | PTRACE_EVENT_SECCOMP2 << 8) || + signal == (SIGTRAP | PTRACE_EVENT_SECCOMP << 8)) { + + unsigned long flags = 0; + signal = 0; + + /* SECCOMP TRAP can only be received for + * sysenter events, ignore otherwise */ + if (!IS_IN_SYSENTER(tracee)) { + tracee->restart_how = PTRACE_CONT; + return 0; + } + status = ptrace(PTRACE_GETEVENTMSG, tracee->pid, NULL, &flags); + if (status < 0) + break; + + if (tracee->seccomp == ENABLED && (flags & FILTER_SYSEXIT) == 0) { + tracee->restart_how = PTRACE_CONT; + translate_syscall(tracee); + + if (tracee->seccomp == DISABLING) + tracee->restart_how = PTRACE_SYSCALL; + break; + } + } + + /* Fall through. */ + case SIGTRAP | 0x80: + + signal = 0; + + /* This tracee got signaled then freed during the + sysenter stage but the kernel reports the sysexit + stage; just discard this spurious tracee/event. */ + + if (tracee->exe == NULL) { + tracee->restart_how = PTRACE_CONT; /* SYSCALL OR CONT */ + return 0; + } + + switch (tracee->seccomp) { + case ENABLED: + if (IS_IN_SYSENTER(tracee)) { + /* sysenter: ensure the sysexit + * stage will be hit under seccomp. */ + tracee->restart_how = PTRACE_SYSCALL; + tracee->sysexit_pending = true; + } + else { + /* sysexit: the next sysenter + * will be notified by seccomp. */ + tracee->restart_how = PTRACE_CONT; + tracee->sysexit_pending = false; + } + /* Fall through. */ + case DISABLED: + translate_syscall(tracee); + + /* This syscall has disabled seccomp. */ + if (tracee->seccomp == DISABLING) { + tracee->restart_how = PTRACE_SYSCALL; + tracee->seccomp = DISABLED; + } + + break; + + case DISABLING: + /* Seccomp was disabled by the + * previous syscall, but its sysenter + * stage was already handled. */ + tracee->seccomp = DISABLED; + if (IS_IN_SYSENTER(tracee)) + tracee->status = 1; + break; + } + break; + + case SIGTRAP | PTRACE_EVENT_VFORK << 8: + signal = 0; + (void) new_child(tracee, CLONE_VFORK); + break; + + case SIGTRAP | PTRACE_EVENT_FORK << 8: + case SIGTRAP | PTRACE_EVENT_CLONE << 8: + signal = 0; + (void) new_child(tracee, 0); + break; + + case SIGTRAP | PTRACE_EVENT_VFORK_DONE << 8: + case SIGTRAP | PTRACE_EVENT_EXEC << 8: + case SIGTRAP | PTRACE_EVENT_EXIT << 8: + signal = 0; + break; + + case SIGSTOP: + /* Stop this tracee until PRoot has received + * the EVENT_*FORK|CLONE notification. */ + if (tracee->exe == NULL) { + tracee->sigstop = SIGSTOP_PENDING; + signal = -1; + } + + /* For each tracee, the first SIGSTOP + * is only used to notify the tracer. */ + if (tracee->sigstop == SIGSTOP_IGNORED) { + tracee->sigstop = SIGSTOP_ALLOWED; + signal = 0; + } + break; + + default: + /* Deliver this signal as-is. */ + break; + } + } + + /* Clear the pending event, if any. */ + tracee->as_ptracee.event4.proot.pending = false; + + return signal; +} + + +/** + * For kernels < 4.8.0 * Handle the current event (@tracee_status) of the given @tracee. * This function returns the "computed" signal that should be used to * restart the given @tracee. @@ -579,6 +842,7 @@ int handle_tracee_event(Tracee *tracee, int tracee_status) return signal; } + /** * Restart the given @tracee with the specified @signal. This * function returns false if the tracee was not restarted (error or diff --git a/src/tracee/event.h b/src/tracee/event.h index ff00cfbc7..7899e7307 100644 --- a/src/tracee/event.h +++ b/src/tracee/event.h @@ -30,6 +30,7 @@ extern int launch_process(Tracee *tracee, char *const argv[]); extern int event_loop(); extern int handle_tracee_event(Tracee *tracee, int tracee_status); +extern int handle_tracee_event_kernel_4_8(Tracee *tracee, int tracee_status); extern bool restart_tracee(Tracee *tracee, int signal); #endif /* TRACEE_EVENT_H */ From 2a2a37e8e35ff7fabfc2b1faade3959a78cf44ff Mon Sep 17 00:00:00 2001 From: Akihiro Suda Date: Fri, 13 Apr 2018 14:33:18 +0900 Subject: [PATCH 02/12] support chroot to a relative path to the current root. e.g. `chroot .` in `/`. This fix is needed for running `apk`. Signed-off-by: Akihiro Suda --- src/extension/fake_id0/fake_id0.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/extension/fake_id0/fake_id0.c b/src/extension/fake_id0/fake_id0.c index e86d483e9..b5c21a4db 100644 --- a/src/extension/fake_id0/fake_id0.c +++ b/src/extension/fake_id0/fake_id0.c @@ -664,6 +664,10 @@ static int handle_sysexit_end(Tracee *tracee, Config *config) case PR_chroot: { char path[PATH_MAX]; + char path_translated[PATH_MAX]; + char path_translated_absolute[PATH_MAX]; + char root_translated[PATH_MAX]; + char root_translated_absolute[PATH_MAX]; word_t input; int status; @@ -677,12 +681,24 @@ static int handle_sysexit_end(Tracee *tracee, Config *config) input = peek_reg(tracee, MODIFIED, SYSARG_1); + // path can be relative status = read_path(tracee, path, input); if (status < 0) return status; + // weird: translate(".") returns "/." rather than "/", when cwd is "/" + status = translate_path(tracee, path_translated, AT_FDCWD, path, false); + if (status < 0) + return status; + realpath(path_translated, path_translated_absolute); + + status = translate_path(tracee, root_translated, AT_FDCWD, get_root(tracee), false); + if (status < 0) + return status; + realpath(root_translated, root_translated_absolute); + /* Only "new rootfs == current rootfs" is supported yet. */ - status = compare_paths(get_root(tracee), path); + status = compare_paths(root_translated_absolute, path_translated_absolute); if (status != PATHS_ARE_EQUAL) return 0; From 081bb63955eb4378e53cf4d0eb0ed0d3222bf66e Mon Sep 17 00:00:00 2001 From: Akihiro Suda Date: Fri, 13 Apr 2018 14:35:49 +0900 Subject: [PATCH 03/12] add rootlesscontainers support This commit allows preserving file owner information as `user.rootlesscontainers` xattr values. Please refer to https://rootlesscontaine.rs/ for further information. Signed-off-by: Akihiro Suda --- .travis.yml | 2 +- doc/proot/rpm-spec | 2 +- doc/proot/stylesheets/rpm-spec.xsl | 2 +- src/GNUmakefile | 13 ++ src/extension/fake_id0/fake_id0.c | 158 +++++++++++++- src/rootlesscontainers/COPYING.APACHE2 | 202 ++++++++++++++++++ src/rootlesscontainers/README.md | 13 ++ .../rootlesscontainers.pb-c.c | 103 +++++++++ .../rootlesscontainers.pb-c.h | 86 ++++++++ .../rootlesscontainers.proto | 33 +++ 10 files changed, 610 insertions(+), 4 deletions(-) create mode 100644 src/rootlesscontainers/COPYING.APACHE2 create mode 100644 src/rootlesscontainers/README.md create mode 100644 src/rootlesscontainers/rootlesscontainers.pb-c.c create mode 100644 src/rootlesscontainers/rootlesscontainers.pb-c.h create mode 100644 src/rootlesscontainers/rootlesscontainers.proto diff --git a/.travis.yml b/.travis.yml index 86d96392f..dc5d50f71 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ compiler: gcc before_install: - sudo apt-get update -qq - - sudo apt-get install -qq libtalloc-dev uthash-dev libarchive-dev gdb strace realpath + - sudo apt-get install -qq libtalloc-dev uthash-dev libarchive-dev gdb strace realpath libprotobuf-c-dev libattr1-dev - sudo pip install cpp-coveralls script: if [ ${COVERITY_SCAN_BRANCH} != 1 ]; then make -C src loader.exe loader-m32.exe build.h && env CFLAGS=--coverage LDFLAGS='--coverage' make -C src proot && env PATH=/bin:/usr/bin:/sbin:/usr/sbin:$PWD/src make -C tests; fi diff --git a/doc/proot/rpm-spec b/doc/proot/rpm-spec index 5f0fae432..bb7f99dab 100644 --- a/doc/proot/rpm-spec +++ b/doc/proot/rpm-spec @@ -10,7 +10,7 @@ Buildroot : %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX) Prefix : /usr Name : proot -BuildRequires: libtalloc-devel +BuildRequires: libtalloc-devel, protobuf-c-devel, libattr-devel %if 0%{?suse_version} >= 1210 || 0%{?fedora_version} >= 15 BuildRequires: glibc-static diff --git a/doc/proot/stylesheets/rpm-spec.xsl b/doc/proot/stylesheets/rpm-spec.xsl index 7015091f7..a86a3a114 100644 --- a/doc/proot/stylesheets/rpm-spec.xsl +++ b/doc/proot/stylesheets/rpm-spec.xsl @@ -15,7 +15,7 @@ Buildroot : %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX) Prefix : /usr Name : proot -BuildRequires: libtalloc-devel +BuildRequires: libtalloc-devel, protobuf-c-devel, libattr-devel %if 0%{?suse_version} >= 1210 || 0%{?fedora_version} >= 15 BuildRequires: glibc-static diff --git a/src/GNUmakefile b/src/GNUmakefile index a79259030..03ed951d8 100644 --- a/src/GNUmakefile +++ b/src/GNUmakefile @@ -1,6 +1,8 @@ # If you want to build outside of the source tree, use the -f option: # make -f ${SOMEWHERE}/proot/src/GNUmakefile +PERSISTENT_CHOWN := 1 + # the VPATH variable must point to the actual makefile directory VPATH := $(dir $(lastword $(MAKEFILE_LIST))) SRC = $(dir $(firstword $(MAKEFILE_LIST))) @@ -15,8 +17,15 @@ OBJCOPY = $(CROSS_COMPILE)objcopy OBJDUMP = $(CROSS_COMPILE)objdump CPPFLAGS += -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -I. -I$(VPATH) +ifdef PERSISTENT_CHOWN + CPPFLAGS += -DPERSISTENT_CHOWN + CPPFLAGS += $(shell pkg-config --cflags libprotobuf-c) +endif CFLAGS += -Wall -Wextra -O2 LDFLAGS += -L. -ltalloc -Wl,-z,noexecstack -static +ifdef PERSISTENT_CHOWN + LDFLAGS += $(shell pkg-config --libs libprotobuf-c) +endif CARE_LDFLAGS = -larchive -static @@ -60,6 +69,10 @@ OBJECTS += \ extension/portmap/map.o \ loader/loader-wrapped.o +ifdef PERSISTENT_CHOWN + OBJECTS += rootlesscontainers/rootlesscontainers.pb-c.o +endif + define define_from_arch.h $2$1 := $(shell $(CC) $1 -E -dM -DNO_LIBC_HEADER $(SRC)/arch.h | grep -w $2 | cut -f 3 -d ' ') endef diff --git a/src/extension/fake_id0/fake_id0.c b/src/extension/fake_id0/fake_id0.c index b5c21a4db..3d7b9e7ff 100644 --- a/src/extension/fake_id0/fake_id0.c +++ b/src/extension/fake_id0/fake_id0.c @@ -44,6 +44,81 @@ #include "path/binding.h" #include "arch.h" +#if defined(PERSISTENT_CHOWN) +#include +#include +#include "path/path.h" +#include "rootlesscontainers/rootlesscontainers.pb-c.h" +#define XATTR_USER_ROOTLESSCONTAINERS "user.rootlesscontainers" + +// return 0 on success. +int rootlesscontainers_get_xattr (int fd, const char *path, uid_t *uid, gid_t *gid) { + Rootlesscontainers__Resource *msg; + void *buf; + assert(fd >= 0 || path != NULL); + ssize_t bufsz = (path != NULL) ? + lgetxattr(path, XATTR_USER_ROOTLESSCONTAINERS, NULL, 0) : + fgetxattr(fd, XATTR_USER_ROOTLESSCONTAINERS, NULL, 0); + // errno can be ENOATTR, EBADF... Typically not critical. + if (bufsz <= 0) + return bufsz; + buf = malloc(bufsz); + if (buf == NULL) + return -1; + bufsz = (path != NULL) ? + lgetxattr(path, XATTR_USER_ROOTLESSCONTAINERS, buf, bufsz) : + fgetxattr(fd, XATTR_USER_ROOTLESSCONTAINERS, buf, bufsz); + if (bufsz <= 0) + return bufsz; + msg = rootlesscontainers__resource__unpack(NULL, bufsz, buf); + if (msg == NULL) { + free(buf); + return -1; + } + if (!msg->has_uid) + msg->uid = (uid_t)-1; + if (!msg->has_gid) + msg->gid = (gid_t)-1; + *uid = (uid_t)msg->uid; + *gid = (gid_t)msg->gid; + free(buf); + rootlesscontainers__resource__free_unpacked(msg, NULL); + return 0; +} + +int rootlesscontainers_set_xattr (int fd, const char *path, uid_t uid, gid_t gid) { + int rc; + Rootlesscontainers__Resource msg = ROOTLESSCONTAINERS__RESOURCE__INIT; + void *buf; + size_t bufsz; + assert(fd >= 0 || path != NULL); + msg.has_uid = true; + msg.uid = (uint32_t)uid; + msg.has_gid = true; + msg.gid = (uint32_t)gid; + bufsz = rootlesscontainers__resource__get_packed_size(&msg); + buf = malloc(bufsz); + if (buf == NULL) + return -1; + rootlesscontainers__resource__pack(&msg, buf); + rc = (path != NULL) ? + lsetxattr(path, XATTR_USER_ROOTLESSCONTAINERS, buf, bufsz, 0): + fsetxattr(fd, XATTR_USER_ROOTLESSCONTAINERS, buf, bufsz, 0); + free(buf); + return rc; +} + +// ENOATTR is ignored +int rootlesscontainers_remove_xattr (int fd, const char *path) { + assert(fd >= 0 || path != NULL); + int rc = (path != NULL) ? + lremovexattr(path, XATTR_USER_ROOTLESSCONTAINERS): + fremovexattr(fd, XATTR_USER_ROOTLESSCONTAINERS); + return ( rc < 0 && errno == ENOATTR) ? 0 : rc; +} + +#endif /* if defined(PERSISTENT_CHOWN) */ + typedef struct { uid_t ruid; uid_t euid; @@ -231,7 +306,7 @@ static void override_permissions(const Tracee *tracee, const char *path, bool is /** * Adjust current @tracee's syscall parameters according to @config. - * This function always returns 0. + * This function returns 0 unless there is an error. */ static int handle_sysenter_end(Tracee *tracee, const Config *config) { @@ -270,6 +345,12 @@ static int handle_sysenter_end(Tracee *tracee, const Config *config) Reg gid_sysarg; uid_t uid; gid_t gid; +#if defined(PERSISTENT_CHOWN) + int status; + int fd = -1; // shut up gcc uninitialization warning + char path[PATH_MAX]; + bool with_path = (sysnum == PR_chown || sysnum == PR_chown32 || sysnum == PR_lchown || sysnum == PR_lchown32 || sysnum == PR_fchownat); +#endif if (sysnum == PR_fchownat) { uid_sysarg = SYSARG_3; @@ -283,6 +364,41 @@ static int handle_sysenter_end(Tracee *tracee, const Config *config) uid = peek_reg(tracee, ORIGINAL, uid_sysarg); gid = peek_reg(tracee, ORIGINAL, gid_sysarg); +#if defined(PERSISTENT_CHOWN) + if (with_path) { + word_t input; + char guestpath[PATH_MAX]; + int dirfd = AT_FDCWD; + if (sysnum == PR_fchownat) { + dirfd = peek_reg(tracee, ORIGINAL, SYSARG_1); + input = peek_reg(tracee, ORIGINAL, SYSARG_2); + status = read_path(tracee, guestpath, input); + } else { + input = peek_reg(tracee, ORIGINAL, SYSARG_1); + status = read_path(tracee, guestpath, input); + } + if (status < 0) + return status; + status = translate_path(tracee, path, dirfd, guestpath, false); + if (status < 0) + return status; + } else { + fd = peek_reg(tracee, ORIGINAL, SYSARG_1); + } + + // TODO: we can also remove xattr when [ug]id == -1 && the recoded one == config->r[ug]id + if (uid != config->ruid || gid != config->rgid) + status = rootlesscontainers_set_xattr(fd, with_path ? path : NULL, uid, gid); + else + status = rootlesscontainers_remove_xattr(fd, with_path ? path : NULL); + + if (status < 0) + return status; + + /* this should always succeed */ + poke_reg(tracee, uid_sysarg, getuid()); + poke_reg(tracee, gid_sysarg, getgid()); +#else /* Swap actual and emulated ids to get a chance of * success. */ if (uid == config->ruid) @@ -290,6 +406,7 @@ static int handle_sysenter_end(Tracee *tracee, const Config *config) if (gid == config->rgid) poke_reg(tracee, gid_sysarg, getgid()); +#endif return 0; } @@ -624,6 +741,14 @@ static int handle_sysexit_end(Tracee *tracee, Config *config) Reg sysarg; uid_t uid; gid_t gid; +#if defined(PERSISTENT_CHOWN) + int status; + char path[PATH_MAX]; + bool with_path = !(sysnum == PR_fstat64 || sysnum == PR_fstat); + int fd = -1; + uid_t uid_xattr; + gid_t gid_xattr; +#endif /* Override only if it succeed. */ result = peek_reg(tracee, CURRENT, SYSARG_RESULT); @@ -659,6 +784,37 @@ static int handle_sysexit_end(Tracee *tracee, Config *config) if (gid == getgid()) poke_uint32(tracee, address + offsetof_stat_gid(tracee), config->sgid); +#if defined(PERSISTENT_CHOWN) + if (with_path) { + word_t input; + char guestpath[PATH_MAX]; + int dirfd = AT_FDCWD; + if (sysnum == PR_fstatat64 || sysnum == PR_newfstatat) { + dirfd = peek_reg(tracee, ORIGINAL, SYSARG_1); + input = peek_reg(tracee, ORIGINAL, SYSARG_2); + status = read_path(tracee, guestpath, input); + } else { + input = peek_reg(tracee, ORIGINAL, SYSARG_1); + status = read_path(tracee, guestpath, input); + } + if (status < 0) + return status; + status = translate_path(tracee, path, dirfd, guestpath, false); + if (status < 0) + return status; + } else { + fd = peek_reg(tracee, ORIGINAL, SYSARG_1); + } + status = rootlesscontainers_get_xattr(fd, with_path ? path: NULL, &uid_xattr, &gid_xattr); + // error is not critical, typically. e.g. ENOATTR + if (status >= 0) { + if (uid_xattr != (uid_t)-1) + poke_uint32(tracee, address + offsetof_stat_uid(tracee), uid_xattr); + if (gid_xattr != (gid_t)-1) + poke_uint32(tracee, address + offsetof_stat_gid(tracee), gid_xattr); + } +#endif + return 0; } diff --git a/src/rootlesscontainers/COPYING.APACHE2 b/src/rootlesscontainers/COPYING.APACHE2 new file mode 100644 index 000000000..d64569567 --- /dev/null +++ b/src/rootlesscontainers/COPYING.APACHE2 @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/src/rootlesscontainers/README.md b/src/rootlesscontainers/README.md new file mode 100644 index 000000000..acc6fb854 --- /dev/null +++ b/src/rootlesscontainers/README.md @@ -0,0 +1,13 @@ +# rootlesscontainers.proto + +This directory contains `rootlesscontainers.proto`, which is used for preserving emulated file owner information as `user.rootlesscontainers` xattr values. + +## Source + +https://raw.githubusercontent.com/rootless-containers/rootlesscontaine.rs/f7b0f5486bb0e0be75771ce50c54471296f040eb/docs/proto/rootlesscontainers.proto + +## Compile + +```console +$ protoc-c --c_out=. rootlesscontainers.proto +``` diff --git a/src/rootlesscontainers/rootlesscontainers.pb-c.c b/src/rootlesscontainers/rootlesscontainers.pb-c.c new file mode 100644 index 000000000..96753b0e2 --- /dev/null +++ b/src/rootlesscontainers/rootlesscontainers.pb-c.c @@ -0,0 +1,103 @@ +/* Generated by the protocol buffer compiler. DO NOT EDIT! */ +/* Generated from: rootlesscontainers.proto */ + +/* Do not generate deprecated warnings for self */ +#ifndef PROTOBUF_C__NO_DEPRECATED +#define PROTOBUF_C__NO_DEPRECATED +#endif + +#include "rootlesscontainers.pb-c.h" +void rootlesscontainers__resource__init + (Rootlesscontainers__Resource *message) +{ + static Rootlesscontainers__Resource init_value = ROOTLESSCONTAINERS__RESOURCE__INIT; + *message = init_value; +} +size_t rootlesscontainers__resource__get_packed_size + (const Rootlesscontainers__Resource *message) +{ + assert(message->base.descriptor == &rootlesscontainers__resource__descriptor); + return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message)); +} +size_t rootlesscontainers__resource__pack + (const Rootlesscontainers__Resource *message, + uint8_t *out) +{ + assert(message->base.descriptor == &rootlesscontainers__resource__descriptor); + return protobuf_c_message_pack ((const ProtobufCMessage*)message, out); +} +size_t rootlesscontainers__resource__pack_to_buffer + (const Rootlesscontainers__Resource *message, + ProtobufCBuffer *buffer) +{ + assert(message->base.descriptor == &rootlesscontainers__resource__descriptor); + return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer); +} +Rootlesscontainers__Resource * + rootlesscontainers__resource__unpack + (ProtobufCAllocator *allocator, + size_t len, + const uint8_t *data) +{ + return (Rootlesscontainers__Resource *) + protobuf_c_message_unpack (&rootlesscontainers__resource__descriptor, + allocator, len, data); +} +void rootlesscontainers__resource__free_unpacked + (Rootlesscontainers__Resource *message, + ProtobufCAllocator *allocator) +{ + assert(message->base.descriptor == &rootlesscontainers__resource__descriptor); + protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); +} +static const ProtobufCFieldDescriptor rootlesscontainers__resource__field_descriptors[2] = +{ + { + "uid", + 1, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_UINT32, + offsetof(Rootlesscontainers__Resource, has_uid), + offsetof(Rootlesscontainers__Resource, uid), + NULL, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, + { + "gid", + 2, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_UINT32, + offsetof(Rootlesscontainers__Resource, has_gid), + offsetof(Rootlesscontainers__Resource, gid), + NULL, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, +}; +static const unsigned rootlesscontainers__resource__field_indices_by_name[] = { + 1, /* field[1] = gid */ + 0, /* field[0] = uid */ +}; +static const ProtobufCIntRange rootlesscontainers__resource__number_ranges[1 + 1] = +{ + { 1, 0 }, + { 0, 2 } +}; +const ProtobufCMessageDescriptor rootlesscontainers__resource__descriptor = +{ + PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, + "rootlesscontainers.Resource", + "Resource", + "Rootlesscontainers__Resource", + "rootlesscontainers", + sizeof(Rootlesscontainers__Resource), + 2, + rootlesscontainers__resource__field_descriptors, + rootlesscontainers__resource__field_indices_by_name, + 1, rootlesscontainers__resource__number_ranges, + (ProtobufCMessageInit) rootlesscontainers__resource__init, + NULL,NULL,NULL /* reserved[123] */ +}; diff --git a/src/rootlesscontainers/rootlesscontainers.pb-c.h b/src/rootlesscontainers/rootlesscontainers.pb-c.h new file mode 100644 index 000000000..a999faf36 --- /dev/null +++ b/src/rootlesscontainers/rootlesscontainers.pb-c.h @@ -0,0 +1,86 @@ +/* Generated by the protocol buffer compiler. DO NOT EDIT! */ +/* Generated from: rootlesscontainers.proto */ + +#ifndef PROTOBUF_C_rootlesscontainers_2eproto__INCLUDED +#define PROTOBUF_C_rootlesscontainers_2eproto__INCLUDED + +#include + +PROTOBUF_C__BEGIN_DECLS + +#if PROTOBUF_C_VERSION_NUMBER < 1000000 +# error This file was generated by a newer version of protoc-c which is incompatible with your libprotobuf-c headers. Please update your headers. +#elif 1002001 < PROTOBUF_C_MIN_COMPILER_VERSION +# error This file was generated by an older version of protoc-c which is incompatible with your libprotobuf-c headers. Please regenerate this file with a newer version of protoc-c. +#endif + + +typedef struct _Rootlesscontainers__Resource Rootlesscontainers__Resource; + + +/* --- enums --- */ + + +/* --- messages --- */ + +/* + * Resource defines the schema for "user.rootlesscontainers" xattr values. + * The resource can be used as a persistent storage for emulated `chown(2)` syscall. + * Syscall emulators SHOULD try to hide this xattr from the emulated environment. + */ +struct _Rootlesscontainers__Resource +{ + ProtobufCMessage base; + /* + * Zero-value MUST be parsed as a literally zero-value, not "unset". + * To keep both uid and gid unchaged, the entire xattr value SHOULD be removed. + * To keep either one of uid or gid unchaged, 0xFFFFFFFF (in other words, + * `(uint32_t) -1`, see also chown(2)) value SHOULD be set. + * (Because some protobuf bindings cannot distinguish "unset" from zero-value.) + */ + protobuf_c_boolean has_uid; + uint32_t uid; + protobuf_c_boolean has_gid; + uint32_t gid; +}; +#define ROOTLESSCONTAINERS__RESOURCE__INIT \ + { PROTOBUF_C_MESSAGE_INIT (&rootlesscontainers__resource__descriptor) \ + , 0,0, 0,0 } + + +/* Rootlesscontainers__Resource methods */ +void rootlesscontainers__resource__init + (Rootlesscontainers__Resource *message); +size_t rootlesscontainers__resource__get_packed_size + (const Rootlesscontainers__Resource *message); +size_t rootlesscontainers__resource__pack + (const Rootlesscontainers__Resource *message, + uint8_t *out); +size_t rootlesscontainers__resource__pack_to_buffer + (const Rootlesscontainers__Resource *message, + ProtobufCBuffer *buffer); +Rootlesscontainers__Resource * + rootlesscontainers__resource__unpack + (ProtobufCAllocator *allocator, + size_t len, + const uint8_t *data); +void rootlesscontainers__resource__free_unpacked + (Rootlesscontainers__Resource *message, + ProtobufCAllocator *allocator); +/* --- per-message closures --- */ + +typedef void (*Rootlesscontainers__Resource_Closure) + (const Rootlesscontainers__Resource *message, + void *closure_data); + +/* --- services --- */ + + +/* --- descriptors --- */ + +extern const ProtobufCMessageDescriptor rootlesscontainers__resource__descriptor; + +PROTOBUF_C__END_DECLS + + +#endif /* PROTOBUF_C_rootlesscontainers_2eproto__INCLUDED */ diff --git a/src/rootlesscontainers/rootlesscontainers.proto b/src/rootlesscontainers/rootlesscontainers.proto new file mode 100644 index 000000000..5bcfdfd96 --- /dev/null +++ b/src/rootlesscontainers/rootlesscontainers.proto @@ -0,0 +1,33 @@ +// rootlesscontainers.proto +// Copyright (C) 2018 Rootless Containers authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +// The rootlesscontainers package is maintained at https://rootlesscontaine.rs/ . +// If you want to extend the resource definition, please open a PR. +package rootlesscontainers; + +// Resource defines the schema for "user.rootlesscontainers" xattr values. +// The resource can be used as a persistent storage for emulated `chown(2)` syscall. +// Syscall emulators SHOULD try to hide this xattr from the emulated environment. +message Resource { + // Zero-value MUST be parsed as a literally zero-value, not "unset". + // To keep both uid and gid unchaged, the entire xattr value SHOULD be removed. + // To keep either one of uid or gid unchaged, 0xFFFFFFFF (in other words, + // `(uint32_t) -1`, see also chown(2)) value SHOULD be set. + // (Because some protobuf bindings cannot distinguish "unset" from zero-value.) + uint32 uid = 1; + uint32 gid = 2; +} From 182d0140ba63c58119c1976c16be85cc2d1226ce Mon Sep 17 00:00:00 2001 From: Max Goltzsche Date: Sun, 23 Sep 2018 19:33:01 +0200 Subject: [PATCH 04/12] Added libattr fallback from ENOATTR to ENODATA in fake_id0 to support build on fedora. Signed-off-by: Max Goltzsche --- src/extension/fake_id0/fake_id0.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/extension/fake_id0/fake_id0.c b/src/extension/fake_id0/fake_id0.c index 3d7b9e7ff..da96aa84d 100644 --- a/src/extension/fake_id0/fake_id0.c +++ b/src/extension/fake_id0/fake_id0.c @@ -51,6 +51,10 @@ #include "rootlesscontainers/rootlesscontainers.pb-c.h" #define XATTR_USER_ROOTLESSCONTAINERS "user.rootlesscontainers" +#ifndef ENOATTR +# define ENOATTR ENODATA +#endif + // return 0 on success. int rootlesscontainers_get_xattr (int fd, const char *path, uid_t *uid, gid_t *gid) { Rootlesscontainers__Resource *msg; From 683bc8ffd5c494004bd18d3e1308bccf48cfe6ce Mon Sep 17 00:00:00 2001 From: Akihiro Suda Date: Thu, 29 Nov 2018 14:17:32 +0900 Subject: [PATCH 05/12] update travis Signed-off-by: Akihiro Suda --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index dc5d50f71..38ad5cdbd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ +dist: xenial language: c compiler: gcc From b013322e7e986ca79e0d9dfd7ff7b499e9672287 Mon Sep 17 00:00:00 2001 From: Akihiro Suda Date: Thu, 29 Nov 2018 14:31:55 +0900 Subject: [PATCH 06/12] disable coverity Signed-off-by: Akihiro Suda --- .travis.yml | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/.travis.yml b/.travis.yml index 38ad5cdbd..412645d2b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,25 +6,5 @@ compiler: gcc before_install: - sudo apt-get update -qq - sudo apt-get install -qq libtalloc-dev uthash-dev libarchive-dev gdb strace realpath libprotobuf-c-dev libattr1-dev - - sudo pip install cpp-coveralls -script: if [ ${COVERITY_SCAN_BRANCH} != 1 ]; then make -C src loader.exe loader-m32.exe build.h && env CFLAGS=--coverage LDFLAGS='--coverage' make -C src proot && env PATH=/bin:/usr/bin:/sbin:/usr/sbin:$PWD/src make -C tests; fi - -after_success: - - coveralls --build-root src --exclude tests --gcov-options '\-lp' - -env: - global: - # The next declaration is the encrypted COVERITY_SCAN_TOKEN, created - # via the "travis encrypt" command using the project repo's public key - - secure: "G2fG/oWcEOiG+RYLCK3XOO/7ZXn4LoiIyOT4fxxJzb43gu/90lEkbwsALqVAAjh/Fn5T4rYqiECeJ0jEhxvWak1pK/jkFshfXzL34yaY8ZLNtwvnFf7+DDtsj1Hx136TEjYuyc/jasoTf/3fNlIX6Oh1BB6c0UtJfHwTfbreRbI=" - -addons: - coverity_scan: - project: - name: "cedric-vincent/PRoot" - description: "PRoot" - notification_email: cedric.vincent@gmail.com - build_command_prepend: - build_command: make -C src - branch_pattern: coverity_scan +script: make -C src From e7976c55abd83dee2793892f723580cf77057c34 Mon Sep 17 00:00:00 2001 From: Dave Dykstra <2129743+DrDaveD@users.noreply.github.com> Date: Tue, 30 Dec 2025 08:36:41 -0600 Subject: [PATCH 07/12] fix problems with rootlesscontainer support after update to upstream master branch Signed-off-by: Dave Dykstra <2129743+DrDaveD@users.noreply.github.com> --- src/extension/fake_id0/fake_id0.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/extension/fake_id0/fake_id0.c b/src/extension/fake_id0/fake_id0.c index 4e3f61f41..32ef9849a 100644 --- a/src/extension/fake_id0/fake_id0.c +++ b/src/extension/fake_id0/fake_id0.c @@ -807,7 +807,7 @@ static int handle_sysexit_end(Tracee *tracee, Config *config) word_t input; char guestpath[PATH_MAX]; int dirfd = AT_FDCWD; - if (sysnum == PR_fstatat64 || sysnum == PR_newfstatat) { + if (sysnum == PR_fstatat64 || sysnum == PR_newfstatat || sysnum == PR_statx) { dirfd = peek_reg(tracee, ORIGINAL, SYSARG_1); input = peek_reg(tracee, ORIGINAL, SYSARG_2); status = read_path(tracee, guestpath, input); @@ -827,9 +827,9 @@ static int handle_sysexit_end(Tracee *tracee, Config *config) // error is not critical, typically. e.g. ENOATTR if (status >= 0) { if (uid_xattr != (uid_t)-1) - poke_uint32(tracee, address + offsetof_stat_uid(tracee), uid_xattr); + poke_uint32(tracee, address + uid_offset, uid_xattr); if (gid_xattr != (gid_t)-1) - poke_uint32(tracee, address + offsetof_stat_gid(tracee), gid_xattr); + poke_uint32(tracee, address + gid_offset, gid_xattr); } #endif From 20888f102a663b60c1ff86447ad7e30489484c04 Mon Sep 17 00:00:00 2001 From: Dave Dykstra <2129743+DrDaveD@users.noreply.github.com> Date: Tue, 30 Dec 2025 09:42:39 -0600 Subject: [PATCH 08/12] remove broken actions Signed-off-by: Dave Dykstra <2129743+DrDaveD@users.noreply.github.com> --- .github/workflows/main.yml | 58 -------------------------------------- 1 file changed, 58 deletions(-) delete mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index c0f4c8b71..000000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,58 +0,0 @@ -name: build - -on: - push: - branches: - - master - pull_request: - types: [opened, synchronize, reopened] - -jobs: - build: - name: "${{ matrix.SECCOMP == '1' && 'seccomp' || 'no-seccomp' }}" - runs-on: ubuntu-latest - env: - BUILD_WRAPPER_OUT_DIR: tmp - strategy: - fail-fast: false - matrix: - SECCOMP: [ 0, 1 ] - - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Install sonar-scanner and build-wrapper - uses: sonarsource/sonarcloud-github-c-cpp@v1 - - - name: Install build dependencies - run: | - sudo apt-get update -qq - sudo apt-get install -qq clang-tools-12 curl gdb lcov libarchive-dev libtalloc-dev sloccount strace swig uthash-dev python3-dev lzop - - - name: Gather analytics - run: sloccount --details . - - - name: Build elf loader, proot, and care - run: | - build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} make -C src loader.elf loader-m32.elf build.h - build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} env CFLAGS=--coverage LDFLAGS=--coverage make -C src proot care V=1 - - - name: Execute test suite - continue-on-error: true - timeout-minutes: 10 - run: | - build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} env ${{ matrix.SECCOMP == '0' && 'PROOT_NO_SECCOMP=1' || '' }} PATH=/bin:/usr/bin:/sbin:/usr/sbin:$PWD/src make -C test -j $(nproc) QUIET_LOG=$PWD/test.log - - - name: Output test log - if: always() - continue-on-error: true - run: ([ -f test.log ] && cat test.log) || true - - - name: Run sonar-scanner - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONARCLOUD_TOKEN }} - run: | - sonar-scanner --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" From 731daf2aa25eee640fc206268ae67dac73148eaa Mon Sep 17 00:00:00 2001 From: Dave Dykstra <2129743+DrDaveD@users.noreply.github.com> Date: Tue, 10 Mar 2026 22:53:40 -0500 Subject: [PATCH 09/12] use different xattr path such as on opensuse tumbleweed Signed-off-by: Dave Dykstra <2129743+DrDaveD@users.noreply.github.com> --- src/GNUmakefile | 2 ++ src/extension/fake_id0/fake_id0.c | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/src/GNUmakefile b/src/GNUmakefile index e19acd520..6dbb0a08e 100644 --- a/src/GNUmakefile +++ b/src/GNUmakefile @@ -26,6 +26,8 @@ CPPFLAGS += -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -I. -I$(VPATH) -I$(VPATH)/../li ifdef PERSISTENT_CHOWN CPPFLAGS += -DPERSISTENT_CHOWN CPPFLAGS += $(shell pkg-config --cflags libprotobuf-c) + HAS_ATTR_XATTR := $(shell if [ -f /usr/include/attr/xattr.h ]; then echo -DHAS_ATTR_XATTR; fi) + CPPFLAGS += ${HAS_ATTR_XATTR} endif CFLAGS += -g -Wall -Wextra -O2 CFLAGS += $(shell pkg-config --cflags talloc) diff --git a/src/extension/fake_id0/fake_id0.c b/src/extension/fake_id0/fake_id0.c index 32ef9849a..8de97d80e 100644 --- a/src/extension/fake_id0/fake_id0.c +++ b/src/extension/fake_id0/fake_id0.c @@ -46,7 +46,11 @@ #if defined(PERSISTENT_CHOWN) #include +#if defined(HAS_ATTR_XATTR) #include +#else +#include +#endif #include "path/path.h" #include "rootlesscontainers/rootlesscontainers.pb-c.h" #define XATTR_USER_ROOTLESSCONTAINERS "user.rootlesscontainers" From 6d2c3336880381dc43c8c09b8d46df988bde52ea Mon Sep 17 00:00:00 2001 From: Dave Dykstra <2129743+DrDaveD@users.noreply.github.com> Date: Fri, 22 May 2026 20:22:55 +0000 Subject: [PATCH 10/12] pass through exit code when child dies with a signal --- src/tracee/event.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/tracee/event.c b/src/tracee/event.c index ce59f0751..9f406ea0b 100644 --- a/src/tracee/event.c +++ b/src/tracee/event.c @@ -420,13 +420,17 @@ static int handle_tracee_event_kernel_4_8(Tracee *tracee, int tracee_status) signal = 0; if (WIFEXITED(tracee_status)) { - last_exit_status = WEXITSTATUS(tracee_status); + int exit_status = WEXITSTATUS(tracee_status); VERBOSE(tracee, 1, "vpid %" PRIu64 ": exited with status %d", - tracee->vpid, last_exit_status); + tracee->vpid, exit_status); terminate_tracee(tracee); + // Avoid overwriting a failure exit code with a success + if ((exit_status != 0) || (last_exit_status < 0)) + last_exit_status = exit_status; } else if (WIFSIGNALED(tracee_status)) { + last_exit_status = 128 + WTERMSIG(tracee_status); check_architecture(tracee); VERBOSE(tracee, 1, "vpid %" PRIu64 ": terminated with signal %d", @@ -649,13 +653,17 @@ int handle_tracee_event(Tracee *tracee, int tracee_status) signal = 0; if (WIFEXITED(tracee_status)) { - last_exit_status = WEXITSTATUS(tracee_status); + int exit_status = WEXITSTATUS(tracee_status); VERBOSE(tracee, 1, "vpid %" PRIu64 ": exited with status %d", - tracee->vpid, last_exit_status); + tracee->vpid, exit_status); terminate_tracee(tracee); + // Avoid overwriting a failure exit code with a success + if ((exit_status != 0) || (last_exit_status < 0)) + last_exit_status = exit_status; } else if (WIFSIGNALED(tracee_status)) { + last_exit_status = 128 + WTERMSIG(tracee_status); check_architecture(tracee); VERBOSE(tracee, 1, "vpid %" PRIu64 ": terminated with signal %d", From 9b04d2e5ef497b680bfb11031f2032e0d0cdd20b Mon Sep 17 00:00:00 2001 From: ben-auo <180770701+ben-auo@users.noreply.github.com> Date: Tue, 3 Nov 2026 21:02:01 -0700 Subject: [PATCH 11/12] include libgen.h for basename(3) when not using glibc musl only declares basename(3) in libgen.h, so cli.c fails to compile with an implicit declaration error. glibc is left unchanged, because its libgen.h replaces the GNU basename with the POSIX one. Assisted-by: LLM Signed-off-by: ben-auo <180770701+ben-auo@users.noreply.github.com> --- src/cli/cli.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cli/cli.c b/src/cli/cli.c index 4e79066f1..205d6e15d 100644 --- a/src/cli/cli.c +++ b/src/cli/cli.c @@ -24,6 +24,9 @@ #include /* bool, true, false, */ #include /* ARG_MAX, PATH_MAX, */ #include /* str*(3), basename(3), */ +#if !defined(__GLIBC__) +#include /* basename(3), */ +#endif #include /* talloc*, */ #include /* exit(3), EXIT_*, strtol(3), {g,s}etenv(3), */ #include /* assert(3), */ From 54a577364c5b4b4801797603651493f5907b8e11 Mon Sep 17 00:00:00 2001 From: Dave Dykstra <2129743+DrDaveD@users.noreply.github.com> Date: Wed, 4 Nov 2026 16:48:49 -0600 Subject: [PATCH 12/12] add protobuf-c dev packages for github actions Signed-off-by: Dave Dykstra <2129743+DrDaveD@users.noreply.github.com> --- .github/workflows/codeql.yml | 2 +- .github/workflows/pull-request.yml | 6 +++--- .github/workflows/release.yml | 2 +- test/docker/alpine/x86_64/Dockerfile | 1 + test/docker/centos/x86_64/Dockerfile | 1 + test/docker/debian/x86_64/Dockerfile | 1 + 6 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 5ccc408cd..3c97fb8ef 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -29,7 +29,7 @@ jobs: build-mode: manual - name: Install build dependencies - run: sudo apt-get update -qq && sudo apt-get install -qq libarchive-dev libtalloc-dev pkg-config swig uthash-dev python3-dev lzop + run: sudo apt-get update -qq && sudo apt-get install -qq libarchive-dev libprotobuf-c-dev libtalloc-dev pkg-config swig uthash-dev python3-dev lzop - name: Build run: make -C src clean loader.elf loader-m32.elf build.h proot care diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 9442c0013..82e562667 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -53,7 +53,7 @@ jobs: - name: Install build dependencies run: | sudo apt-get update -qq - sudo apt-get install -qq check libtalloc-dev pkg-config + sudo apt-get install -qq check libprotobuf-c-dev libtalloc-dev pkg-config - name: Run the libcheck suite run: make -C test/unit check @@ -77,7 +77,7 @@ jobs: - name: Install build dependencies run: | sudo apt-get update -qq - sudo apt-get install -qq bats clang-tools curl gdb lcov libarchive-dev libtalloc-dev pkg-config sloccount strace swig uthash-dev python3-dev lzop + sudo apt-get install -qq bats clang-tools curl gdb lcov libarchive-dev libprotobuf-c-dev libtalloc-dev pkg-config sloccount strace swig uthash-dev python3-dev lzop - name: Gather analytics run: sloccount --details . @@ -130,7 +130,7 @@ jobs: - name: Install cross toolchain and target libraries run: | sudo apt-get install -qq -y crossbuild-essential-arm64 pkg-config uthash-dev qemu-user \ - libarchive-dev:arm64 libtalloc-dev:arm64 + libarchive-dev:arm64 libprotobuf-c-dev:arm64 libtalloc-dev:arm64 - name: Cross-build proot and care for aarch64 run: | diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b3cceae62..dad22702d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -37,7 +37,7 @@ jobs: - name: Install build dependencies run: | sudo apt-get update -qq - sudo apt-get install -qq libarchive-dev libtalloc-dev pkg-config uthash-dev lzop g++ + sudo apt-get install -qq libarchive-dev libprotobuf-c-dev libtalloc-dev pkg-config uthash-dev lzop g++ - name: Build static proot and care binaries run: | diff --git a/test/docker/alpine/x86_64/Dockerfile b/test/docker/alpine/x86_64/Dockerfile index cec425e30..1a4c595e7 100644 --- a/test/docker/alpine/x86_64/Dockerfile +++ b/test/docker/alpine/x86_64/Dockerfile @@ -16,6 +16,7 @@ RUN apk add --no-cache \ make \ mcookie \ musl-dev \ + protobuf-c-dev \ py3-docutils \ python3-dev \ strace \ diff --git a/test/docker/centos/x86_64/Dockerfile b/test/docker/centos/x86_64/Dockerfile index 8e270b850..7815efa05 100644 --- a/test/docker/centos/x86_64/Dockerfile +++ b/test/docker/centos/x86_64/Dockerfile @@ -16,6 +16,7 @@ RUN dnf install -y \ lzop \ make \ pkg-config \ + protobuf-c-devel \ python3-devel \ strace \ swig \ diff --git a/test/docker/debian/x86_64/Dockerfile b/test/docker/debian/x86_64/Dockerfile index 671a9772a..249a46b8f 100644 --- a/test/docker/debian/x86_64/Dockerfile +++ b/test/docker/debian/x86_64/Dockerfile @@ -8,6 +8,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ docutils-common \ git \ libarchive-dev \ + libprotobuf-c-dev \ libtalloc-dev \ make \ pkg-config \