diff options
author | Weilin Wu <wlogsky@google.com> | 2024-04-01 06:16:30 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2024-04-01 06:16:30 +0000 |
commit | 5fd1f1787613db42d28886dd06038dd18bec5d35 (patch) | |
tree | df2168936d1d81831b548e00a1e958445beb8356 | |
parent | ba1f12119170f8edae8d17d905c2a27614a67f95 (diff) | |
download | adb-5fd1f1787613db42d28886dd06038dd18bec5d35.tar.gz |
Revert "adb: Do not use fs_config unless we are root (try 2)."
Revert submission 3001420-main-Ied805bc3912ea0b4e1691127b5032aef632f85fd
Reason for revert: DroidMonitor: Potential culprit for Bug 331999499 - verifying through ABTD before revert submission. This is part of the standard investigation process, and does not mean your CL will be reverted.
Reverted changes: /q/submissionid:3001420-main-Ied805bc3912ea0b4e1691127b5032aef632f85fd
Change-Id: I26437c5af8e297dd528f79821de1280638f9380d
-rw-r--r-- | daemon/file_sync_service.cpp | 18 | ||||
-rw-r--r-- | libs/libadbd_fs/adbd_fs.cpp | 19 | ||||
-rw-r--r-- | libs/libadbd_fs/include/adbd_fs.h | 2 |
3 files changed, 23 insertions, 16 deletions
diff --git a/daemon/file_sync_service.cpp b/daemon/file_sync_service.cpp index ab20e582..5891d30e 100644 --- a/daemon/file_sync_service.cpp +++ b/daemon/file_sync_service.cpp @@ -68,6 +68,16 @@ using android::base::Dirname; using android::base::Realpath; using android::base::StringPrintf; +static bool should_use_fs_config(const std::string& path) { +#if defined(__ANDROID__) + // TODO: use fs_config to configure permissions on /data too. + return !android::base::StartsWith(path, "/data/"); +#else + UNUSED(path); + return false; +#endif +} + static bool update_capabilities(const char* path, uint64_t capabilities) { #if defined(__ANDROID__) if (capabilities == 0) { @@ -109,7 +119,9 @@ static bool secure_mkdirs(const std::string& path) { } partial_path += path_component; - adbd_fs_config(partial_path.c_str(), true, nullptr, &uid, &gid, &mode, &capabilities); + if (should_use_fs_config(partial_path)) { + 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) { return false; @@ -518,8 +530,8 @@ static bool send_impl(int s, const std::string& path, mode_t mode, CompressionTy uid_t uid = -1; gid_t gid = -1; uint64_t capabilities = 0; - if (!dry_run) { - adbd_fs_config(path.c_str(), false, nullptr, &uid, &gid, &mode, &capabilities); + if (should_use_fs_config(path) && !dry_run) { + 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, diff --git a/libs/libadbd_fs/adbd_fs.cpp b/libs/libadbd_fs/adbd_fs.cpp index e2425ef3..8e62d40d 100644 --- a/libs/libadbd_fs/adbd_fs.cpp +++ b/libs/libadbd_fs/adbd_fs.cpp @@ -17,19 +17,14 @@ #include <adbd_fs.h> #include <private/fs_config.h> -#include <unistd.h> 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) { - // Only root has the necessary permissions to be able to apply fs_config. - if (getuid() != 0) { - return; - } - struct fs_config conf; - if (get_fs_config(path, dir, target_out_path, &conf)) { - *uid = conf.uid; - *gid = conf.gid; - *mode = conf.mode; - *capabilities = conf.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/libs/libadbd_fs/include/adbd_fs.h b/libs/libadbd_fs/include/adbd_fs.h index 1c0895c6..6158d720 100644 --- a/libs/libadbd_fs/include/adbd_fs.h +++ b/libs/libadbd_fs/include/adbd_fs.h @@ -20,7 +20,7 @@ #include <sys/types.h> extern "C" { -// Thin wrapper around libcutils get_fs_config. +// 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); } |