Fix security-manager worker 76/231576/1
authorDariusz Michaluk <d.michaluk@samsung.com>
Tue, 14 Apr 2020 13:09:35 +0000 (15:09 +0200)
committerDariusz Michaluk <d.michaluk@samsung.com>
Wed, 22 Apr 2020 11:43:42 +0000 (13:43 +0200)
Move worker process to main mount namespace after finishing job.

Change-Id: Ic0ed8011ecc8fab04a237c6a96190f4a8cc5d266

src/common/worker.cpp

index 466f50dac01ccab63611ab89229324da312217e6..70d0d4a6096454205510ab007f9a765b25c82d4c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2017 - 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2017 - 2020 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *  Contact: Tomasz Swierczek <t.swierczek@samsung.com>
  *
@@ -40,29 +40,22 @@ Worker::Worker(Channel channel)
 int Worker::doWork(const NSMountLogic::EntryVector &entries)
 {
     int status = 0;
-    bool inGlobalNamespace = false;
+    bool inGlobalNamespace = true;
 
     for (auto &entry : entries) {
         try {
-            // in most cases entry.uid will not change between iterations
-            auto storagePrivilegePathMap = MountNS::getPrivilegePathMap(entry.uid);
-
-            if (!inGlobalNamespace && MountNS::enterMountNamespace(MountNS::MAIN_MOUNT_NAMESPACE)) {
-                inGlobalNamespace = true;
-            }
-
-            if (!inGlobalNamespace) {
-                LogError("Error entering global mount namespace. Environment of application: "
-                         << entry.smackLabel << " will not be setup correctly.");
-                continue;
-            }
-
-            if (MountNS::enterMountNamespace(MountNS::getUserAppServiceMountPointPath(entry.uid, entry.smackLabel, entry.pid))) {
+            auto appNamespace = MountNS::getUserAppServiceMountPointPath(entry.uid, entry.smackLabel, entry.pid);
+            if (MountNS::enterMountNamespace(appNamespace)) {
                 inGlobalNamespace = false;
             } else {
+                status = -1;
+                LogError("Error entering app mount namespace. Environment of application: "
+                         << entry.smackLabel <<  "for user: " << entry.uid << " will not be setup correctly.");
                 continue;
             }
 
+            // in most cases entry.uid will not change between iterations
+            auto storagePrivilegePathMap = MountNS::getPrivilegePathMap(entry.uid);
             for (auto &privStatus : entry.privilegeStatusVector) {
                 auto &privName = privStatus.first;
                 auto &allowed  = privStatus.second;
@@ -77,13 +70,22 @@ int Worker::doWork(const NSMountLogic::EntryVector &entries)
                                    "directory " << privilegePath.dstPath << " doesn't exist");
                         continue;
                     }
-                    if (SECURITY_MANAGER_SUCCESS != applyPrivilegePath(allowed, privilegePath))
+                    if (SECURITY_MANAGER_SUCCESS != applyPrivilegePath(allowed, privilegePath)) {
                         status = -1;
+                        LogError("Environment of application: " << entry.smackLabel <<  "for user: "
+                                 << entry.uid << " will not be setup correctly.");
+                    }
                 }
             }
         } catch (...) {
             status = -1;
-            LogError("Could not set up access to path for application: " << entry.smackLabel);
+            LogError("Environment of application: " << entry.smackLabel <<  "for user: "
+                     << entry.uid << " will not be setup correctly.");
+        }
+
+        if (!inGlobalNamespace && !MountNS::enterMountNamespace(MountNS::MAIN_MOUNT_NAMESPACE)) {
+            status = -1;
+            LogError("Error entering global mount namespace.");
         }
     }
     return status;