From 0538ba3d59a1a29adcee0b4656b204fda102ad89 Mon Sep 17 00:00:00 2001 From: Marcin Bukat Date: Fri, 2 Mar 2018 21:45:52 +0100 Subject: Agptek Rocker: Restrict root directory to SD only Actual / of underlying linux OS should not be available to user. I am still not sure if implementation is correct. It doesn't perform any relative path sandboxing for example. Change-Id: Ic577a10f3947f6e950e2c4d03173f9f207395eb7 --- firmware/target/hosted/filesystem-app.c | 8 ++++++++ firmware/target/hosted/lc-unix.c | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'firmware/target/hosted') diff --git a/firmware/target/hosted/filesystem-app.c b/firmware/target/hosted/filesystem-app.c index 4f1019c7a1..d9fcd64e2d 100644 --- a/firmware/target/hosted/filesystem-app.c +++ b/firmware/target/hosted/filesystem-app.c @@ -37,6 +37,10 @@ #include "logf.h" +#if defined(AGPTEK_ROCKER) && !defined(BOOTLOADER) +#define PIVOT_ROOT "/mnt/sd_0" +#endif + #if (CONFIG_PLATFORM & PLATFORM_ANDROID) static const char rbhome[] = "/sdcard"; #elif (CONFIG_PLATFORM & (PLATFORM_SDL|PLATFORM_MAEMO|PLATFORM_PANDORA)) \ @@ -205,6 +209,10 @@ const char * handle_special_dirs(const char *dir, unsigned flags, #endif #ifdef HAVE_MULTIDRIVE dir = handle_special_links(dir, flags, buf, bufsize); +#endif +#ifdef PIVOT_ROOT + snprintf(buf, bufsize, "%s/%s", PIVOT_ROOT, dir); + dir = buf; #endif return dir; } diff --git a/firmware/target/hosted/lc-unix.c b/firmware/target/hosted/lc-unix.c index 810dc9f92c..1061883832 100644 --- a/firmware/target/hosted/lc-unix.c +++ b/firmware/target/hosted/lc-unix.c @@ -21,6 +21,7 @@ #include /* size_t */ #include +#include "file.h" #include "debug.h" #include "load_code.h" @@ -28,7 +29,11 @@ void *lc_open(const char *filename, unsigned char *buf, size_t buf_size) { (void)buf; (void)buf_size; - void *handle = dlopen(filename, RTLD_NOW); + char path[MAX_PATH]; + + const char *fpath = handle_special_dirs(filename, 0, path, sizeof(path)); + + void *handle = dlopen(fpath, RTLD_NOW); if (handle == NULL) { DEBUGF("failed to load %s\n", filename); -- cgit