From 33f7f28798bae58fbdf7b2437cdc7cb4e0ee96ab Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Mon, 13 May 2019 20:26:30 -0400 Subject: [PATCH] kernel & runtime_loader: Don't load from non-packaged when "Disable user add-ons" is set. Confirmed to fix #14361. It is finally possible to un-brick an install with a bad system library in non-packaged without having to use another install to do so. Change-Id: Iafea7821f02cb34e77c766b1f97d1c19206b1081 Reviewed-on: https://review.haiku-os.org/c/1452 Reviewed-by: Adrien Destugues --- headers/private/system/user_runtime.h | 1 + src/system/kernel/team.cpp | 8 +++++++ src/system/runtime_loader/runtime_loader.cpp | 23 ++++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/headers/private/system/user_runtime.h b/headers/private/system/user_runtime.h index 9bd6d1712c..9110ed2189 100644 --- a/headers/private/system/user_runtime.h +++ b/headers/private/system/user_runtime.h @@ -29,6 +29,7 @@ struct user_space_program_args { char **args; char **env; mode_t umask; // (mode_t)-1 means not set + bool disable_user_addons; }; #endif /* KERNEL_USER_RUNTIME_H_ */ diff --git a/src/system/kernel/team.cpp b/src/system/kernel/team.cpp index 3a1f918403..15cb73f653 100644 --- a/src/system/kernel/team.cpp +++ b/src/system/kernel/team.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -151,6 +152,7 @@ static ProcessGroupHashTable sGroupHash; static spinlock sGroupHashLock = B_SPINLOCK_INITIALIZER; static Team* sKernelTeam = NULL; +static bool sDisableUserAddOns = false; // A list of process groups of children of dying session leaders that need to // be signalled, if they have become orphaned and contain stopped processes. @@ -1575,6 +1577,8 @@ team_create_thread_start_internal(void* args) || user_memcpy(&programArgs->error_token, &teamArgs->error_token, sizeof(uint32)) < B_OK || user_memcpy(&programArgs->umask, &teamArgs->umask, sizeof(mode_t)) < B_OK + || user_memcpy(&programArgs->disable_user_addons, + &sDisableUserAddOns, sizeof(bool)) < B_OK || user_memcpy(userArgs, teamArgs->flat_args, teamArgs->flat_args_size) < B_OK) { // the team deletion process will clean this mess @@ -2835,6 +2839,10 @@ team_init(kernel_args* args) // stick it in the team hash sTeamHash.Insert(sKernelTeam); + // check safe mode settings + sDisableUserAddOns = get_safemode_boolean(B_SAFEMODE_DISABLE_USER_ADD_ONS, + false); + add_debugger_command_etc("team", &dump_team_info, "Dump info about a particular team", "[ |
| ]\n" diff --git a/src/system/runtime_loader/runtime_loader.cpp b/src/system/runtime_loader/runtime_loader.cpp index b71a6dfc50..22abe2d945 100644 --- a/src/system/runtime_loader/runtime_loader.cpp +++ b/src/system/runtime_loader/runtime_loader.cpp @@ -47,6 +47,29 @@ search_path_for_type(image_type type) { const char *path = NULL; + // If "user add-ons" are disabled via safemode settings, we bypass the + // environment and defaults and return a different set of paths without + // the user or non-packaged ones. + if (gProgramArgs->disable_user_addons) { + switch (type) { + case B_APP_IMAGE: + return kGlobalBinDirectory + ":" kSystemAppsDirectory + ":" kSystemPreferencesDirectory; + + case B_LIBRARY_IMAGE: + return kAppLocalLibDirectory + ":" kSystemLibDirectory; + + case B_ADD_ON_IMAGE: + return kAppLocalAddonsDirectory + ":" kSystemAddonsDirectory; + + default: + return NULL; + } + } + // TODO: The *PATH variables should not include the standard system paths. // Instead those paths should always be used after the directories specified // via the variables.