Label package base paths for SHARED_RO bind mounting 89/217589/3
authorZofia Grzelewska <z.abramowska@samsung.com>
Tue, 12 Nov 2019 14:27:11 +0000 (15:27 +0100)
committerTomasz Swierczek <t.swierczek@samsung.com>
Wed, 20 Nov 2019 11:11:50 +0000 (11:11 +0000)
Label $APP_HOME/.shared/$PKG_NAME and $APP_HOME/.shared/$PKG_NAME
paths with "User::Home" to allow bind mount in application context.

Change-Id: Ib19de4e87766f5a313f1e5e0542e1da8b30f8a40

src/common/include/service_impl_utils.h
src/common/service_impl.cpp
src/common/service_impl_utils.cpp

index b68b359841445e69c4c3a58fe5530a60868a8245..f7e288a92b8b2885233df298d8864fc6f47de9c1 100644 (file)
@@ -40,6 +40,7 @@ bool containSubDir(const std::string &parent, const pkg_paths &paths);
 int getLegalPkgBaseDirs(const uid_t &uid,
                         const std::string &pkgName,
                         app_install_type installType,
+                        std::string &homePath,
                         std::vector<std::string> &legalPkgBaseDirs,
                         bool isSharedRO);
 
index 8c88ffa65f73d9faff9678cb06e052c55a04b3c7..b03d7ee9651a07fed351cd0bb0e3e36e5600b6ea 100644 (file)
@@ -332,8 +332,10 @@ int ServiceImpl::labelPaths(const pkg_paths &paths,
         int authorId;
         m_privilegeDb.GetPkgAuthorId(pkgName, authorId);
 
+        std::string homePath;
         std::vector<std::string> pkgLegalBaseDirs;
-        int ret = getLegalPkgBaseDirs(uid, pkgName, installationType, pkgLegalBaseDirs, isSharedRO);
+        int ret = getLegalPkgBaseDirs(uid, pkgName, installationType, homePath,
+                                      pkgLegalBaseDirs, isSharedRO);
         if (ret != SECURITY_MANAGER_SUCCESS) {
             LogError("Failed to generate legal directories for application");
             return ret;
@@ -343,6 +345,15 @@ int ServiceImpl::labelPaths(const pkg_paths &paths,
         if (!pathsCheck(paths, pkgLegalBaseDirs))
             return SECURITY_MANAGER_ERROR_NOT_PATH_OWNER;
 
+        if (isSharedRO) {
+            // Label shared_ro base paths for bind mounting
+            std::string sharedPath = homePath + ".shared/" + pkgName;
+            std::string sharedTmpPath = homePath + ".shared_tmp/" + pkgName;
+            if (FS::directoryStatus(sharedPath) == 1 && FS::directoryStatus(sharedTmpPath) == 1) {
+                SmackLabels::setupPkgBasePath(sharedPath);
+                SmackLabels::setupPkgBasePath(sharedTmpPath);
+            }
+        }
         // register paths
         for (const auto &pkgPath : paths) {
             const std::string &path = pkgPath.first;
index eb1ff7e0ac718f45561410c3fd2e22c19eb9899d..d2bde19b07296561fc6017291a74801986bc4b6e 100644 (file)
@@ -100,6 +100,7 @@ std::string realPath(const std::string &path)
 int getLegalPkgBaseDirs(const uid_t &uid,
                         const std::string &pkgName,
                         app_install_type installType,
+                        std::string &homePath,
                         std::vector<std::string> &legalPkgDirs,
                         bool isSharedRO)
 {
@@ -108,7 +109,7 @@ int getLegalPkgBaseDirs(const uid_t &uid,
     bool isSdAvailable = false;
     bool isSkelAvailable = false;
     enum tzplatform_variable baseId;
-    enum tzplatform_variable extendedSdId;
+    enum tzplatform_variable extendedSdId = _TZPLATFORM_VARIABLES_INVALID_;
 
     switch (installType) {
     case SM_APP_INSTALL_LOCAL:
@@ -133,12 +134,13 @@ int getLegalPkgBaseDirs(const uid_t &uid,
 
     legalPkgDirs.clear();
 
-    std::string basePath;
-    if (!getPath(tpc, baseId, pkgName, basePath)) {
-        LogError("Couldn't generate base path");
+    if (!getPath(tpc, baseId, "", homePath)) {
+        LogError("Couldn't generate home path");
         return SECURITY_MANAGER_ERROR_UNKNOWN;
     }
 
+    std::string basePath = homePath + pkgName;
+
     LogDebug("Base path is : " << basePath);
     legalPkgDirs.push_back(std::move(basePath));