Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit da1251d6 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge changes from topic "adb_root_in_user"

* changes:
  Allow overriding ro.debuggable to 1 on USER builds
  adbd: allowing adb root when the device is unlocked
parents 9d3310c0 1dacd42a
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ cc_defaults {
        "-Wthread-safety",
        "-Wvla",
        "-DADB_HOST=1",         // overridden by adbd_defaults
        "-DALLOW_ADBD_ROOT=0",  // overridden by adbd_defaults
    ],
    cpp_std: "experimental",

@@ -79,7 +80,8 @@ cc_defaults {
    product_variables: {
        debuggable: {
            cflags: [
                "-DALLOW_ADBD_ROOT",
                "-UALLOW_ADBD_ROOT",
                "-DALLOW_ADBD_ROOT=1",
                "-DALLOW_ADBD_DISABLE_VERITY",
                "-DALLOW_ADBD_NO_AUTH",
            ],
+15 −8
Original line number Diff line number Diff line
@@ -58,17 +58,23 @@
#if defined(__ANDROID__)
static const char* root_seclabel = nullptr;

static inline bool is_device_unlocked() {
    return "orange" == android::base::GetProperty("ro.boot.verifiedbootstate", "");
}

static bool should_drop_capabilities_bounding_set() {
#if defined(ALLOW_ADBD_ROOT)
    if (ALLOW_ADBD_ROOT || is_device_unlocked()) {
        if (__android_log_is_debuggable()) {
            return false;
        }
#endif
    }
    return true;
}

static bool should_drop_privileges() {
#if defined(ALLOW_ADBD_ROOT)
    // "adb root" not allowed, always drop privileges.
    if (!ALLOW_ADBD_ROOT && !is_device_unlocked()) return true;

    // The properties that affect `adb root` and `adb unroot` are ro.secure and
    // ro.debuggable. In this context the names don't make the expected behavior
    // particularly obvious.
@@ -98,9 +104,6 @@ static bool should_drop_privileges() {
    }

    return drop;
#else
    return true; // "adb root" not allowed, always drop privileges.
#endif // ALLOW_ADBD_ROOT
}

static void drop_privileges(int server_port) {
@@ -205,6 +208,10 @@ int adbd_main(int server_port) {
#if defined(ALLOW_ADBD_NO_AUTH)
    // If ro.adb.secure is unset, default to no authentication required.
    auth_required = android::base::GetBoolProperty("ro.adb.secure", false);
#elif defined(__ANDROID__)
    if (is_device_unlocked()) {  // allows no authentication when the device is unlocked.
        auth_required = android::base::GetBoolProperty("ro.adb.secure", false);
    }
#endif

    adbd_auth_init();
+6 −0
Original line number Diff line number Diff line
@@ -199,6 +199,12 @@ int FirstStageMain(int argc, char** argv) {
        SwitchRoot("/first_stage_ramdisk");
    }

    // 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);
    }

    if (!DoFirstStageMount()) {
        LOG(FATAL) << "Failed to mount required partitions early ...";
    }
+11 −1
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@
#include <android-base/stringprintf.h>
#include <android-base/strings.h>
#include <cutils/android_reboot.h>
#include <fs_avb/fs_avb.h>
#include <fs_mgr_vendor_overlay.h>
#include <keyutils.h>
#include <libavb/libavb.h>
@@ -74,6 +75,7 @@ using android::base::ReadFileToString;
using android::base::StringPrintf;
using android::base::Timer;
using android::base::Trim;
using android::fs_mgr::AvbHandle;

namespace android {
namespace init {
@@ -92,6 +94,7 @@ static std::string wait_prop_value;
static bool shutting_down;
static std::string shutdown_command;
static bool do_shutdown = false;
static bool load_debug_prop = false;

std::vector<std::string> late_import_paths;

@@ -655,10 +658,17 @@ int SecondStageMain(int argc, char** argv) {
    const char* avb_version = getenv("INIT_AVB_VERSION");
    if (avb_version) property_set("ro.boot.avb_version", avb_version);

    // See if need to load debug props to allow adb root, when the device is unlocked.
    const char* force_debuggable_env = getenv("INIT_FORCE_DEBUGGABLE");
    if (force_debuggable_env && AvbHandle::IsDeviceUnlocked()) {
        load_debug_prop = "true"s == force_debuggable_env;
    }

    // Clean up our environment.
    unsetenv("INIT_STARTED_AT");
    unsetenv("INIT_SELINUX_TOOK");
    unsetenv("INIT_AVB_VERSION");
    unsetenv("INIT_FORCE_DEBUGGABLE");

    // Now set up SELinux for second stage.
    SelinuxSetupKernelLogging();
@@ -672,7 +682,7 @@ int SecondStageMain(int argc, char** argv) {

    InstallSignalFdHandler(&epoll);

    property_load_boot_defaults();
    property_load_boot_defaults(load_debug_prop);
    fs_mgr_vendor_overlay_mount_all();
    export_oem_lock_status();
    StartPropertyService(&epoll);
+7 −1
Original line number Diff line number Diff line
@@ -866,7 +866,7 @@ static void property_derive_build_fingerprint() {
    }
}

void property_load_boot_defaults() {
void property_load_boot_defaults(bool load_debug_prop) {
    // TODO(b/117892318): merge prop.default and build.prop files into one
    // We read the properties and their values into a map, in order to always allow properties
    // loaded in the later property files to override the properties in loaded in the earlier
@@ -888,6 +888,12 @@ void property_load_boot_defaults() {
    load_properties_from_file("/product_services/build.prop", nullptr, &properties);
    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);
    }

    for (const auto& [name, value] : properties) {
        std::string error;
        if (PropertySet(name, value, &error) != PROP_SUCCESS) {
Loading