Copying debug ramdisk files to /debug_ramdisk/*
In previous implementation, userdebug sepoilcy and property files are loaded from the system.img. This CL changes this to: - first-stage init copies userdebug files from ramdisk to /debug_ramisk/* - second-stage init loads files from /debug_ramdisk/*. Note: same as before, the above can only be triggered, if the device is UNLOCKED With this, we don't have to put userdebug related files into the USER system.img. Bug: 126493225 Test: boot device with a ramdisk with /force_debuggable, checks related files are loaded Change-Id: I63f5f846e82ba78427062bf7615c26173878d8f3
This commit is contained in:
parent
fc1749280c
commit
30afda71c0
8 changed files with 58 additions and 9 deletions
|
@ -61,6 +61,7 @@ cc_defaults {
|
|||
static_libs: [
|
||||
"libseccomp_policy",
|
||||
"libavb",
|
||||
"libc++fs",
|
||||
"libcgrouprc_format",
|
||||
"libprotobuf-cpp-lite",
|
||||
"libpropertyinfoserializer",
|
||||
|
|
|
@ -68,12 +68,14 @@ LOCAL_UNSTRIPPED_PATH := $(TARGET_RAMDISK_OUT_UNSTRIPPED)
|
|||
# Set up the same mount points on the ramdisk that system-as-root contains.
|
||||
LOCAL_POST_INSTALL_CMD := mkdir -p \
|
||||
$(TARGET_RAMDISK_OUT)/apex \
|
||||
$(TARGET_RAMDISK_OUT)/debug_ramdisk \
|
||||
$(TARGET_RAMDISK_OUT)/dev \
|
||||
$(TARGET_RAMDISK_OUT)/mnt \
|
||||
$(TARGET_RAMDISK_OUT)/proc \
|
||||
$(TARGET_RAMDISK_OUT)/sys \
|
||||
|
||||
LOCAL_STATIC_LIBRARIES := \
|
||||
libc++fs \
|
||||
libfs_avb \
|
||||
libfs_mgr \
|
||||
libfec \
|
||||
|
|
26
init/debug_ramdisk.h
Normal file
26
init/debug_ramdisk.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace android {
|
||||
namespace init {
|
||||
|
||||
constexpr const char kDebugRamdiskProp[] = "/debug_ramdisk/adb_debug.prop";
|
||||
constexpr const char kDebugRamdiskSEPolicy[] = "/debug_ramdisk/userdebug_plat_sepolicy.cil";
|
||||
|
||||
} // namespace init
|
||||
} // namespace android
|
|
@ -26,6 +26,7 @@
|
|||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
@ -35,6 +36,7 @@
|
|||
#include <cutils/android_reboot.h>
|
||||
#include <private/android_filesystem_config.h>
|
||||
|
||||
#include "debug_ramdisk.h"
|
||||
#include "first_stage_mount.h"
|
||||
#include "reboot_utils.h"
|
||||
#include "switch_root.h"
|
||||
|
@ -44,6 +46,8 @@ using android::base::boot_clock;
|
|||
|
||||
using namespace std::literals;
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace android {
|
||||
namespace init {
|
||||
|
||||
|
@ -159,6 +163,9 @@ int FirstStageMain(int argc, char** argv) {
|
|||
CHECKCALL(mount("tmpfs", "/apex", "tmpfs", MS_NOEXEC | MS_NOSUID | MS_NODEV,
|
||||
"mode=0755,uid=0,gid=0"));
|
||||
|
||||
// /debug_ramdisk is used to preserve additional files from the debug ramdisk
|
||||
CHECKCALL(mount("tmpfs", "/debug_ramdisk", "tmpfs", MS_NOEXEC | MS_NOSUID | MS_NODEV,
|
||||
"mode=0755,uid=0,gid=0"));
|
||||
#undef CHECKCALL
|
||||
|
||||
// Now that tmpfs is mounted on /dev and we have /dev/kmsg, we can actually
|
||||
|
@ -202,7 +209,14 @@ int FirstStageMain(int argc, char** argv) {
|
|||
// If this file is present, the second-stage init will use a userdebug sepolicy
|
||||
// and load adb_debug.prop to allow adb root, if the device is unlocked.
|
||||
if (access("/force_debuggable", F_OK) == 0) {
|
||||
setenv("INIT_FORCE_DEBUGGABLE", "true", 1);
|
||||
std::error_code ec; // to invoke the overloaded copy_file() that won't throw.
|
||||
if (!fs::copy_file("/adb_debug.prop", kDebugRamdiskProp, ec) ||
|
||||
!fs::copy_file("/userdebug_plat_sepolicy.cil", kDebugRamdiskSEPolicy, ec)) {
|
||||
LOG(ERROR) << "Failed to setup debug ramdisk";
|
||||
} else {
|
||||
// setenv for second-stage init to read above kDebugRamdisk* files.
|
||||
setenv("INIT_FORCE_DEBUGGABLE", "true", 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (!DoFirstStageMount()) {
|
||||
|
|
|
@ -621,6 +621,12 @@ static void GlobalSeccomp() {
|
|||
});
|
||||
}
|
||||
|
||||
static void UmountDebugRamdisk() {
|
||||
if (umount("/debug_ramdisk") != 0) {
|
||||
LOG(ERROR) << "Failed to umount /debug_ramdisk";
|
||||
}
|
||||
}
|
||||
|
||||
int SecondStageMain(int argc, char** argv) {
|
||||
if (REBOOT_BOOTLOADER_ON_PANIC) {
|
||||
InstallRebootSignalHandlers();
|
||||
|
@ -685,6 +691,7 @@ int SecondStageMain(int argc, char** argv) {
|
|||
InstallSignalFdHandler(&epoll);
|
||||
|
||||
property_load_boot_defaults(load_debug_prop);
|
||||
UmountDebugRamdisk();
|
||||
fs_mgr_vendor_overlay_mount_all();
|
||||
export_oem_lock_status();
|
||||
StartPropertyService(&epoll);
|
||||
|
|
|
@ -56,6 +56,7 @@
|
|||
#include <selinux/label.h>
|
||||
#include <selinux/selinux.h>
|
||||
|
||||
#include "debug_ramdisk.h"
|
||||
#include "epoll.h"
|
||||
#include "init.h"
|
||||
#include "persistent_properties.h"
|
||||
|
@ -887,9 +888,8 @@ void property_load_boot_defaults(bool load_debug_prop) {
|
|||
load_properties_from_file("/factory/factory.prop", "ro.*", &properties);
|
||||
|
||||
if (load_debug_prop) {
|
||||
constexpr static const char kAdbDebugProp[] = "/system/etc/adb_debug.prop";
|
||||
LOG(INFO) << "Loading " << kAdbDebugProp;
|
||||
load_properties_from_file(kAdbDebugProp, nullptr, &properties);
|
||||
LOG(INFO) << "Loading " << kDebugRamdiskProp;
|
||||
load_properties_from_file(kDebugRamdiskProp, nullptr, &properties);
|
||||
}
|
||||
|
||||
for (const auto& [name, value] : properties) {
|
||||
|
|
|
@ -64,6 +64,7 @@
|
|||
#include <fs_avb/fs_avb.h>
|
||||
#include <selinux/android.h>
|
||||
|
||||
#include "debug_ramdisk.h"
|
||||
#include "reboot_utils.h"
|
||||
#include "util.h"
|
||||
|
||||
|
@ -271,8 +272,6 @@ bool GetVendorMappingVersion(std::string* plat_vers) {
|
|||
}
|
||||
|
||||
constexpr const char plat_policy_cil_file[] = "/system/etc/selinux/plat_sepolicy.cil";
|
||||
constexpr const char userdebug_plat_policy_cil_file[] =
|
||||
"/system/etc/selinux/userdebug_plat_sepolicy.cil";
|
||||
|
||||
bool IsSplitPolicyDevice() {
|
||||
return access(plat_policy_cil_file, R_OK) != -1;
|
||||
|
@ -292,7 +291,7 @@ bool LoadSplitPolicy() {
|
|||
const char* force_debuggable_env = getenv("INIT_FORCE_DEBUGGABLE");
|
||||
bool use_userdebug_policy =
|
||||
((force_debuggable_env && "true"s == force_debuggable_env) &&
|
||||
AvbHandle::IsDeviceUnlocked() && access(userdebug_plat_policy_cil_file, F_OK) == 0);
|
||||
AvbHandle::IsDeviceUnlocked() && access(kDebugRamdiskSEPolicy, F_OK) == 0);
|
||||
if (use_userdebug_policy) {
|
||||
LOG(WARNING) << "Using userdebug system sepolicy";
|
||||
}
|
||||
|
@ -367,7 +366,7 @@ bool LoadSplitPolicy() {
|
|||
// clang-format off
|
||||
std::vector<const char*> compile_args {
|
||||
"/system/bin/secilc",
|
||||
use_userdebug_policy ? userdebug_plat_policy_cil_file : plat_policy_cil_file,
|
||||
use_userdebug_policy ? kDebugRamdiskSEPolicy: plat_policy_cil_file,
|
||||
"-m", "-M", "true", "-G", "-N",
|
||||
"-c", version_as_string.c_str(),
|
||||
plat_mapping_file.c_str(),
|
||||
|
|
|
@ -97,7 +97,7 @@ endif
|
|||
#
|
||||
# create some directories (some are mount points) and symlinks
|
||||
LOCAL_POST_INSTALL_CMD := mkdir -p $(addprefix $(TARGET_ROOT_OUT)/, \
|
||||
dev proc sys system data odm oem acct config storage mnt apex $(BOARD_ROOT_EXTRA_FOLDERS)); \
|
||||
dev proc sys system data odm oem acct config storage mnt apex debug_ramdisk $(BOARD_ROOT_EXTRA_FOLDERS)); \
|
||||
ln -sf /system/bin $(TARGET_ROOT_OUT)/bin; \
|
||||
ln -sf /system/etc $(TARGET_ROOT_OUT)/etc; \
|
||||
ln -sf /data/user_de/0/com.android.shell/files/bugreports $(TARGET_ROOT_OUT)/bugreports; \
|
||||
|
|
Loading…
Reference in a new issue