diff options
author | Konrad Lipinski <k.lipinski2@partner.samsung.com> | 2018-10-03 11:12:31 +0200 |
---|---|---|
committer | Konrad Lipinski <k.lipinski2@partner.samsung.com> | 2018-10-03 15:43:27 +0200 |
commit | 4e944753dadb336befa4f870c2c613e40b4963d4 (patch) | |
tree | a4cb11f5cb950abe968466a3e1e02db1a654909a /src/common/service_impl.cpp | |
parent | a6d66bf4ddaf75693a4a22c967c2718153b9013b (diff) | |
download | security-manager-4e944753dadb336befa4f870c2c613e40b4963d4.tar.gz security-manager-4e944753dadb336befa4f870c2c613e40b4963d4.tar.bz2 security-manager-4e944753dadb336befa4f870c2c613e40b4963d4.zip |
Prevent smack rules leaking during multi-app hybrid pkg uninstall
Package hybridity would be detected after database modifications and
change from 1 to 0 for the last application as a result, leading to
wrong process labels being considered (User::Pkg::$pkgName as opposed
to User::Pkg::$pkgName::App::$appName).
Hybridity is now checked ahead of time to prevent the issue.
Change-Id: Ibe08d443d5fe29d36dabd6df023123da82286d21
Diffstat (limited to 'src/common/service_impl.cpp')
-rw-r--r-- | src/common/service_impl.cpp | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/src/common/service_impl.cpp b/src/common/service_impl.cpp index d902b250..31527946 100644 --- a/src/common/service_impl.cpp +++ b/src/common/service_impl.cpp @@ -65,7 +65,7 @@ InstallHelper::InstallHelper() { UninstallHelper::UninstallHelper() { isUserPkgInstalled = false; - isOldPkgHybrid = false; + isPkgHybrid = false; removePkg = false; removeAuthor = false; authorId = 0; @@ -995,7 +995,7 @@ void ServiceImpl::appUninstallPrivileges(app_inst_req::app &app, app_inst_req &r uh.removeApps.push_back(removeApp); } -void ServiceImpl::appUninstallCynaraPolicies(std::string &processLabel, app_inst_req &req, +void ServiceImpl::appUninstallCynaraPolicies(const std::string &processLabel, app_inst_req &req, UninstallHelper &ui) { LogDebug("Removing Cynara policy for: pkgName=" << req.pkgName @@ -1020,9 +1020,9 @@ int ServiceImpl::appUninstallSmackRules(app_inst_req &req, UninstallHelper &uh) for (unsigned appIdx = 0; appIdx < req.apps.size(); ++appIdx) { if (uh.removeApps[appIdx]) { const std::string &appName = req.apps[appIdx].appName; - std::string processLabel = getAppProcessLabel(appName, req.pkgName); + std::string processLabel = SmackLabels::generateProcessLabel(appName, req.pkgName, uh.isPkgHybrid); LogDebug("Removing Smack rules for appName " << appName); - if (uh.isOldPkgHybrid || uh.removePkg || uh.isOldPkgHybrid != req.isHybrid) { + if (uh.removePkg || uh.isPkgHybrid || req.isHybrid) { /* * Nonhybrid apps have the same label, so revoking it is unnecessary * unless whole package is being removed. @@ -1077,12 +1077,10 @@ int ServiceImpl::appUninstallSmackRules(app_inst_req &req, UninstallHelper &uh) int ServiceImpl::appUninstall(const Credentials &creds, app_inst_req &req) { - int ret; - try { // initial checks int toRemove = 0; - ret = appUninstallInitialChecks(creds, req, toRemove); + int ret = appUninstallInitialChecks(creds, req, toRemove); if (ret != SECURITY_MANAGER_SUCCESS) { return ret; } else { @@ -1099,6 +1097,7 @@ int ServiceImpl::appUninstall(const Credentials &creds, app_inst_req &req) getPkgLabels(req.pkgName, uh.pkgLabels); m_privilegeDb.GetPackagesInfo(uh.pkgsInfo); getPkgsProcessLabels(uh.pkgsInfo, uh.pkgsProcessLabels); + uh.isPkgHybrid = m_privilegeDb.IsPackageHybrid(req.pkgName); LogDebug("Uninstalling pkg: " << req.pkgName << " with " << req.apps.size() << " apps"); for (auto &app: req.apps) { @@ -1111,14 +1110,10 @@ int ServiceImpl::appUninstall(const Credentials &creds, app_inst_req &req) for (auto &app : req.apps) { if (app.appName.empty()) continue; - // Cynara client (Smack label) needs to be calculated before we'll remove app from privileges db - // Otherwise, last app being removed from pkg will not be able to determine correct Smack label - // if the pkg is hybrid - std::string processLabel = getAppProcessLabel(app.appName, req.pkgName); // [db] remove app appUninstallPrivileges(app, req, uh); // [cynara] update app policy - appUninstallCynaraPolicies(processLabel, req, uh); + appUninstallCynaraPolicies(SmackLabels::generateProcessLabel(app.appName, req.pkgName, uh.isPkgHybrid), req, uh); } // [db] commit @@ -1129,8 +1124,7 @@ int ServiceImpl::appUninstall(const Credentials &creds, app_inst_req &req) updatePermissibleSet(req.uid, req.installationType); // remove and merge Smack rules for apps and pkg - ret = appUninstallSmackRules(req, uh); - return ret; + return appUninstallSmackRules(req, uh); } catch (const PrivilegeDb::Exception::IOError &e) { LogError("Cannot access application database: " << e.DumpToString()); return SECURITY_MANAGER_ERROR_SERVER_ERROR; |