From ce6fea7a2395c9a6fe84f1c5c49d933ec83325fb Mon Sep 17 00:00:00 2001 From: Martin Franc Date: Sat, 6 Feb 2021 13:00:28 +0100 Subject: [PATCH] Prevent wob from doing fstat syscall in pledged environment fixes #62 --- main.c | 12 ++++++++++++ pledge_seccomp.c | 1 - 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index a7c47be..957ec8b 100644 --- a/main.c +++ b/main.c @@ -20,6 +20,8 @@ #define MIN(a, b) (((a) < (b)) ? (a) : (b)) +#define STDIN_BUFFER_LENGTH INPUT_BUFFER_LENGTH + #define _POSIX_C_SOURCE 200809L #include #include @@ -469,12 +471,22 @@ wob_draw_percentage(const struct wob_geom *geom, uint32_t *argb, struct wob_colo } } +static char stdin_buffer[STDIN_BUFFER_LENGTH]; + int main(int argc, char **argv) { wob_log_use_colors(isatty(STDERR_FILENO)); wob_log_level_warn(); + // libc is doing fstat syscall to determine the optimal buffer size and that can be problematic to wob_pledge() + // to solve this problem we can just pass the optimal buffer ourselves + if (setvbuf(stdin, stdin_buffer, _IOFBF, sizeof(stdin_buffer)) != 0) { + wob_log_error("Failed to set stdin buffer size to %zu", sizeof(stdin_buffer)); + + return EXIT_FAILURE; + } + const char *usage = "Usage: wob [options]\n" "\n" diff --git a/pledge_seccomp.c b/pledge_seccomp.c index 0746618..745f322 100644 --- a/pledge_seccomp.c +++ b/pledge_seccomp.c @@ -21,7 +21,6 @@ wob_pledge(void) SCMP_SYS(exit), SCMP_SYS(exit_group), SCMP_SYS(fcntl), - SCMP_SYS(fstat), SCMP_SYS(gettimeofday), SCMP_SYS(poll), SCMP_SYS(ppoll),