From aee11b0a3da5bbfd09d258278700b358a8691151 Mon Sep 17 00:00:00 2001 From: Dan Shi Date: Fri, 19 Aug 2022 18:40:14 +0000 Subject: [PATCH] Revert "libprocessgroup: Add support for SetUserProfiles" Revert "Freeze package cgroup before killing" Revert submission 19436294-freeze_kill Reason for revert: b/243096961 Reverted Changes: I06aaa5a08:Freeze package cgroup before killing I45e34244f:libprocessgroup: Add support for SetUserProfiles Bug: 243096961 Change-Id: I32162341d6a38f458a9c59d63e0cdc56a97f1efe --- .../include/processgroup/processgroup.h | 1 - libprocessgroup/processgroup.cpp | 4 -- libprocessgroup/task_profiles.cpp | 66 ------------------- libprocessgroup/task_profiles.h | 6 -- libprocessgroup/task_profiles_test.cpp | 4 -- 5 files changed, 81 deletions(-) diff --git a/libprocessgroup/include/processgroup/processgroup.h b/libprocessgroup/include/processgroup/processgroup.h index 32479e458..39b9f3fc0 100644 --- a/libprocessgroup/include/processgroup/processgroup.h +++ b/libprocessgroup/include/processgroup/processgroup.h @@ -32,7 +32,6 @@ bool CgroupGetAttributePathForTask(const std::string& attr_name, int tid, std::s bool SetTaskProfiles(int tid, const std::vector& profiles, bool use_fd_cache = false); bool SetProcessProfiles(uid_t uid, pid_t pid, const std::vector& profiles); -bool SetUserProfiles(uid_t uid, const std::vector& profiles); #ifndef __ANDROID_VNDK__ diff --git a/libprocessgroup/processgroup.cpp b/libprocessgroup/processgroup.cpp index b1ce8af1f..51c810e98 100644 --- a/libprocessgroup/processgroup.cpp +++ b/libprocessgroup/processgroup.cpp @@ -174,10 +174,6 @@ extern "C" bool android_set_process_profiles(uid_t uid, pid_t pid, size_t num_pr return SetProcessProfiles(uid, pid, profiles_); } -bool SetUserProfiles(uid_t uid, const std::vector& profiles) { - return TaskProfiles::GetInstance().SetUserProfiles(uid, profiles, false); -} - static std::string ConvertUidToPath(const char* cgroup, uid_t uid) { return StringPrintf("%s/uid_%d", cgroup, uid); } diff --git a/libprocessgroup/task_profiles.cpp b/libprocessgroup/task_profiles.cpp index 9dfc0ba9a..e1c593407 100644 --- a/libprocessgroup/task_profiles.cpp +++ b/libprocessgroup/task_profiles.cpp @@ -139,19 +139,6 @@ bool ProfileAttribute::GetPathForTask(int tid, std::string* path) const { return true; } -bool ProfileAttribute::GetPathForUID(uid_t uid, std::string* path) const -{ - if (path == nullptr) { - return true; - } - - const std::string& file_name = - controller()->version() == 2 && !file_v2_name_.empty() ? file_v2_name_ : file_name_; - *path = StringPrintf("%s/uid_%d/%s", controller()->path(), uid, file_name.c_str()); - return true; -} - - bool SetClampsAction::ExecuteForProcess(uid_t, pid_t) const { // TODO: add support when kernel supports util_clamp LOG(WARNING) << "SetClampsAction::ExecuteForProcess is not supported"; @@ -238,31 +225,6 @@ bool SetAttributeAction::ExecuteForTask(int tid) const { return true; } -bool SetAttributeAction::ExecuteForUID(uid_t uid) const -{ - std::string path; - - if (!attribute_->GetPathForUID(uid, &path)) { - LOG(ERROR) << "Failed to find cgroup for uid " << uid; - return false; - } - - if (!WriteStringToFile(value_, path)) { - if (access(path.c_str(), F_OK) < 0) { - if (optional_) { - return true; - } else { - LOG(ERROR) << "No such cgroup attribute: " << path; - return false; - } - } - PLOG(ERROR) << "Failed to write '" << value_ << "' to " << path; - return false; - } - return true; -} - - SetCgroupAction::SetCgroupAction(const CgroupController& c, const std::string& p) : controller_(c), path_(p) { FdCacheHelper::Init(controller_.GetTasksFilePath(path_), fd_[ProfileAction::RCT_TASK]); @@ -590,16 +552,6 @@ bool TaskProfile::ExecuteForTask(int tid) const { return true; } -bool TaskProfile::ExecuteForUID(uid_t uid) const { - for (const auto& element : elements_) { - if (!element->ExecuteForUID(uid)) { - LOG(VERBOSE) << "Applying profile action " << element->Name() << " failed"; - return false; - } - } - return true; -} - void TaskProfile::EnableResourceCaching(ProfileAction::ResourceCacheType cache_type) { if (res_cached_) { return; @@ -852,24 +804,6 @@ const IProfileAttribute* TaskProfiles::GetAttribute(const std::string& name) con return nullptr; } -bool TaskProfiles::SetUserProfiles(uid_t uid, const std::vector& profiles, - bool use_fd_cache) { - for (const auto& name : profiles) { - TaskProfile* profile = GetProfile(name); - if (profile != nullptr) { - if (use_fd_cache) { - profile->EnableResourceCaching(ProfileAction::RCT_PROCESS); - } - if (!profile->ExecuteForUID(uid)) { - PLOG(WARNING) << "Failed to apply " << name << " process profile"; - } - } else { - PLOG(WARNING) << "Failed to find " << name << "process profile"; - } - } - return true; -} - bool TaskProfiles::SetProcessProfiles(uid_t uid, pid_t pid, const std::vector& profiles, bool use_fd_cache) { bool success = true; diff --git a/libprocessgroup/task_profiles.h b/libprocessgroup/task_profiles.h index cdd9b42a2..df08f65c7 100644 --- a/libprocessgroup/task_profiles.h +++ b/libprocessgroup/task_profiles.h @@ -33,7 +33,6 @@ class IProfileAttribute { virtual const CgroupController* controller() const = 0; virtual const std::string& file_name() const = 0; virtual bool GetPathForTask(int tid, std::string* path) const = 0; - virtual bool GetPathForUID(uid_t uid, std::string* path) const = 0; }; class ProfileAttribute : public IProfileAttribute { @@ -51,7 +50,6 @@ class ProfileAttribute : public IProfileAttribute { void Reset(const CgroupController& controller, const std::string& file_name) override; bool GetPathForTask(int tid, std::string* path) const override; - bool GetPathForUID(uid_t uid, std::string* path) const override; private: CgroupController controller_; @@ -71,7 +69,6 @@ class ProfileAction { // Default implementations will fail virtual bool ExecuteForProcess(uid_t, pid_t) const { return false; }; virtual bool ExecuteForTask(int) const { return false; }; - virtual bool ExecuteForUID(uid_t) const { return false; }; virtual void EnableResourceCaching(ResourceCacheType) {} virtual void DropResourceCaching(ResourceCacheType) {} @@ -116,7 +113,6 @@ class SetAttributeAction : public ProfileAction { const char* Name() const override { return "SetAttribute"; } bool ExecuteForProcess(uid_t uid, pid_t pid) const override; bool ExecuteForTask(int tid) const override; - bool ExecuteForUID(uid_t uid) const override; private: const IProfileAttribute* attribute_; @@ -180,7 +176,6 @@ class TaskProfile { bool ExecuteForProcess(uid_t uid, pid_t pid) const; bool ExecuteForTask(int tid) const; - bool ExecuteForUID(uid_t uid) const; void EnableResourceCaching(ProfileAction::ResourceCacheType cache_type); void DropResourceCaching(ProfileAction::ResourceCacheType cache_type); @@ -217,7 +212,6 @@ class TaskProfiles { bool SetProcessProfiles(uid_t uid, pid_t pid, const std::vector& profiles, bool use_fd_cache); bool SetTaskProfiles(int tid, const std::vector& profiles, bool use_fd_cache); - bool SetUserProfiles(uid_t uid, const std::vector& profiles, bool use_fd_cache); private: std::map> profiles_; diff --git a/libprocessgroup/task_profiles_test.cpp b/libprocessgroup/task_profiles_test.cpp index fed819e53..09ac44c6b 100644 --- a/libprocessgroup/task_profiles_test.cpp +++ b/libprocessgroup/task_profiles_test.cpp @@ -121,10 +121,6 @@ class ProfileAttributeMock : public IProfileAttribute { return true; }; - bool GetPathForUID(uid_t, std::string *) const override { - return false; - } - private: const std::string file_name_; };