init: handle more bootconfig parameters am: 79058486d2

Original change: https://android-review.googlesource.com/c/platform/system/core/+/1615298

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I3a7250bb7c6a7694eb2431d31d9f104721a9507b
This commit is contained in:
Devin Moore 2021-03-08 18:44:30 +00:00 committed by Automerger Merge Worker
commit 786355f304
3 changed files with 23 additions and 8 deletions

View file

@ -105,8 +105,20 @@ void StartConsole(const std::string& cmdline) {
_exit(127); _exit(127);
} }
int FirstStageConsole(const std::string& cmdline) { int FirstStageConsole(const std::string& cmdline, const std::string& bootconfig) {
auto pos = cmdline.find("androidboot.first_stage_console="); auto pos = bootconfig.find("androidboot.first_stage_console =");
if (pos != std::string::npos) {
int val = 0;
if (sscanf(bootconfig.c_str() + pos, "androidboot.first_stage_console = \"%d\"", &val) !=
1) {
return FirstStageConsoleParam::DISABLED;
}
if (val <= FirstStageConsoleParam::MAX_PARAM_VALUE && val >= 0) {
return val;
}
}
pos = cmdline.find("androidboot.first_stage_console=");
if (pos != std::string::npos) { if (pos != std::string::npos) {
int val = 0; int val = 0;
if (sscanf(cmdline.c_str() + pos, "androidboot.first_stage_console=%d", &val) != 1) { if (sscanf(cmdline.c_str() + pos, "androidboot.first_stage_console=%d", &val) != 1) {

View file

@ -29,7 +29,7 @@ enum FirstStageConsoleParam {
}; };
void StartConsole(const std::string& cmdline); void StartConsole(const std::string& cmdline);
int FirstStageConsole(const std::string& cmdline); int FirstStageConsole(const std::string& cmdline, const std::string& bootconfig);
} // namespace init } // namespace init
} // namespace android } // namespace android

View file

@ -102,8 +102,9 @@ void FreeRamdisk(DIR* dir, dev_t dev) {
} }
} }
bool ForceNormalBoot(const std::string& cmdline) { bool ForceNormalBoot(const std::string& cmdline, const std::string& bootconfig) {
return cmdline.find("androidboot.force_normal_boot=1") != std::string::npos; return bootconfig.find("androidboot.force_normal_boot = \"1\"") != std::string::npos ||
cmdline.find("androidboot.force_normal_boot=1") != std::string::npos;
} }
} // namespace } // namespace
@ -211,6 +212,8 @@ int FirstStageMain(int argc, char** argv) {
android::base::ReadFileToString("/proc/cmdline", &cmdline); android::base::ReadFileToString("/proc/cmdline", &cmdline);
// Don't expose the raw bootconfig to unprivileged processes. // Don't expose the raw bootconfig to unprivileged processes.
chmod("/proc/bootconfig", 0440); chmod("/proc/bootconfig", 0440);
std::string bootconfig;
android::base::ReadFileToString("/proc/bootconfig", &bootconfig);
gid_t groups[] = {AID_READPROC}; gid_t groups[] = {AID_READPROC};
CHECKCALL(setgroups(arraysize(groups), groups)); CHECKCALL(setgroups(arraysize(groups), groups));
CHECKCALL(mount("sysfs", "/sys", "sysfs", 0, NULL)); CHECKCALL(mount("sysfs", "/sys", "sysfs", 0, NULL));
@ -278,11 +281,11 @@ int FirstStageMain(int argc, char** argv) {
old_root_dir.reset(); old_root_dir.reset();
} }
auto want_console = ALLOW_FIRST_STAGE_CONSOLE ? FirstStageConsole(cmdline) : 0; auto want_console = ALLOW_FIRST_STAGE_CONSOLE ? FirstStageConsole(cmdline, bootconfig) : 0;
boot_clock::time_point module_start_time = boot_clock::now(); boot_clock::time_point module_start_time = boot_clock::now();
int module_count = 0; int module_count = 0;
if (!LoadKernelModules(IsRecoveryMode() && !ForceNormalBoot(cmdline), want_console, if (!LoadKernelModules(IsRecoveryMode() && !ForceNormalBoot(cmdline, bootconfig), want_console,
module_count)) { module_count)) {
if (want_console != FirstStageConsoleParam::DISABLED) { if (want_console != FirstStageConsoleParam::DISABLED) {
LOG(ERROR) << "Failed to load kernel modules, starting console"; LOG(ERROR) << "Failed to load kernel modules, starting console";
@ -324,7 +327,7 @@ int FirstStageMain(int argc, char** argv) {
LOG(INFO) << "Copied ramdisk prop to " << dest; LOG(INFO) << "Copied ramdisk prop to " << dest;
} }
if (ForceNormalBoot(cmdline)) { if (ForceNormalBoot(cmdline, bootconfig)) {
mkdir("/first_stage_ramdisk", 0755); mkdir("/first_stage_ramdisk", 0755);
// SwitchRoot() must be called with a mount point as the target, so we bind mount the // SwitchRoot() must be called with a mount point as the target, so we bind mount the
// target directory to itself here. // target directory to itself here.