Skip RegisterSecurityContextForPath in recovery 34/286634/5
authorilho kim <ilho159.kim@samsung.com>
Tue, 10 Jan 2023 13:18:13 +0000 (22:18 +0900)
committerilho kim <ilho159.kim@samsung.com>
Wed, 8 Feb 2023 11:50:43 +0000 (20:50 +0900)
RegisterSecurityContextForPath call is applied to the security manager
database if "owner rw, other ro" exist in the path
In other cases, there is no need to call the function because it only
apply a smack label. Because the smack label is already applied to the
file during package recovery

Change-Id: Ice4fcab75ed67dcf3d8ecae7d4a632a36e6bfda5
Signed-off-by: ilho kim <ilho159.kim@samsung.com>
src/common/security_registration.cc
src/common/security_registration.h
src/common/step/security/step_recover_security.cc

index baabe1b..c08992b 100644 (file)
@@ -590,4 +590,18 @@ bool RegisterSecurityContextForPathExternalOnly(const std::string &pkg_id,
   return result;
 }
 
+bool HasOwnerRwOtherRoPaths(const boost::filesystem::path& path) {
+  for (auto& policy : kSecurityPolicies) {
+    if (policy.second != SECURITY_MANAGER_PATH_OWNER_RW_OTHER_RO)
+      continue;
+
+    bf::path subpath = path / policy.first;
+    LOG(ERROR) << "subpath : " << subpath;
+    if (bf::exists(subpath))
+      return true;
+  }
+
+  return false;
+}
+
 }  // namespace common_installer
index 4b09698..9eb1227 100644 (file)
@@ -105,6 +105,8 @@ bool RegisterSecurityContextForPathExternalOnly(const std::string &pkg_id,
     const std::string &pkg_type, const boost::filesystem::path& path,
     uid_t uid, std::string* error_message);
 
+bool HasOwnerRwOtherRoPaths(const boost::filesystem::path& path);
+
 }  // namespace common_installer
 
 #endif  // COMMON_SECURITY_REGISTRATION_H_
index ae59eaa..c9c061a 100644 (file)
@@ -75,6 +75,10 @@ Step::Status StepRecoverSecurity::RecoveryUpdate() {
     }
     return Status::RECOVERY_ERROR;
   }
+
+  if (!HasOwnerRwOtherRoPaths(context_->GetPkgPath()))
+    return Status::OK;
+
   if (!RegisterSecurityContextForPath(
       context_->pkgid.get(), context_->GetPkgPath(), context_->uid.get(),
       context_->is_readonly_package.get(), &error_message)) {