From c0b0b10d62c33109877b778d4e0f1cc777743913 Mon Sep 17 00:00:00 2001 From: Jooyung Han Date: Wed, 16 Oct 2019 22:35:01 +0000 Subject: [PATCH 01/15] Revert "Use com.android.vndk.current variant for vndk list" This reverts commit 82f94d61cb544ff23b5c46811ab7af2aca0b66c0. Reason for revert: some targets are broken Bug: 142773030 Change-Id: Ida59c52af3d2fd694855fcee60b5bb0d99c85f8d (cherry picked from commit 08f2376d70500adb5256c11e2a2143d9e5e53d8e) --- rootdir/Android.mk | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rootdir/Android.mk b/rootdir/Android.mk index 52417305f..e1bb02fc6 100644 --- a/rootdir/Android.mk +++ b/rootdir/Android.mk @@ -326,7 +326,7 @@ LOCAL_MODULE_CLASS := ETC LOCAL_MODULE_PATH := $(TARGET_OUT_ETC) LOCAL_MODULE_STEM := $(call append_vndk_version,$(LOCAL_MODULE)) include $(BUILD_SYSTEM)/base_rules.mk -$(LOCAL_BUILT_MODULE): PRIVATE_VNDK_SAMEPROCESS_LIBRARIES := $(call module-installed-files-or-guess,$(VNDK_SAMEPROCESS_LIBRARIES),.com.android.vndk.current) +$(LOCAL_BUILT_MODULE): PRIVATE_VNDK_SAMEPROCESS_LIBRARIES := $(call module-installed-files-or-guess,$(VNDK_SAMEPROCESS_LIBRARIES),.vendor) $(LOCAL_BUILT_MODULE): @echo "Generate: $@" @mkdir -p $(dir $@) @@ -342,7 +342,7 @@ LOCAL_MODULE_CLASS := ETC LOCAL_MODULE_PATH := $(TARGET_OUT_ETC) LOCAL_MODULE_STEM := $(call append_vndk_version,$(LOCAL_MODULE)) include $(BUILD_SYSTEM)/base_rules.mk -$(LOCAL_BUILT_MODULE): PRIVATE_VNDK_CORE_LIBRARIES := $(call module-installed-files-or-guess,$(VNDK_CORE_LIBRARIES),.com.android.vndk.current) +$(LOCAL_BUILT_MODULE): PRIVATE_VNDK_CORE_LIBRARIES := $(call module-installed-files-or-guess,$(VNDK_CORE_LIBRARIES),.vendor) $(LOCAL_BUILT_MODULE): @echo "Generate: $@" @mkdir -p $(dir $@) @@ -358,7 +358,7 @@ LOCAL_MODULE_CLASS := ETC LOCAL_MODULE_PATH := $(TARGET_OUT_ETC) LOCAL_MODULE_STEM := $(call append_vndk_version,$(LOCAL_MODULE)) include $(BUILD_SYSTEM)/base_rules.mk -$(LOCAL_BUILT_MODULE): PRIVATE_VNDK_PRIVATE_LIBRARIES := $(call module-installed-files-or-guess,$(VNDK_PRIVATE_LIBRARIES),.com.android.vndk.current) +$(LOCAL_BUILT_MODULE): PRIVATE_VNDK_PRIVATE_LIBRARIES := $(call module-installed-files-or-guess,$(VNDK_PRIVATE_LIBRARIES),.vendor) $(LOCAL_BUILT_MODULE): @echo "Generate: $@" @mkdir -p $(dir $@) From bcc9803be55788df7163420d32ba001376f4bbaf Mon Sep 17 00:00:00 2001 From: Tom Cherry Date: Fri, 31 Jan 2020 09:03:05 -0800 Subject: [PATCH 02/15] libbase: Have LogdLogger use LOGGER_ENTRY_MAX_PAYLOAD for its buffer LogdLogger has its own buffer for adding the file and line number to FATAL messages, but it is much lower than LOGGER_ENTRY_MAX_PAYLOAD and that causes problems now that more logs are piped through this logger, so increase the limit to maximum. Also, in the case that the file and line number are not added, simply pass the buffer through to liblog, since there is no reason to copy to a separate buffer. Bug: 148678509 Test: build, unit tests Change-Id: I064aa34641e784dca6c529c51cb192069821d64a (cherry picked from commit 42ee2e4f8fc2c7e42214c981853db3c7ebbb5128) --- base/logging.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/base/logging.cpp b/base/logging.cpp index a8687067a..f42b9966b 100644 --- a/base/logging.cpp +++ b/base/logging.cpp @@ -340,18 +340,18 @@ void LogdLogger::operator()(LogId id, LogSeverity severity, const char* tag, int lg_id = LogIdTolog_id_t(id); - char log_message[1024]; + char log_message_with_file[4068]; // LOGGER_ENTRY_MAX_PAYLOAD, not available in the NDK. if (priority == ANDROID_LOG_FATAL && file != nullptr) { - snprintf(log_message, sizeof(log_message), "%s:%u] %s", file, line, message); - } else { - snprintf(log_message, sizeof(log_message), "%s", message); + snprintf(log_message_with_file, sizeof(log_message_with_file), "%s:%u] %s", file, line, + message); + message = log_message_with_file; } static auto& liblog_functions = GetLibLogFunctions(); if (liblog_functions) { __android_logger_data logger_data = {sizeof(__android_logger_data), lg_id, priority, tag, static_cast(nullptr), 0}; - liblog_functions->__android_log_logd_logger(&logger_data, log_message); + liblog_functions->__android_log_logd_logger(&logger_data, message); } else { __android_log_buf_print(lg_id, priority, tag, "%s", message); } From d0696eba9da33cf9b3974e9f5d8e1f022c71c57a Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 3 Feb 2020 13:56:05 -0800 Subject: [PATCH 03/15] libsnapshot: Restrict when snapshots can be deleted. Do not delete snapshots for any reason other than merge-complete or a cancel request from update_engine. Additionally, create a rollback indicator file if booting into the source slot, so update_engine can attempt to cancel the update. Bug: 147819418 Bug: 147347110 Test: libsnapshot_test gtest Change-Id: Id357a91cec467a60246c7c3d133f6c54ccb3fc93 (cherry picked from commit 367cca3937bd449f6762f625336ca10d28076d17) --- fs_mgr/libsnapshot/device_info.cpp | 1 + .../include/libsnapshot/snapshot.h | 8 +- fs_mgr/libsnapshot/snapshot.cpp | 130 ++++++++++++------ fs_mgr/libsnapshot/snapshot_test.cpp | 10 +- fs_mgr/libsnapshot/snapshotctl.cpp | 4 +- 5 files changed, 104 insertions(+), 49 deletions(-) diff --git a/fs_mgr/libsnapshot/device_info.cpp b/fs_mgr/libsnapshot/device_info.cpp index bacb41c48..0e9010066 100644 --- a/fs_mgr/libsnapshot/device_info.cpp +++ b/fs_mgr/libsnapshot/device_info.cpp @@ -22,6 +22,7 @@ namespace android { namespace snapshot { #ifdef LIBSNAPSHOT_USE_HAL +using android::hardware::boot::V1_0::BoolResult; using android::hardware::boot::V1_0::CommandResult; #endif diff --git a/fs_mgr/libsnapshot/include/libsnapshot/snapshot.h b/fs_mgr/libsnapshot/include/libsnapshot/snapshot.h index e786bc9dc..ed92dd797 100644 --- a/fs_mgr/libsnapshot/include/libsnapshot/snapshot.h +++ b/fs_mgr/libsnapshot/include/libsnapshot/snapshot.h @@ -174,6 +174,7 @@ class SnapshotManager final { // See InitiateMerge() and ProcessUpdateState() for details. // Returns: // - None if no merge to initiate + // - Unverified if called on the source slot // - MergeCompleted if merge is completed // - other states indicating an error has occurred UpdateState InitiateMergeAndWait(); @@ -273,6 +274,7 @@ class SnapshotManager final { FRIEND_TEST(SnapshotTest, UpdateBootControlHal); FRIEND_TEST(SnapshotUpdateTest, DataWipeAfterRollback); FRIEND_TEST(SnapshotUpdateTest, DataWipeRollbackInRecovery); + FRIEND_TEST(SnapshotUpdateTest, FullUpdateFlow); FRIEND_TEST(SnapshotUpdateTest, MergeCannotRemoveCow); FRIEND_TEST(SnapshotUpdateTest, MergeInRecovery); FRIEND_TEST(SnapshotUpdateTest, SnapshotStatusFileWithoutCow); @@ -374,7 +376,7 @@ class SnapshotManager final { bool HandleCancelledUpdate(LockedFile* lock); // Helper for HandleCancelledUpdate. Assumes booting from new slot. - bool HandleCancelledUpdateOnNewSlot(LockedFile* lock); + bool AreAllSnapshotsCancelled(LockedFile* lock); // Remove artifacts created by the update process, such as snapshots, and // set the update state to None. @@ -439,7 +441,7 @@ class SnapshotManager final { std::string GetSnapshotStatusFilePath(const std::string& name); std::string GetSnapshotBootIndicatorPath(); - void RemoveSnapshotBootIndicator(); + std::string GetRollbackIndicatorPath(); // Return the name of the device holding the "snapshot" or "snapshot-merge" // target. This may not be the final device presented via MapSnapshot(), if @@ -503,6 +505,8 @@ class SnapshotManager final { friend std::ostream& operator<<(std::ostream& os, SnapshotManager::Slot slot); Slot GetCurrentSlot(); + std::string ReadUpdateSourceSlotSuffix(); + std::string gsid_dir_; std::string metadata_dir_; std::unique_ptr device_; diff --git a/fs_mgr/libsnapshot/snapshot.cpp b/fs_mgr/libsnapshot/snapshot.cpp index 63a930238..a937b433f 100644 --- a/fs_mgr/libsnapshot/snapshot.cpp +++ b/fs_mgr/libsnapshot/snapshot.cpp @@ -188,11 +188,19 @@ bool SnapshotManager::TryCancelUpdate(bool* needs_merge) { return true; } -SnapshotManager::Slot SnapshotManager::GetCurrentSlot() { +std::string SnapshotManager::ReadUpdateSourceSlotSuffix() { auto boot_file = GetSnapshotBootIndicatorPath(); std::string contents; if (!android::base::ReadFileToString(boot_file, &contents)) { PLOG(WARNING) << "Cannot read " << boot_file; + return {}; + } + return contents; +} + +SnapshotManager::Slot SnapshotManager::GetCurrentSlot() { + auto contents = ReadUpdateSourceSlotSuffix(); + if (contents.empty()) { return Slot::Unknown; } if (device_->GetSlotSuffix() == contents) { @@ -201,6 +209,15 @@ SnapshotManager::Slot SnapshotManager::GetCurrentSlot() { return Slot::Target; } +static bool RemoveFileIfExists(const std::string& path) { + std::string message; + if (!android::base::RemoveFileIfExists(path, &message)) { + LOG(ERROR) << "Remove failed: " << path << ": " << message; + return false; + } + return true; +} + bool SnapshotManager::RemoveAllUpdateState(LockedFile* lock) { LOG(INFO) << "Removing all update state."; @@ -223,7 +240,13 @@ bool SnapshotManager::RemoveAllUpdateState(LockedFile* lock) { return false; } - RemoveSnapshotBootIndicator(); + // It's okay if these fail - first-stage init performs a deeper check after + // reading the indicator file, so it's not a problem if it still exists + // after the update completes. + std::vector files = {GetSnapshotBootIndicatorPath(), GetRollbackIndicatorPath()}; + for (const auto& file : files) { + RemoveFileIfExists(file); + } // If this fails, we'll keep trying to remove the update state (as the // device reboots or starts a new update) until it finally succeeds. @@ -250,6 +273,13 @@ bool SnapshotManager::FinishedSnapshotWrites() { return false; } + // This file is written on boot to detect whether a rollback occurred. It + // MUST NOT exist before rebooting, otherwise, we're at risk of deleting + // snapshots too early. + if (!RemoveFileIfExists(GetRollbackIndicatorPath())) { + return false; + } + // This file acts as both a quick indicator for init (it can use access(2) // to decide how to do first-stage mounts), and it stores the old slot, so // we can tell whether or not we performed a rollback. @@ -966,14 +996,8 @@ std::string SnapshotManager::GetSnapshotBootIndicatorPath() { return metadata_dir_ + "/" + android::base::Basename(kBootIndicatorPath); } -void SnapshotManager::RemoveSnapshotBootIndicator() { - // It's okay if this fails - first-stage init performs a deeper check after - // reading the indicator file, so it's not a problem if it still exists - // after the update completes. - auto boot_file = GetSnapshotBootIndicatorPath(); - if (unlink(boot_file.c_str()) == -1 && errno != ENOENT) { - PLOG(ERROR) << "unlink " << boot_file; - } +std::string SnapshotManager::GetRollbackIndicatorPath() { + return metadata_dir_ + "/rollback-indicator"; } void SnapshotManager::AcknowledgeMergeSuccess(LockedFile* lock) { @@ -1144,25 +1168,18 @@ bool SnapshotManager::HandleCancelledUpdate(LockedFile* lock) { if (slot == Slot::Unknown) { return false; } - if (slot == Slot::Target) { - // We're booted into the target slot, which means we just rebooted - // after applying the update. - if (!HandleCancelledUpdateOnNewSlot(lock)) { - return false; - } + + // If all snapshots were reflashed, then cancel the entire update. + if (AreAllSnapshotsCancelled(lock)) { + RemoveAllUpdateState(lock); + return true; } - // The only way we can get here is if: - // (1) The device rolled back to the previous slot. - // (2) This function was called prematurely before rebooting the device. - // (3) fastboot set_active was used. - // (4) The device updates to the new slot but re-flashed *all* partitions - // in the new slot. - // - // In any case, delete the snapshots. It may be worth using the boot_control - // HAL to differentiate case (2). - RemoveAllUpdateState(lock); - return true; + // This unverified update might be rolled back, or it might not (b/147347110 + // comment #77). Take no action, as update_engine is responsible for deciding + // whether to cancel. + LOG(ERROR) << "Update state is being processed before reboot, taking no action."; + return false; } std::unique_ptr SnapshotManager::ReadCurrentMetadata() { @@ -1187,7 +1204,7 @@ SnapshotManager::MetadataPartitionState SnapshotManager::GetMetadataPartitionSta return MetadataPartitionState::Flashed; } -bool SnapshotManager::HandleCancelledUpdateOnNewSlot(LockedFile* lock) { +bool SnapshotManager::AreAllSnapshotsCancelled(LockedFile* lock) { std::vector snapshots; if (!ListSnapshots(lock, &snapshots)) { LOG(WARNING) << "Failed to list snapshots to determine whether device has been flashed " @@ -1196,35 +1213,45 @@ bool SnapshotManager::HandleCancelledUpdateOnNewSlot(LockedFile* lock) { return true; } + auto source_slot_suffix = ReadUpdateSourceSlotSuffix(); + if (source_slot_suffix.empty()) { + return false; + } + uint32_t source_slot = SlotNumberForSlotSuffix(source_slot_suffix); + uint32_t target_slot = (source_slot == 0) ? 1 : 0; + // Attempt to detect re-flashing on each partition. // - If all partitions are re-flashed, we can proceed to cancel the whole update. // - If only some of the partitions are re-flashed, snapshots for re-flashed partitions are // deleted. Caller is responsible for merging the rest of the snapshots. // - If none of the partitions are re-flashed, caller is responsible for merging the snapshots. - auto metadata = ReadCurrentMetadata(); - if (!metadata) return false; - bool all_snapshot_cancelled = true; + // + // Note that we use target slot metadata, since if an OTA has been applied + // to the target slot, we can detect the UPDATED flag. Any kind of flash + // operation against dynamic partitions ensures that all copies of the + // metadata are in sync, so flashing all partitions on the source slot will + // remove the UPDATED flag on the target slot as well. + const auto& opener = device_->GetPartitionOpener(); + auto super_device = device_->GetSuperDevice(target_slot); + auto metadata = android::fs_mgr::ReadMetadata(opener, super_device, target_slot); + if (!metadata) { + return false; + } + + bool all_snapshots_cancelled = true; for (const auto& snapshot_name : snapshots) { if (GetMetadataPartitionState(*metadata, snapshot_name) == MetadataPartitionState::Updated) { - LOG(WARNING) << "Cannot cancel update because snapshot" << snapshot_name - << " is in use."; - all_snapshot_cancelled = false; + all_snapshots_cancelled = false; continue; } // Delete snapshots for partitions that are re-flashed after the update. - LOG(INFO) << "Detected re-flashing of partition " << snapshot_name << "."; - if (!DeleteSnapshot(lock, snapshot_name)) { - // This is an error, but it is okay to leave the snapshot in the short term. - // However, if all_snapshot_cancelled == false after exiting the loop, caller may - // initiate merge for this unused snapshot, which is likely to fail. - LOG(WARNING) << "Failed to delete snapshot for re-flashed partition " << snapshot_name; - } + LOG(WARNING) << "Detected re-flashing of partition " << snapshot_name << "."; } - if (!all_snapshot_cancelled) return false; - - LOG(INFO) << "All partitions are re-flashed after update, removing all update states."; - return true; + if (all_snapshots_cancelled) { + LOG(WARNING) << "All partitions are re-flashed after update, removing all update states."; + } + return all_snapshots_cancelled; } bool SnapshotManager::RemoveAllSnapshots(LockedFile* lock) { @@ -1344,7 +1371,16 @@ bool SnapshotManager::NeedSnapshotsInFirstStageMount() { // the reason be clearer? Because the indicator file still exists, and // if this was FATAL, reverting to the old slot would be broken. auto slot = GetCurrentSlot(); + if (slot != Slot::Target) { + if (slot == Slot::Source && !device_->IsRecovery()) { + // Device is rebooting into the original slot, so mark this as a + // rollback. + auto path = GetRollbackIndicatorPath(); + if (!android::base::WriteStringToFile("1", path)) { + PLOG(ERROR) << "Unable to write rollback indicator: " << path; + } + } LOG(INFO) << "Not booting from new slot. Will not mount snapshots."; return false; } @@ -2370,6 +2406,10 @@ UpdateState SnapshotManager::InitiateMergeAndWait() { return state; } if (state == UpdateState::Unverified) { + if (GetCurrentSlot() != Slot::Target) { + LOG(INFO) << "Cannot merge until device reboots."; + return state; + } if (!InitiateMerge()) { LOG(ERROR) << "Failed to initiate merge."; return state; diff --git a/fs_mgr/libsnapshot/snapshot_test.cpp b/fs_mgr/libsnapshot/snapshot_test.cpp index c5ad44ca5..9777264b1 100644 --- a/fs_mgr/libsnapshot/snapshot_test.cpp +++ b/fs_mgr/libsnapshot/snapshot_test.cpp @@ -447,6 +447,9 @@ TEST_F(SnapshotTest, FirstStageMountAfterRollback) { auto sm = SnapshotManager::NewForFirstStageMount(info); ASSERT_NE(sm, nullptr); ASSERT_FALSE(sm->NeedSnapshotsInFirstStageMount()); + + auto indicator = sm->GetRollbackIndicatorPath(); + ASSERT_EQ(access(indicator.c_str(), R_OK), 0); } TEST_F(SnapshotTest, Merge) { @@ -1015,6 +1018,9 @@ TEST_F(SnapshotUpdateTest, FullUpdateFlow) { ASSERT_TRUE(init->NeedSnapshotsInFirstStageMount()); ASSERT_TRUE(init->CreateLogicalAndSnapshotPartitions("super", snapshot_timeout_)); + auto indicator = sm->GetRollbackIndicatorPath(); + ASSERT_NE(access(indicator.c_str(), R_OK), 0); + // Check that the target partitions have the same content. for (const auto& name : {"sys_b", "vnd_b", "prd_b"}) { ASSERT_TRUE(IsPartitionUnchanged(name)); @@ -1681,9 +1687,11 @@ TEST_P(FlashAfterUpdateTest, FlashSlotAfterUpdate) { ASSERT_NE(nullptr, flashed_builder->FindPartition("prd" + flashed_slot_suffix)); flashed_builder->RemovePartition("prd" + flashed_slot_suffix); + // Note that fastbootd always updates the partition table of both slots. auto flashed_metadata = flashed_builder->Export(); ASSERT_NE(nullptr, flashed_metadata); - ASSERT_TRUE(UpdatePartitionTable(*opener_, "super", *flashed_metadata, flashed_slot)); + ASSERT_TRUE(UpdatePartitionTable(*opener_, "super", *flashed_metadata, 0)); + ASSERT_TRUE(UpdatePartitionTable(*opener_, "super", *flashed_metadata, 1)); std::string path; for (const auto& name : {"sys", "vnd"}) { diff --git a/fs_mgr/libsnapshot/snapshotctl.cpp b/fs_mgr/libsnapshot/snapshotctl.cpp index 9f23c45cc..d724be390 100644 --- a/fs_mgr/libsnapshot/snapshotctl.cpp +++ b/fs_mgr/libsnapshot/snapshotctl.cpp @@ -112,7 +112,9 @@ bool MergeCmdHandler(int argc, char** argv) { auto state = SnapshotManager::New()->InitiateMergeAndWait(); - if (state == UpdateState::None) { + // We could wind up in the Unverified state if the device rolled back or + // hasn't fully rebooted. Ignore this. + if (state == UpdateState::None || state == UpdateState::Unverified) { return true; } if (state == UpdateState::MergeCompleted) { From 53e4bf8b95cd6d2fe7b4e2f4a08be2f1db033398 Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Wed, 19 Feb 2020 13:50:57 -0800 Subject: [PATCH 04/15] adbd: remove static dependency on libcutils. We were previously statically linking libcutils into adbd for several different reasons, which were addressed as follows: socket functions: extracted to a statically linked libcutils_network fs_config: wrapped with a shared library on /system ATRACE: deleted the single use in adbd Test: treehugger Change-Id: I821fa174cfcbfa8e29a4be10de4016b817adbaf8 (cherry picked from commit a9b62d545275ca32775a0bc5f004abe03aaa38ad) --- adb/Android.bp | 85 ++++------------ adb/adb_trace.h | 7 -- adb/client/adb_install.cpp | 1 + adb/client/incremental_server.cpp | 1 + adb/daemon/file_sync_service.cpp | 16 ++-- adb/daemon/usb.cpp | 1 + .../deploypatchgenerator/apk_archive.cpp | 2 + adb/{adbconnection => libs}/.clang-format | 0 adb/libs/adbconnection/.clang-format | 1 + adb/libs/adbconnection/Android.bp | 59 ++++++++++++ .../adbconnection/adbconnection_client.cpp | 0 .../adbconnection/adbconnection_server.cpp | 0 .../include/adbconnection/client.h | 0 .../include/adbconnection/server.h | 0 .../libadbconnection_client.map.txt | 0 adb/libs/libadbd_fs/Android.bp | 30 ++++++ adb/libs/libadbd_fs/adbd_fs.cpp | 30 ++++++ adb/libs/libadbd_fs/include/adbd_fs.h | 26 +++++ adb/libs/libadbd_fs/libadbd_fs.map.txt | 6 ++ libcutils/Android.bp | 96 ++++++++++++++++--- 20 files changed, 266 insertions(+), 95 deletions(-) rename adb/{adbconnection => libs}/.clang-format (100%) create mode 120000 adb/libs/adbconnection/.clang-format create mode 100644 adb/libs/adbconnection/Android.bp rename adb/{ => libs}/adbconnection/adbconnection_client.cpp (100%) rename adb/{ => libs}/adbconnection/adbconnection_server.cpp (100%) rename adb/{ => libs}/adbconnection/include/adbconnection/client.h (100%) rename adb/{ => libs}/adbconnection/include/adbconnection/server.h (100%) rename adb/{ => libs}/adbconnection/libadbconnection_client.map.txt (100%) create mode 100644 adb/libs/libadbd_fs/Android.bp create mode 100644 adb/libs/libadbd_fs/adbd_fs.cpp create mode 100644 adb/libs/libadbd_fs/include/adbd_fs.h create mode 100644 adb/libs/libadbd_fs/libadbd_fs.map.txt diff --git a/adb/Android.bp b/adb/Android.bp index 1004483ac..2f1fe3ca0 100644 --- a/adb/Android.bp +++ b/adb/Android.bp @@ -114,66 +114,6 @@ cc_defaults { }, } -// libadbconnection -// ========================================================= -// libadbconnection_client/server implement the socket handling for jdwp -// forwarding and the track-jdwp service. -cc_library { - name: "libadbconnection_server", - srcs: ["adbconnection/adbconnection_server.cpp"], - - export_include_dirs: ["adbconnection/include"], - - stl: "libc++_static", - shared_libs: ["liblog"], - static_libs: ["libbase"], - - defaults: ["adbd_defaults", "host_adbd_supported"], - - // Avoid getting duplicate symbol of android::build::getbuildnumber(). - use_version_lib: false, - - recovery_available: true, - compile_multilib: "both", -} - -cc_library { - name: "libadbconnection_client", - srcs: ["adbconnection/adbconnection_client.cpp"], - - export_include_dirs: ["adbconnection/include"], - - stl: "libc++_static", - shared_libs: ["liblog"], - static_libs: ["libbase"], - - defaults: ["adbd_defaults"], - visibility: [ - "//art:__subpackages__", - "//system/core/adb/apex:__subpackages__", - ], - apex_available: [ - "com.android.adbd", - "test_com.android.adbd", - ], - - // libadbconnection_client doesn't need an embedded build number. - use_version_lib: false, - - target: { - linux: { - version_script: "adbconnection/libadbconnection_client.map.txt", - }, - }, - stubs: { - symbol_file: "adbconnection/libadbconnection_client.map.txt", - versions: ["1"], - }, - - host_supported: true, - compile_multilib: "both", -} - // libadb // ========================================================= // These files are compiled for both the host and the device. @@ -459,7 +399,6 @@ cc_library_static { "libbase", "libcrypto", "libcrypto_utils", - "libcutils", "liblog", ], @@ -483,7 +422,7 @@ cc_library_static { }, } -cc_library { +cc_library_static { name: "libadbd_services", defaults: ["adbd_defaults", "host_adbd_supported"], recovery_available: true, @@ -513,11 +452,11 @@ cc_library { "libadb_protos", "libadb_tls_connection", "libadbd_auth", + "libadbd_fs", "libasyncio", "libbase", "libcrypto", "libcrypto_utils", - "libcutils", "liblog", ], @@ -564,13 +503,19 @@ cc_library { "libadb_pairing_connection", "libadb_tls_connection", "libadbd_auth", - "libadbd_services", + "libadbd_fs", "libasyncio", "libbase", "libcrypto", "libcrypto_utils", - "libcutils", "liblog", + "libselinux", + ], + + static_libs: [ + "libadbd_services", + "libcutils_sockets", + "libdiagnose_usb", ], export_include_dirs: [ @@ -605,7 +550,7 @@ cc_binary { "libbase", "libcap", "libcrypto_utils", - "libcutils", + "libcutils_sockets", "libdiagnose_usb", "liblog", "libmdnssd", @@ -620,10 +565,14 @@ cc_binary { "libadb_protos", "libadb_tls_connection", "libadbd_auth", + "libadbd_fs", "libcrypto", ], - required: ["libadbd_auth"], + required: [ + "libadbd_auth", + "libadbd_fs", + ], } phony { @@ -699,9 +648,9 @@ cc_test { "libadb_pairing_connection_static", "libadb_tls_connection_static", "libbase", - "libcutils", "libcrypto_utils", "libcrypto_static", + "libcutils_sockets", "libdiagnose_usb", "liblog", "libusb", diff --git a/adb/adb_trace.h b/adb/adb_trace.h index ed4be88a6..3421a0296 100644 --- a/adb/adb_trace.h +++ b/adb/adb_trace.h @@ -59,11 +59,4 @@ extern int adb_trace_mask; void adb_trace_init(char**); void adb_trace_enable(AdbTrace trace_tag); -// Include before stdatomic.h (introduced in cutils/trace.h) to avoid compile error. -#include - -#define ATRACE_TAG ATRACE_TAG_ADB -#include -#include - #endif /* __ADB_TRACE_H */ diff --git a/adb/client/adb_install.cpp b/adb/client/adb_install.cpp index 982a96b74..21b8f4999 100644 --- a/adb/client/adb_install.cpp +++ b/adb/client/adb_install.cpp @@ -17,6 +17,7 @@ #include "adb_install.h" #include +#include #include #include #include diff --git a/adb/client/incremental_server.cpp b/adb/client/incremental_server.cpp index 726533d2a..8d1f48ce6 100644 --- a/adb/client/incremental_server.cpp +++ b/adb/client/incremental_server.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include #include diff --git a/adb/daemon/file_sync_service.cpp b/adb/daemon/file_sync_service.cpp index d6af7087d..edf5683d3 100644 --- a/adb/daemon/file_sync_service.cpp +++ b/adb/daemon/file_sync_service.cpp @@ -40,10 +40,13 @@ #include #include -#include +#include + +// Needed for __android_log_security_bswrite. #include #if defined(__ANDROID__) +#include #include #include #endif @@ -98,7 +101,7 @@ static bool secure_mkdirs(const std::string& path) { for (const auto& path_component : path_components) { uid_t uid = -1; gid_t gid = -1; - unsigned int mode = 0775; + mode_t mode = 0775; uint64_t capabilities = 0; if (path_component.empty()) { @@ -111,7 +114,7 @@ static bool secure_mkdirs(const std::string& path) { partial_path += path_component; if (should_use_fs_config(partial_path)) { - fs_config(partial_path.c_str(), 1, nullptr, &uid, &gid, &mode, &capabilities); + adbd_fs_config(partial_path.c_str(), 1, nullptr, &uid, &gid, &mode, &capabilities); } if (adb_mkdir(partial_path.c_str(), mode) == -1) { if (errno != EEXIST) { @@ -468,9 +471,7 @@ static bool do_send(int s, const std::string& spec, std::vector& buffer) { gid_t gid = -1; uint64_t capabilities = 0; if (should_use_fs_config(path)) { - unsigned int broken_api_hack = mode; - fs_config(path.c_str(), 0, nullptr, &uid, &gid, &broken_api_hack, &capabilities); - mode = broken_api_hack; + adbd_fs_config(path.c_str(), 0, nullptr, &uid, &gid, &mode, &capabilities); } result = handle_send_file(s, path.c_str(), ×tamp, uid, gid, capabilities, mode, buffer, @@ -550,7 +551,6 @@ static const char* sync_id_to_name(uint32_t id) { static bool handle_sync_command(int fd, std::vector& buffer) { D("sync: waiting for request"); - ATRACE_CALL(); SyncRequest request; if (!ReadFdExactly(fd, &request, sizeof(request))) { SendSyncFail(fd, "command read failure"); @@ -569,8 +569,6 @@ static bool handle_sync_command(int fd, std::vector& buffer) { name[path_length] = 0; std::string id_name = sync_id_to_name(request.id); - std::string trace_name = StringPrintf("%s(%s)", id_name.c_str(), name); - ATRACE_NAME(trace_name.c_str()); D("sync: %s('%s')", id_name.c_str(), name); switch (request.id) { diff --git a/adb/daemon/usb.cpp b/adb/daemon/usb.cpp index c7f8895b8..092819807 100644 --- a/adb/daemon/usb.cpp +++ b/adb/daemon/usb.cpp @@ -19,6 +19,7 @@ #include "sysdeps.h" #include +#include #include #include #include diff --git a/adb/fastdeploy/deploypatchgenerator/apk_archive.cpp b/adb/fastdeploy/deploypatchgenerator/apk_archive.cpp index 932d579b5..9da256e24 100644 --- a/adb/fastdeploy/deploypatchgenerator/apk_archive.cpp +++ b/adb/fastdeploy/deploypatchgenerator/apk_archive.cpp @@ -18,6 +18,8 @@ #include "apk_archive.h" +#include + #include "adb_trace.h" #include "sysdeps.h" diff --git a/adb/adbconnection/.clang-format b/adb/libs/.clang-format similarity index 100% rename from adb/adbconnection/.clang-format rename to adb/libs/.clang-format diff --git a/adb/libs/adbconnection/.clang-format b/adb/libs/adbconnection/.clang-format new file mode 120000 index 000000000..e545823f4 --- /dev/null +++ b/adb/libs/adbconnection/.clang-format @@ -0,0 +1 @@ +../../.clang-format-2 \ No newline at end of file diff --git a/adb/libs/adbconnection/Android.bp b/adb/libs/adbconnection/Android.bp new file mode 100644 index 000000000..f6b0a4239 --- /dev/null +++ b/adb/libs/adbconnection/Android.bp @@ -0,0 +1,59 @@ +// libadbconnection +// ========================================================= +// libadbconnection_client/server implement the socket handling for jdwp +// forwarding and the track-jdwp service. +cc_library { + name: "libadbconnection_server", + srcs: ["adbconnection_server.cpp"], + + export_include_dirs: ["include"], + + stl: "libc++_static", + shared_libs: ["liblog"], + static_libs: ["libbase"], + + defaults: ["adbd_defaults", "host_adbd_supported"], + + // Avoid getting duplicate symbol of android::build::GetBuildNumber(). + use_version_lib: false, + + recovery_available: true, + compile_multilib: "both", +} + +cc_library { + name: "libadbconnection_client", + srcs: ["adbconnection_client.cpp"], + + export_include_dirs: ["include"], + + stl: "libc++_static", + shared_libs: ["liblog"], + static_libs: ["libbase"], + + defaults: ["adbd_defaults"], + visibility: [ + "//art:__subpackages__", + "//system/core/adb/apex:__subpackages__", + ], + apex_available: [ + "com.android.adbd", + "test_com.android.adbd", + ], + + // libadbconnection_client doesn't need an embedded build number. + use_version_lib: false, + + target: { + linux: { + version_script: "libadbconnection_client.map.txt", + }, + }, + stubs: { + symbol_file: "libadbconnection_client.map.txt", + versions: ["1"], + }, + + host_supported: true, + compile_multilib: "both", +} diff --git a/adb/adbconnection/adbconnection_client.cpp b/adb/libs/adbconnection/adbconnection_client.cpp similarity index 100% rename from adb/adbconnection/adbconnection_client.cpp rename to adb/libs/adbconnection/adbconnection_client.cpp diff --git a/adb/adbconnection/adbconnection_server.cpp b/adb/libs/adbconnection/adbconnection_server.cpp similarity index 100% rename from adb/adbconnection/adbconnection_server.cpp rename to adb/libs/adbconnection/adbconnection_server.cpp diff --git a/adb/adbconnection/include/adbconnection/client.h b/adb/libs/adbconnection/include/adbconnection/client.h similarity index 100% rename from adb/adbconnection/include/adbconnection/client.h rename to adb/libs/adbconnection/include/adbconnection/client.h diff --git a/adb/adbconnection/include/adbconnection/server.h b/adb/libs/adbconnection/include/adbconnection/server.h similarity index 100% rename from adb/adbconnection/include/adbconnection/server.h rename to adb/libs/adbconnection/include/adbconnection/server.h diff --git a/adb/adbconnection/libadbconnection_client.map.txt b/adb/libs/adbconnection/libadbconnection_client.map.txt similarity index 100% rename from adb/adbconnection/libadbconnection_client.map.txt rename to adb/libs/adbconnection/libadbconnection_client.map.txt diff --git a/adb/libs/libadbd_fs/Android.bp b/adb/libs/libadbd_fs/Android.bp new file mode 100644 index 000000000..d17814825 --- /dev/null +++ b/adb/libs/libadbd_fs/Android.bp @@ -0,0 +1,30 @@ +// libadbd_fs +// ========================================================= +cc_library { + name: "libadbd_fs", + defaults: ["adbd_defaults"], + + srcs: ["adbd_fs.cpp"], + static_libs: [ + "libbase", + "libcutils", + "liblog", + ], + export_include_dirs: ["include"], + + version_script: "libadbd_fs.map.txt", + stubs: { + versions: ["1"], + symbol_file: "libadbd_fs.map.txt", + }, + + host_supported: true, + recovery_available: true, + compile_multilib: "both", + + target: { + darwin: { + enabled: false, + } + }, +} diff --git a/adb/libs/libadbd_fs/adbd_fs.cpp b/adb/libs/libadbd_fs/adbd_fs.cpp new file mode 100644 index 000000000..8e62d40d1 --- /dev/null +++ b/adb/libs/libadbd_fs/adbd_fs.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2020 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. + */ + +#include + +#include + +void adbd_fs_config(const char* path, int dir, const char* target_out_path, uid_t* uid, gid_t* gid, + mode_t* mode, uint64_t* capabilities) { + unsigned uid_hack; + unsigned gid_hack; + unsigned mode_hack; + fs_config(path, dir, target_out_path, &uid_hack, &gid_hack, &mode_hack, capabilities); + *uid = uid_hack; + *gid = gid_hack; + *mode = mode_hack; +} diff --git a/adb/libs/libadbd_fs/include/adbd_fs.h b/adb/libs/libadbd_fs/include/adbd_fs.h new file mode 100644 index 000000000..6158d7208 --- /dev/null +++ b/adb/libs/libadbd_fs/include/adbd_fs.h @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2020 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 + +#include +#include + +extern "C" { +// Thin wrapper around libcutils fs_config. +void adbd_fs_config(const char* path, int dir, const char* target_out_path, uid_t* uid, gid_t* gid, + mode_t* mode, uint64_t* capabilities); +} diff --git a/adb/libs/libadbd_fs/libadbd_fs.map.txt b/adb/libs/libadbd_fs/libadbd_fs.map.txt new file mode 100644 index 000000000..1454e9639 --- /dev/null +++ b/adb/libs/libadbd_fs/libadbd_fs.map.txt @@ -0,0 +1,6 @@ +LIBADBD_FS { + global: + adbd_fs_config; # apex + local: + *; +}; diff --git a/libcutils/Android.bp b/libcutils/Android.bp index 0379f6e2e..4e93df370 100644 --- a/libcutils/Android.bp +++ b/libcutils/Android.bp @@ -21,11 +21,6 @@ libcutils_nonwindows_sources = [ "fs.cpp", "hashmap.cpp", "multiuser.cpp", - "socket_inaddr_any_server_unix.cpp", - "socket_local_client_unix.cpp", - "socket_local_server_unix.cpp", - "socket_network_client_unix.cpp", - "sockets_unix.cpp", "str_parms.cpp", ] @@ -49,6 +44,90 @@ cc_library_headers { }, } +// Socket specific parts of libcutils that are safe to statically link into an APEX. +cc_library_static { + name: "libcutils_sockets", + vendor_available: true, + vndk: { + enabled: true, + support_system_process: true, + }, + recovery_available: true, + host_supported: true, + native_bridge_supported: true, + apex_available: [ + "//apex_available:platform", + "//apex_available:anyapex", + ], + + export_include_dirs: ["include"], + + srcs: ["sockets.cpp"], + target: { + linux_bionic: { + enabled: true, + }, + + not_windows: { + srcs: [ + "socket_inaddr_any_server_unix.cpp", + "socket_local_client_unix.cpp", + "socket_local_server_unix.cpp", + "socket_network_client_unix.cpp", + "sockets_unix.cpp", + ], + }, + + // "not_windows" means "non-Windows host". + android: { + srcs: [ + "android_get_control_file.cpp", + "socket_inaddr_any_server_unix.cpp", + "socket_local_client_unix.cpp", + "socket_local_server_unix.cpp", + "socket_network_client_unix.cpp", + "sockets_unix.cpp", + ], + static_libs: ["libbase"], + }, + + windows: { + host_ldlibs: ["-lws2_32"], + srcs: [ + "socket_inaddr_any_server_windows.cpp", + "socket_network_client_windows.cpp", + "sockets_windows.cpp", + ], + + enabled: true, + cflags: [ + "-D_GNU_SOURCE", + ], + }, + }, +} + +cc_test { + name: "libcutils_sockets_test", + test_suites: ["device-tests"], + static_libs: ["libbase", "libcutils_sockets"], + cflags: [ + "-Wall", + "-Wextra", + "-Werror", + ], + + srcs: ["sockets_test.cpp"], + target: { + android: { + srcs: [ + "android_get_control_file_test.cpp", + "android_get_control_socket_test.cpp", + ], + }, + }, +} + cc_library { name: "libcutils", vendor_available: true, @@ -66,7 +145,6 @@ cc_library { "load_file.cpp", "native_handle.cpp", "record_stream.cpp", - "sockets.cpp", "strlcpy.c", "threads.cpp", ], @@ -86,9 +164,6 @@ cc_library { host_ldlibs: ["-lws2_32"], srcs: [ - "socket_inaddr_any_server_windows.cpp", - "socket_network_client_windows.cpp", - "sockets_windows.cpp", "trace-host.cpp", ], @@ -97,10 +172,8 @@ cc_library { "-D_GNU_SOURCE", ], }, - android: { srcs: libcutils_nonwindows_sources + [ - "android_get_control_file.cpp", "android_reboot.cpp", "ashmem-dev.cpp", "fs_config.cpp", @@ -149,6 +222,7 @@ cc_library { } }, + whole_static_libs: ["libcutils_sockets"], shared_libs: [ "liblog", "libbase", From 646e4179f7a1987a97a995272127f8f7543c930d Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Fri, 21 Feb 2020 16:38:29 -0800 Subject: [PATCH 05/15] adbd: fix build breakage. This broke because two CLs touching the Android.bp file both independently passed presubmit, but failed when combined. Clean up a misindentation while we're at it. Bug: http://b/150032367 Test: mma in system/core/adb Change-Id: I091ef9dec806c767ffb21a5fd73b2bb37ab29ff9 (cherry picked from commit 6d949e89a47e4876b835fe95d3299699da0bba92) --- adb/Android.bp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/adb/Android.bp b/adb/Android.bp index 2f1fe3ca0..fea8c7807 100644 --- a/adb/Android.bp +++ b/adb/Android.bp @@ -375,7 +375,7 @@ cc_library_static { srcs: libadb_srcs + libadb_linux_srcs + libadb_posix_srcs + [ "daemon/auth.cpp", "daemon/jdwp_service.cpp", - "daemon/adb_wifi.cpp", + "daemon/adb_wifi.cpp", ], local_include_dirs: [ @@ -516,6 +516,7 @@ cc_library { "libadbd_services", "libcutils_sockets", "libdiagnose_usb", + "libmdnssd", ], export_include_dirs: [ From 0c13e1eb38dc8aa6f2ce67110ba9a1368d5bb3d1 Mon Sep 17 00:00:00 2001 From: George Burgess IV Date: Fri, 21 Feb 2020 14:36:31 -0800 Subject: [PATCH 06/15] incremental_server: fix a use of uninitalized memory Without this, the caller is likely to assume that their buffer is fully usable, which clang's analyzer doesn't believe is the case. Another option is to set `*size` to nonzero. Caught by the static analyzer: system/core/adb/client/incremental_server.cpp:111:31: warning: 1st function call argument is an uninitialized value [clang-analyzer-core.CallAndMessage] Bug: http://b/150032044 Test: TreeHugger Change-Id: Ib844aa4ab3ebb297ca8f6f4289bbe3212275275b Merged-In: Ib844aa4ab3ebb297ca8f6f4289bbe3212275275b (cherry picked from commit 19b500bd505dce85d90f5be6f318399aed9cc990) (cherry picked from commit 15c7a3f8f82b5a5730734215cce118f5e2c3025d) --- adb/client/incremental_server.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adb/client/incremental_server.cpp b/adb/client/incremental_server.cpp index 726533d2a..585e50c44 100644 --- a/adb/client/incremental_server.cpp +++ b/adb/client/incremental_server.cpp @@ -258,7 +258,7 @@ bool IncrementalServer::SkipToRequest(void* buffer, size_t* size, bool blocking) if (r == -1) { fprintf(stderr, "Failed to read from fd %d: %d. Exit\n", adb_fd_.get(), errno); - return true; + return false; } // socket is closed From 8d05b2bed6681ce697deab9669a8417d44649b91 Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Wed, 19 Feb 2020 13:50:57 -0800 Subject: [PATCH 07/15] adbd: remove static dependency on libcutils. We were previously statically linking libcutils into adbd for several different reasons, which were addressed as follows: socket functions: extracted to a statically linked libcutils_network fs_config: wrapped with a shared library on /system ATRACE: deleted the single use in adbd Bug: http://b/150032044 Test: treehugger Change-Id: I821fa174cfcbfa8e29a4be10de4016b817adbaf8 Merged-In: I821fa174cfcbfa8e29a4be10de4016b817adbaf8 (cherry picked from commit a9b62d545275ca32775a0bc5f004abe03aaa38ad) (cherry picked from commit b5778c1fe7bfa04d2dea0191e340c9adc588110d) --- adb/Android.bp | 85 ++++------------ adb/adb_trace.h | 7 -- adb/client/adb_install.cpp | 1 + adb/client/incremental_server.cpp | 1 + adb/daemon/file_sync_service.cpp | 16 ++-- adb/daemon/usb.cpp | 1 + .../deploypatchgenerator/apk_archive.cpp | 2 + adb/{adbconnection => libs}/.clang-format | 0 adb/libs/adbconnection/.clang-format | 1 + adb/libs/adbconnection/Android.bp | 59 ++++++++++++ .../adbconnection/adbconnection_client.cpp | 0 .../adbconnection/adbconnection_server.cpp | 0 .../include/adbconnection/client.h | 0 .../include/adbconnection/server.h | 0 .../libadbconnection_client.map.txt | 0 adb/libs/libadbd_fs/Android.bp | 30 ++++++ adb/libs/libadbd_fs/adbd_fs.cpp | 30 ++++++ adb/libs/libadbd_fs/include/adbd_fs.h | 26 +++++ adb/libs/libadbd_fs/libadbd_fs.map.txt | 6 ++ libcutils/Android.bp | 96 ++++++++++++++++--- 20 files changed, 266 insertions(+), 95 deletions(-) rename adb/{adbconnection => libs}/.clang-format (100%) create mode 120000 adb/libs/adbconnection/.clang-format create mode 100644 adb/libs/adbconnection/Android.bp rename adb/{ => libs}/adbconnection/adbconnection_client.cpp (100%) rename adb/{ => libs}/adbconnection/adbconnection_server.cpp (100%) rename adb/{ => libs}/adbconnection/include/adbconnection/client.h (100%) rename adb/{ => libs}/adbconnection/include/adbconnection/server.h (100%) rename adb/{ => libs}/adbconnection/libadbconnection_client.map.txt (100%) create mode 100644 adb/libs/libadbd_fs/Android.bp create mode 100644 adb/libs/libadbd_fs/adbd_fs.cpp create mode 100644 adb/libs/libadbd_fs/include/adbd_fs.h create mode 100644 adb/libs/libadbd_fs/libadbd_fs.map.txt diff --git a/adb/Android.bp b/adb/Android.bp index 1004483ac..2f1fe3ca0 100644 --- a/adb/Android.bp +++ b/adb/Android.bp @@ -114,66 +114,6 @@ cc_defaults { }, } -// libadbconnection -// ========================================================= -// libadbconnection_client/server implement the socket handling for jdwp -// forwarding and the track-jdwp service. -cc_library { - name: "libadbconnection_server", - srcs: ["adbconnection/adbconnection_server.cpp"], - - export_include_dirs: ["adbconnection/include"], - - stl: "libc++_static", - shared_libs: ["liblog"], - static_libs: ["libbase"], - - defaults: ["adbd_defaults", "host_adbd_supported"], - - // Avoid getting duplicate symbol of android::build::getbuildnumber(). - use_version_lib: false, - - recovery_available: true, - compile_multilib: "both", -} - -cc_library { - name: "libadbconnection_client", - srcs: ["adbconnection/adbconnection_client.cpp"], - - export_include_dirs: ["adbconnection/include"], - - stl: "libc++_static", - shared_libs: ["liblog"], - static_libs: ["libbase"], - - defaults: ["adbd_defaults"], - visibility: [ - "//art:__subpackages__", - "//system/core/adb/apex:__subpackages__", - ], - apex_available: [ - "com.android.adbd", - "test_com.android.adbd", - ], - - // libadbconnection_client doesn't need an embedded build number. - use_version_lib: false, - - target: { - linux: { - version_script: "adbconnection/libadbconnection_client.map.txt", - }, - }, - stubs: { - symbol_file: "adbconnection/libadbconnection_client.map.txt", - versions: ["1"], - }, - - host_supported: true, - compile_multilib: "both", -} - // libadb // ========================================================= // These files are compiled for both the host and the device. @@ -459,7 +399,6 @@ cc_library_static { "libbase", "libcrypto", "libcrypto_utils", - "libcutils", "liblog", ], @@ -483,7 +422,7 @@ cc_library_static { }, } -cc_library { +cc_library_static { name: "libadbd_services", defaults: ["adbd_defaults", "host_adbd_supported"], recovery_available: true, @@ -513,11 +452,11 @@ cc_library { "libadb_protos", "libadb_tls_connection", "libadbd_auth", + "libadbd_fs", "libasyncio", "libbase", "libcrypto", "libcrypto_utils", - "libcutils", "liblog", ], @@ -564,13 +503,19 @@ cc_library { "libadb_pairing_connection", "libadb_tls_connection", "libadbd_auth", - "libadbd_services", + "libadbd_fs", "libasyncio", "libbase", "libcrypto", "libcrypto_utils", - "libcutils", "liblog", + "libselinux", + ], + + static_libs: [ + "libadbd_services", + "libcutils_sockets", + "libdiagnose_usb", ], export_include_dirs: [ @@ -605,7 +550,7 @@ cc_binary { "libbase", "libcap", "libcrypto_utils", - "libcutils", + "libcutils_sockets", "libdiagnose_usb", "liblog", "libmdnssd", @@ -620,10 +565,14 @@ cc_binary { "libadb_protos", "libadb_tls_connection", "libadbd_auth", + "libadbd_fs", "libcrypto", ], - required: ["libadbd_auth"], + required: [ + "libadbd_auth", + "libadbd_fs", + ], } phony { @@ -699,9 +648,9 @@ cc_test { "libadb_pairing_connection_static", "libadb_tls_connection_static", "libbase", - "libcutils", "libcrypto_utils", "libcrypto_static", + "libcutils_sockets", "libdiagnose_usb", "liblog", "libusb", diff --git a/adb/adb_trace.h b/adb/adb_trace.h index ed4be88a6..3421a0296 100644 --- a/adb/adb_trace.h +++ b/adb/adb_trace.h @@ -59,11 +59,4 @@ extern int adb_trace_mask; void adb_trace_init(char**); void adb_trace_enable(AdbTrace trace_tag); -// Include before stdatomic.h (introduced in cutils/trace.h) to avoid compile error. -#include - -#define ATRACE_TAG ATRACE_TAG_ADB -#include -#include - #endif /* __ADB_TRACE_H */ diff --git a/adb/client/adb_install.cpp b/adb/client/adb_install.cpp index 982a96b74..21b8f4999 100644 --- a/adb/client/adb_install.cpp +++ b/adb/client/adb_install.cpp @@ -17,6 +17,7 @@ #include "adb_install.h" #include +#include #include #include #include diff --git a/adb/client/incremental_server.cpp b/adb/client/incremental_server.cpp index 585e50c44..2512d0562 100644 --- a/adb/client/incremental_server.cpp +++ b/adb/client/incremental_server.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include #include diff --git a/adb/daemon/file_sync_service.cpp b/adb/daemon/file_sync_service.cpp index d6af7087d..edf5683d3 100644 --- a/adb/daemon/file_sync_service.cpp +++ b/adb/daemon/file_sync_service.cpp @@ -40,10 +40,13 @@ #include #include -#include +#include + +// Needed for __android_log_security_bswrite. #include #if defined(__ANDROID__) +#include #include #include #endif @@ -98,7 +101,7 @@ static bool secure_mkdirs(const std::string& path) { for (const auto& path_component : path_components) { uid_t uid = -1; gid_t gid = -1; - unsigned int mode = 0775; + mode_t mode = 0775; uint64_t capabilities = 0; if (path_component.empty()) { @@ -111,7 +114,7 @@ static bool secure_mkdirs(const std::string& path) { partial_path += path_component; if (should_use_fs_config(partial_path)) { - fs_config(partial_path.c_str(), 1, nullptr, &uid, &gid, &mode, &capabilities); + adbd_fs_config(partial_path.c_str(), 1, nullptr, &uid, &gid, &mode, &capabilities); } if (adb_mkdir(partial_path.c_str(), mode) == -1) { if (errno != EEXIST) { @@ -468,9 +471,7 @@ static bool do_send(int s, const std::string& spec, std::vector& buffer) { gid_t gid = -1; uint64_t capabilities = 0; if (should_use_fs_config(path)) { - unsigned int broken_api_hack = mode; - fs_config(path.c_str(), 0, nullptr, &uid, &gid, &broken_api_hack, &capabilities); - mode = broken_api_hack; + adbd_fs_config(path.c_str(), 0, nullptr, &uid, &gid, &mode, &capabilities); } result = handle_send_file(s, path.c_str(), ×tamp, uid, gid, capabilities, mode, buffer, @@ -550,7 +551,6 @@ static const char* sync_id_to_name(uint32_t id) { static bool handle_sync_command(int fd, std::vector& buffer) { D("sync: waiting for request"); - ATRACE_CALL(); SyncRequest request; if (!ReadFdExactly(fd, &request, sizeof(request))) { SendSyncFail(fd, "command read failure"); @@ -569,8 +569,6 @@ static bool handle_sync_command(int fd, std::vector& buffer) { name[path_length] = 0; std::string id_name = sync_id_to_name(request.id); - std::string trace_name = StringPrintf("%s(%s)", id_name.c_str(), name); - ATRACE_NAME(trace_name.c_str()); D("sync: %s('%s')", id_name.c_str(), name); switch (request.id) { diff --git a/adb/daemon/usb.cpp b/adb/daemon/usb.cpp index c7f8895b8..092819807 100644 --- a/adb/daemon/usb.cpp +++ b/adb/daemon/usb.cpp @@ -19,6 +19,7 @@ #include "sysdeps.h" #include +#include #include #include #include diff --git a/adb/fastdeploy/deploypatchgenerator/apk_archive.cpp b/adb/fastdeploy/deploypatchgenerator/apk_archive.cpp index 932d579b5..9da256e24 100644 --- a/adb/fastdeploy/deploypatchgenerator/apk_archive.cpp +++ b/adb/fastdeploy/deploypatchgenerator/apk_archive.cpp @@ -18,6 +18,8 @@ #include "apk_archive.h" +#include + #include "adb_trace.h" #include "sysdeps.h" diff --git a/adb/adbconnection/.clang-format b/adb/libs/.clang-format similarity index 100% rename from adb/adbconnection/.clang-format rename to adb/libs/.clang-format diff --git a/adb/libs/adbconnection/.clang-format b/adb/libs/adbconnection/.clang-format new file mode 120000 index 000000000..e545823f4 --- /dev/null +++ b/adb/libs/adbconnection/.clang-format @@ -0,0 +1 @@ +../../.clang-format-2 \ No newline at end of file diff --git a/adb/libs/adbconnection/Android.bp b/adb/libs/adbconnection/Android.bp new file mode 100644 index 000000000..f6b0a4239 --- /dev/null +++ b/adb/libs/adbconnection/Android.bp @@ -0,0 +1,59 @@ +// libadbconnection +// ========================================================= +// libadbconnection_client/server implement the socket handling for jdwp +// forwarding and the track-jdwp service. +cc_library { + name: "libadbconnection_server", + srcs: ["adbconnection_server.cpp"], + + export_include_dirs: ["include"], + + stl: "libc++_static", + shared_libs: ["liblog"], + static_libs: ["libbase"], + + defaults: ["adbd_defaults", "host_adbd_supported"], + + // Avoid getting duplicate symbol of android::build::GetBuildNumber(). + use_version_lib: false, + + recovery_available: true, + compile_multilib: "both", +} + +cc_library { + name: "libadbconnection_client", + srcs: ["adbconnection_client.cpp"], + + export_include_dirs: ["include"], + + stl: "libc++_static", + shared_libs: ["liblog"], + static_libs: ["libbase"], + + defaults: ["adbd_defaults"], + visibility: [ + "//art:__subpackages__", + "//system/core/adb/apex:__subpackages__", + ], + apex_available: [ + "com.android.adbd", + "test_com.android.adbd", + ], + + // libadbconnection_client doesn't need an embedded build number. + use_version_lib: false, + + target: { + linux: { + version_script: "libadbconnection_client.map.txt", + }, + }, + stubs: { + symbol_file: "libadbconnection_client.map.txt", + versions: ["1"], + }, + + host_supported: true, + compile_multilib: "both", +} diff --git a/adb/adbconnection/adbconnection_client.cpp b/adb/libs/adbconnection/adbconnection_client.cpp similarity index 100% rename from adb/adbconnection/adbconnection_client.cpp rename to adb/libs/adbconnection/adbconnection_client.cpp diff --git a/adb/adbconnection/adbconnection_server.cpp b/adb/libs/adbconnection/adbconnection_server.cpp similarity index 100% rename from adb/adbconnection/adbconnection_server.cpp rename to adb/libs/adbconnection/adbconnection_server.cpp diff --git a/adb/adbconnection/include/adbconnection/client.h b/adb/libs/adbconnection/include/adbconnection/client.h similarity index 100% rename from adb/adbconnection/include/adbconnection/client.h rename to adb/libs/adbconnection/include/adbconnection/client.h diff --git a/adb/adbconnection/include/adbconnection/server.h b/adb/libs/adbconnection/include/adbconnection/server.h similarity index 100% rename from adb/adbconnection/include/adbconnection/server.h rename to adb/libs/adbconnection/include/adbconnection/server.h diff --git a/adb/adbconnection/libadbconnection_client.map.txt b/adb/libs/adbconnection/libadbconnection_client.map.txt similarity index 100% rename from adb/adbconnection/libadbconnection_client.map.txt rename to adb/libs/adbconnection/libadbconnection_client.map.txt diff --git a/adb/libs/libadbd_fs/Android.bp b/adb/libs/libadbd_fs/Android.bp new file mode 100644 index 000000000..d17814825 --- /dev/null +++ b/adb/libs/libadbd_fs/Android.bp @@ -0,0 +1,30 @@ +// libadbd_fs +// ========================================================= +cc_library { + name: "libadbd_fs", + defaults: ["adbd_defaults"], + + srcs: ["adbd_fs.cpp"], + static_libs: [ + "libbase", + "libcutils", + "liblog", + ], + export_include_dirs: ["include"], + + version_script: "libadbd_fs.map.txt", + stubs: { + versions: ["1"], + symbol_file: "libadbd_fs.map.txt", + }, + + host_supported: true, + recovery_available: true, + compile_multilib: "both", + + target: { + darwin: { + enabled: false, + } + }, +} diff --git a/adb/libs/libadbd_fs/adbd_fs.cpp b/adb/libs/libadbd_fs/adbd_fs.cpp new file mode 100644 index 000000000..8e62d40d1 --- /dev/null +++ b/adb/libs/libadbd_fs/adbd_fs.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2020 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. + */ + +#include + +#include + +void adbd_fs_config(const char* path, int dir, const char* target_out_path, uid_t* uid, gid_t* gid, + mode_t* mode, uint64_t* capabilities) { + unsigned uid_hack; + unsigned gid_hack; + unsigned mode_hack; + fs_config(path, dir, target_out_path, &uid_hack, &gid_hack, &mode_hack, capabilities); + *uid = uid_hack; + *gid = gid_hack; + *mode = mode_hack; +} diff --git a/adb/libs/libadbd_fs/include/adbd_fs.h b/adb/libs/libadbd_fs/include/adbd_fs.h new file mode 100644 index 000000000..6158d7208 --- /dev/null +++ b/adb/libs/libadbd_fs/include/adbd_fs.h @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2020 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 + +#include +#include + +extern "C" { +// Thin wrapper around libcutils fs_config. +void adbd_fs_config(const char* path, int dir, const char* target_out_path, uid_t* uid, gid_t* gid, + mode_t* mode, uint64_t* capabilities); +} diff --git a/adb/libs/libadbd_fs/libadbd_fs.map.txt b/adb/libs/libadbd_fs/libadbd_fs.map.txt new file mode 100644 index 000000000..1454e9639 --- /dev/null +++ b/adb/libs/libadbd_fs/libadbd_fs.map.txt @@ -0,0 +1,6 @@ +LIBADBD_FS { + global: + adbd_fs_config; # apex + local: + *; +}; diff --git a/libcutils/Android.bp b/libcutils/Android.bp index 0379f6e2e..4e93df370 100644 --- a/libcutils/Android.bp +++ b/libcutils/Android.bp @@ -21,11 +21,6 @@ libcutils_nonwindows_sources = [ "fs.cpp", "hashmap.cpp", "multiuser.cpp", - "socket_inaddr_any_server_unix.cpp", - "socket_local_client_unix.cpp", - "socket_local_server_unix.cpp", - "socket_network_client_unix.cpp", - "sockets_unix.cpp", "str_parms.cpp", ] @@ -49,6 +44,90 @@ cc_library_headers { }, } +// Socket specific parts of libcutils that are safe to statically link into an APEX. +cc_library_static { + name: "libcutils_sockets", + vendor_available: true, + vndk: { + enabled: true, + support_system_process: true, + }, + recovery_available: true, + host_supported: true, + native_bridge_supported: true, + apex_available: [ + "//apex_available:platform", + "//apex_available:anyapex", + ], + + export_include_dirs: ["include"], + + srcs: ["sockets.cpp"], + target: { + linux_bionic: { + enabled: true, + }, + + not_windows: { + srcs: [ + "socket_inaddr_any_server_unix.cpp", + "socket_local_client_unix.cpp", + "socket_local_server_unix.cpp", + "socket_network_client_unix.cpp", + "sockets_unix.cpp", + ], + }, + + // "not_windows" means "non-Windows host". + android: { + srcs: [ + "android_get_control_file.cpp", + "socket_inaddr_any_server_unix.cpp", + "socket_local_client_unix.cpp", + "socket_local_server_unix.cpp", + "socket_network_client_unix.cpp", + "sockets_unix.cpp", + ], + static_libs: ["libbase"], + }, + + windows: { + host_ldlibs: ["-lws2_32"], + srcs: [ + "socket_inaddr_any_server_windows.cpp", + "socket_network_client_windows.cpp", + "sockets_windows.cpp", + ], + + enabled: true, + cflags: [ + "-D_GNU_SOURCE", + ], + }, + }, +} + +cc_test { + name: "libcutils_sockets_test", + test_suites: ["device-tests"], + static_libs: ["libbase", "libcutils_sockets"], + cflags: [ + "-Wall", + "-Wextra", + "-Werror", + ], + + srcs: ["sockets_test.cpp"], + target: { + android: { + srcs: [ + "android_get_control_file_test.cpp", + "android_get_control_socket_test.cpp", + ], + }, + }, +} + cc_library { name: "libcutils", vendor_available: true, @@ -66,7 +145,6 @@ cc_library { "load_file.cpp", "native_handle.cpp", "record_stream.cpp", - "sockets.cpp", "strlcpy.c", "threads.cpp", ], @@ -86,9 +164,6 @@ cc_library { host_ldlibs: ["-lws2_32"], srcs: [ - "socket_inaddr_any_server_windows.cpp", - "socket_network_client_windows.cpp", - "sockets_windows.cpp", "trace-host.cpp", ], @@ -97,10 +172,8 @@ cc_library { "-D_GNU_SOURCE", ], }, - android: { srcs: libcutils_nonwindows_sources + [ - "android_get_control_file.cpp", "android_reboot.cpp", "ashmem-dev.cpp", "fs_config.cpp", @@ -149,6 +222,7 @@ cc_library { } }, + whole_static_libs: ["libcutils_sockets"], shared_libs: [ "liblog", "libbase", From 8cc8d32b1bd96da4cd49d6b4d2928164c85e51b6 Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Fri, 21 Feb 2020 16:38:29 -0800 Subject: [PATCH 08/15] adbd: fix build breakage. This broke because two CLs touching the Android.bp file both independently passed presubmit, but failed when combined. Clean up a misindentation while we're at it. Bug: http://b/150032044 Bug: http://b/150032367 Test: mma in system/core/adb Change-Id: I091ef9dec806c767ffb21a5fd73b2bb37ab29ff9 Merged-In: I091ef9dec806c767ffb21a5fd73b2bb37ab29ff9 (cherry picked from commit 6d949e89a47e4876b835fe95d3299699da0bba92) (cherry picked from commit 3467ef46d436985408c7b126a0e746cd5bb8b2be) --- adb/Android.bp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/adb/Android.bp b/adb/Android.bp index 2f1fe3ca0..fea8c7807 100644 --- a/adb/Android.bp +++ b/adb/Android.bp @@ -375,7 +375,7 @@ cc_library_static { srcs: libadb_srcs + libadb_linux_srcs + libadb_posix_srcs + [ "daemon/auth.cpp", "daemon/jdwp_service.cpp", - "daemon/adb_wifi.cpp", + "daemon/adb_wifi.cpp", ], local_include_dirs: [ @@ -516,6 +516,7 @@ cc_library { "libadbd_services", "libcutils_sockets", "libdiagnose_usb", + "libmdnssd", ], export_include_dirs: [ From 920e0ee6b680dae03502d60d4b9b66b3f36c79f1 Mon Sep 17 00:00:00 2001 From: Joshua Duong Date: Mon, 24 Feb 2020 10:03:54 -0800 Subject: [PATCH 09/15] Properly remove adb DNS services. Bug: b/150136878 Bug: b/111434128 Bug: http://b/150032044 Test: make Change-Id: Ibfb92a7c197a25fd1913107d277fbc5f78108c05 Merged-In: Ibfb92a7c197a25fd1913107d277fbc5f78108c05 (cherry picked from commit 79a452a923057a8f8fb6fa4bf9075e71c7a737e4) (cherry picked from commit e36a53e3076d38674fc4ddb200c19f1c5de6bcdd) --- adb/client/transport_mdns.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/adb/client/transport_mdns.cpp b/adb/client/transport_mdns.cpp index ff1f7b4c6..22b9b1808 100644 --- a/adb/client/transport_mdns.cpp +++ b/adb/client/transport_mdns.cpp @@ -409,9 +409,9 @@ static void adb_RemoveDNSService(const char* regType, const char* serviceName) { } std::string sName(serviceName); - std::remove_if(services->begin(), services->end(), [&sName](ResolvedService* service) { - return (sName == service->serviceName()); - }); + services->erase(std::remove_if( + services->begin(), services->end(), + [&sName](ResolvedService* service) { return (sName == service->serviceName()); })); } // Returns the version the device wanted to advertise, From 4eb98033a604898cbc96406d1e76b579568abae4 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 21 Feb 2020 17:11:07 -0800 Subject: [PATCH 10/15] init: Make sure ImageManager status files are labelled. adb remount and snapshot-based updates use ImageManager in first-stage init. This creates status files, which need to be labelled. Bug: 148834619 Test: manual test Change-Id: I72949fca2889f9e5612049844a78bf9355b48797 Merged-In: I72949fca2889f9e5612049844a78bf9355b48797 (cherry picked from commit 960a81f4a1055ea72e53ac361a45e93dfa903447) --- init/selinux.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/init/selinux.cpp b/init/selinux.cpp index c5b7576c9..2faa16720 100644 --- a/init/selinux.cpp +++ b/init/selinux.cpp @@ -535,7 +535,9 @@ void SelinuxRestoreContext() { selinux_android_restorecon("/linkerconfig", 0); - selinux_android_restorecon(gsi::kDsuAvbKeyDir, SELINUX_ANDROID_RESTORECON_RECURSE); + // adb remount, snapshot-based updates, and DSUs all create files during + // first-stage init. + selinux_android_restorecon("/metadata", SELINUX_ANDROID_RESTORECON_RECURSE); } int SelinuxKlogCallback(int type, const char* fmt, ...) { From a49bc6167be19b8ce47598f4a453c67098e43f46 Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Thu, 20 Feb 2020 17:54:57 -0800 Subject: [PATCH 11/15] init: restorecon libsnapshot rollback indicator The rollback indicator is created during first stage init and is unlabeled. Need to restorecon it properly so that it can be properly deleted by update_engine later. Bug: 149956852 Bug: 150907679 Test: apply OTA, reboot, look at serial console Change-Id: Ie954023b557865691fec2ae378145596bf1973a9 (cherry picked from commit dd4e7ef6ce7e40d8922d0d6bdca0d59121c36759) --- fs_mgr/libsnapshot/include/libsnapshot/snapshot.h | 3 +++ fs_mgr/libsnapshot/snapshot.cpp | 7 ++++++- init/selinux.cpp | 4 ++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/fs_mgr/libsnapshot/include/libsnapshot/snapshot.h b/fs_mgr/libsnapshot/include/libsnapshot/snapshot.h index 32345d26f..81f616ce6 100644 --- a/fs_mgr/libsnapshot/include/libsnapshot/snapshot.h +++ b/fs_mgr/libsnapshot/include/libsnapshot/snapshot.h @@ -125,6 +125,9 @@ class SnapshotManager final { // might be needed to perform first-stage mounts. static bool IsSnapshotManagerNeeded(); + // Helper function for second stage init to restorecon on the rollback indicator. + static std::string GetGlobalRollbackIndicatorPath(); + // Begin an update. This must be called before creating any snapshots. It // will fail if GetUpdateState() != None. bool BeginUpdate(); diff --git a/fs_mgr/libsnapshot/snapshot.cpp b/fs_mgr/libsnapshot/snapshot.cpp index 61fc2dff6..154b5d755 100644 --- a/fs_mgr/libsnapshot/snapshot.cpp +++ b/fs_mgr/libsnapshot/snapshot.cpp @@ -81,6 +81,7 @@ using namespace std::chrono_literals; using namespace std::string_literals; static constexpr char kBootIndicatorPath[] = "/metadata/ota/snapshot-boot"; +static constexpr char kRollbackIndicatorPath[] = "/metadata/ota/rollback-indicator"; static constexpr auto kUpdateStateCheckInterval = 2s; // Note: IImageManager is an incomplete type in the header, so the default @@ -1012,7 +1013,7 @@ std::string SnapshotManager::GetSnapshotBootIndicatorPath() { } std::string SnapshotManager::GetRollbackIndicatorPath() { - return metadata_dir_ + "/rollback-indicator"; + return metadata_dir_ + "/" + android::base::Basename(kRollbackIndicatorPath); } void SnapshotManager::AcknowledgeMergeSuccess(LockedFile* lock) { @@ -1469,6 +1470,10 @@ bool SnapshotManager::IsSnapshotManagerNeeded() { return access(kBootIndicatorPath, F_OK) == 0; } +std::string SnapshotManager::GetGlobalRollbackIndicatorPath() { + return kRollbackIndicatorPath; +} + bool SnapshotManager::NeedSnapshotsInFirstStageMount() { // If we fail to read, we'll wind up using CreateLogicalPartitions, which // will create devices that look like the old slot, except with extra diff --git a/init/selinux.cpp b/init/selinux.cpp index 2faa16720..acbcbd647 100644 --- a/init/selinux.cpp +++ b/init/selinux.cpp @@ -66,6 +66,7 @@ #include #include #include +#include #include #include "debug_ramdisk.h" @@ -78,6 +79,7 @@ using android::base::ParseInt; using android::base::Timer; using android::base::unique_fd; using android::fs_mgr::AvbHandle; +using android::snapshot::SnapshotManager; namespace android { namespace init { @@ -538,6 +540,8 @@ void SelinuxRestoreContext() { // adb remount, snapshot-based updates, and DSUs all create files during // first-stage init. selinux_android_restorecon("/metadata", SELINUX_ANDROID_RESTORECON_RECURSE); + + selinux_android_restorecon(SnapshotManager::GetGlobalRollbackIndicatorPath().c_str(), 0); } int SelinuxKlogCallback(int type, const char* fmt, ...) { From 88e9401f9a7cdfdec2ef9f1724841137057328a7 Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Mon, 9 Mar 2020 15:20:55 -0700 Subject: [PATCH 12/15] adbd: make libadbd_services cc_library again. For currently unknown reasons, sideloading is broken with libadbd_services as a cc_library_static. Partial revert of commit a9b62d545275ca32775a0bc5f004abe03aaa38ad. Bug: http://b/151056300 Test: xunchang@ tested manually Change-Id: Iaffad9c476ba0adcffc5db512ba4a7ee0fb5cb22 (cherry picked from commit 7f8a37c8c7b038f1ea1a91a0ab91c503dcf7d7e6) --- adb/Android.bp | 5 +++-- libcutils/Android.bp | 7 ++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/adb/Android.bp b/adb/Android.bp index a26017fc2..e02a54e64 100644 --- a/adb/Android.bp +++ b/adb/Android.bp @@ -429,7 +429,7 @@ cc_library_static { }, } -cc_library_static { +cc_library { name: "libadbd_services", defaults: ["adbd_defaults", "host_adbd_supported"], recovery_available: true, @@ -464,6 +464,7 @@ cc_library_static { "libbase", "libcrypto", "libcrypto_utils", + "libcutils_sockets", "liblog", ], @@ -515,6 +516,7 @@ cc_library { "libadb_tls_connection", "libadbd_auth", "libadbd_fs", + "libadbd_services", "libasyncio", "libbase", "libcrypto", @@ -533,7 +535,6 @@ cc_library { }, static_libs: [ - "libadbd_services", "libcutils_sockets", "libdiagnose_usb", "libmdnssd", diff --git a/libcutils/Android.bp b/libcutils/Android.bp index 4e93df370..fc06c1d1b 100644 --- a/libcutils/Android.bp +++ b/libcutils/Android.bp @@ -45,13 +45,9 @@ cc_library_headers { } // Socket specific parts of libcutils that are safe to statically link into an APEX. -cc_library_static { +cc_library { name: "libcutils_sockets", vendor_available: true, - vndk: { - enabled: true, - support_system_process: true, - }, recovery_available: true, host_supported: true, native_bridge_supported: true, @@ -62,6 +58,7 @@ cc_library_static { export_include_dirs: ["include"], + shared_libs: ["liblog"], srcs: ["sockets.cpp"], target: { linux_bionic: { From 91a32148fe182fbad99dfe459c711b224353bbf0 Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Mon, 9 Mar 2020 15:20:55 -0700 Subject: [PATCH 13/15] adbd: make libadbd_services cc_library again. For currently unknown reasons, sideloading is broken with libadbd_services as a cc_library_static. Partial revert of commit a9b62d545275ca32775a0bc5f004abe03aaa38ad. Bug: http://b/151056300 Test: xunchang@ tested manually Change-Id: Iaffad9c476ba0adcffc5db512ba4a7ee0fb5cb22 (cherry picked from commit 7f8a37c8c7b038f1ea1a91a0ab91c503dcf7d7e6) (cherry picked from commit cc8e30e9aa7f0459707337a289e269820d8006c4) --- adb/Android.bp | 5 +++-- libcutils/Android.bp | 7 ++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/adb/Android.bp b/adb/Android.bp index a26017fc2..e02a54e64 100644 --- a/adb/Android.bp +++ b/adb/Android.bp @@ -429,7 +429,7 @@ cc_library_static { }, } -cc_library_static { +cc_library { name: "libadbd_services", defaults: ["adbd_defaults", "host_adbd_supported"], recovery_available: true, @@ -464,6 +464,7 @@ cc_library_static { "libbase", "libcrypto", "libcrypto_utils", + "libcutils_sockets", "liblog", ], @@ -515,6 +516,7 @@ cc_library { "libadb_tls_connection", "libadbd_auth", "libadbd_fs", + "libadbd_services", "libasyncio", "libbase", "libcrypto", @@ -533,7 +535,6 @@ cc_library { }, static_libs: [ - "libadbd_services", "libcutils_sockets", "libdiagnose_usb", "libmdnssd", diff --git a/libcutils/Android.bp b/libcutils/Android.bp index 4e93df370..fc06c1d1b 100644 --- a/libcutils/Android.bp +++ b/libcutils/Android.bp @@ -45,13 +45,9 @@ cc_library_headers { } // Socket specific parts of libcutils that are safe to statically link into an APEX. -cc_library_static { +cc_library { name: "libcutils_sockets", vendor_available: true, - vndk: { - enabled: true, - support_system_process: true, - }, recovery_available: true, host_supported: true, native_bridge_supported: true, @@ -62,6 +58,7 @@ cc_library_static { export_include_dirs: ["include"], + shared_libs: ["liblog"], srcs: ["sockets.cpp"], target: { linux_bionic: { From f87bbbafab8245b7ee1458eeb83de693bea02d03 Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Mon, 9 Mar 2020 15:20:55 -0700 Subject: [PATCH 14/15] adbd: make libadbd_services cc_library again. For currently unknown reasons, sideloading is broken with libadbd_services as a cc_library_static. Partial revert of commit a9b62d545275ca32775a0bc5f004abe03aaa38ad. Bug: http://b/151056300 Test: xunchang@ tested manually Change-Id: Iaffad9c476ba0adcffc5db512ba4a7ee0fb5cb22 (cherry picked from commit 7f8a37c8c7b038f1ea1a91a0ab91c503dcf7d7e6) (cherry picked from commit d1ee5085f3bb08e5ad6dca077c311c4538f406d0) --- adb/Android.bp | 5 +++-- libcutils/Android.bp | 7 ++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/adb/Android.bp b/adb/Android.bp index a26017fc2..e02a54e64 100644 --- a/adb/Android.bp +++ b/adb/Android.bp @@ -429,7 +429,7 @@ cc_library_static { }, } -cc_library_static { +cc_library { name: "libadbd_services", defaults: ["adbd_defaults", "host_adbd_supported"], recovery_available: true, @@ -464,6 +464,7 @@ cc_library_static { "libbase", "libcrypto", "libcrypto_utils", + "libcutils_sockets", "liblog", ], @@ -515,6 +516,7 @@ cc_library { "libadb_tls_connection", "libadbd_auth", "libadbd_fs", + "libadbd_services", "libasyncio", "libbase", "libcrypto", @@ -533,7 +535,6 @@ cc_library { }, static_libs: [ - "libadbd_services", "libcutils_sockets", "libdiagnose_usb", "libmdnssd", diff --git a/libcutils/Android.bp b/libcutils/Android.bp index 4e93df370..fc06c1d1b 100644 --- a/libcutils/Android.bp +++ b/libcutils/Android.bp @@ -45,13 +45,9 @@ cc_library_headers { } // Socket specific parts of libcutils that are safe to statically link into an APEX. -cc_library_static { +cc_library { name: "libcutils_sockets", vendor_available: true, - vndk: { - enabled: true, - support_system_process: true, - }, recovery_available: true, host_supported: true, native_bridge_supported: true, @@ -62,6 +58,7 @@ cc_library_static { export_include_dirs: ["include"], + shared_libs: ["liblog"], srcs: ["sockets.cpp"], target: { linux_bionic: { From bad50ed24f9d48d001fcedd332d59f162dc3432d Mon Sep 17 00:00:00 2001 From: Steven Moreland Date: Tue, 28 Jul 2020 21:41:54 +0000 Subject: [PATCH 15/15] libutils: check vsnprintf error For encoding errors, this function will return a negative value which causes problems down the line. Check for an error and return. Also, integer overflows are guarded. Bug: 161894517 Test: fuzzer test case Change-Id: Ia85067d4258bde4b875c832d6223db5dd26b8838 Merged-In: Ia85067d4258bde4b875c832d6223db5dd26b8838 (cherry picked from commit ee22384c54d42149491c8b9dbcda0d8c5e88eddc) --- libutils/String8.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libutils/String8.cpp b/libutils/String8.cpp index d13548e4c..9d50e0bc5 100644 --- a/libutils/String8.cpp +++ b/libutils/String8.cpp @@ -322,8 +322,14 @@ status_t String8::appendFormatV(const char* fmt, va_list args) n = vsnprintf(nullptr, 0, fmt, tmp_args); va_end(tmp_args); - if (n != 0) { + if (n < 0) return UNKNOWN_ERROR; + + if (n > 0) { size_t oldLength = length(); + if ((size_t)n > SIZE_MAX - 1 || + oldLength > SIZE_MAX - (size_t)n - 1) { + return NO_MEMORY; + } char* buf = lockBuffer(oldLength + n); if (buf) { vsnprintf(buf + oldLength, n + 1, fmt, args);