[invoker] Sandbox apps when requested. JB#54498 OMP#JOLLA-178

Forces use of generic booster when it detects that application should be
sandboxed but it is not launched via sailjail already and prepends
sailjail argument.

Skips freeing of calloc'ed array.

Signed-off-by: Tomi Leppänen <tomi.leppanen@jolla.com>
pull/1/head
Tomi Leppänen 4 years ago
parent 479435fb1e
commit 4ec490169e

@ -3,12 +3,13 @@ set(COMMON "${CMAKE_HOME_DIRECTORY}/src/common")
# Find dbus
include(FindPkgConfig)
pkg_check_modules(DBUS dbus-1 REQUIRED)
pkg_check_modules(GLIB glib-2.0 REQUIRED)
# Set sources
set(SRC invokelib.c invoker.c ${COMMON}/report.c search.c)
set(SRC invokelib.c invoker.c ${COMMON}/report.c search.c ${COMMON}/sailjail.c)
# Set include dirs
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${DBUS_INCLUDE_DIRS} ${COMMON})
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${DBUS_INCLUDE_DIRS} ${GLIB_INCLUDE_DIRS} ${COMMON})
# Set precompiler flags
add_definitions(-DPROG_NAME_INVOKER="invoker")
@ -16,7 +17,7 @@ add_definitions(-DPROG_NAME_INVOKER="invoker")
# Set target
add_executable(invoker ${SRC})
target_link_libraries(invoker ${DBUS_LDFLAGS})
target_link_libraries(invoker ${DBUS_LDFLAGS} ${GLIB_LDFLAGS})
# Add install rule
install(TARGETS invoker DESTINATION ${CMAKE_INSTALL_FULL_BINDIR})

@ -48,6 +48,7 @@
#include "protocol.h"
#include "invokelib.h"
#include "search.h"
#include "sailjail.h"
#define BOOSTER_SESSION "silica-session"
#define BOOSTER_GENERIC "generic"
@ -627,7 +628,7 @@ static unsigned int get_delay(char *delay_arg, char *param_name,
return delay;
}
static void notify_app_lauch(const char *desktop_file)
static void notify_app_launch(const char *desktop_file)
{
DBusConnection *connection;
DBusMessage *message;
@ -651,6 +652,14 @@ static void notify_app_lauch(const char *desktop_file)
}
}
static bool ask_for_sandboxing(const char *app)
{
char *path = strdup(app);
bool ret_val = sailjail_sandbox(basename(path));
free(path);
return ret_val;
}
static int wait_for_launched_process_to_exit(int socket_fd)
{
int exit_status = EXIT_FAILURE;
@ -790,7 +799,7 @@ static int invoke_remote(int socket_fd, const InvokeArgs *args)
invoker_send_end(socket_fd);
if (args->desktop_file)
notify_app_lauch(args->desktop_file);
notify_app_launch(args->desktop_file);
if (args->wait_term) {
exit_status = wait_for_launched_process_to_exit(socket_fd),
@ -1080,6 +1089,25 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
// If arguments don't define sailjail and sailjaild says the app must be sandboxed,
// we force sandboxing here
if (strcmp(args.prog_name, SAILJAIL_PATH) && ask_for_sandboxing(args.prog_name)) {
// We must use generic booster here as nothing else would work
// to run sailjail which is not compiled for launching via booster
args.app_type = BOOSTER_GENERIC;
// Prepend sailjail
char **old_argv = args.prog_argv;
args.prog_argc += 2;
args.prog_argv = (char **)calloc(args.prog_argc + 1, sizeof *args.prog_argv);
args.prog_argv[0] = SAILJAIL_PATH;
args.prog_argv[1] = "--";
for (int i = 2; i < args.prog_argc + 1; ++i)
args.prog_argv[i] = old_argv[i-2];
// Don't free old_argv because it's probably not dynamically allocated
free(args.prog_name);
args.prog_name = strdup(SAILJAIL_PATH);
}
// Send commands to the launcher daemon
info("Invoking execution: '%s'\n", args.prog_name);
int ret_val = invoke(&args);

Loading…
Cancel
Save