int applyPrivilegePath(bool allow, const PrivilegePath &privilegePath);
bool isPrivacyPrivilegeMountNamespaceEnabled(void);
int createMountNamespace(void);
-bool enterMountNamespace(const Path &mntPath);
+int enterMountNamespace(const Path &mntPath);
int makeMountSlave(const Path &mountPoint);
int makeMountPrivate(const Path &mountPoint);
int bindMountRW(const Path &source, const Path &target);
return SECURITY_MANAGER_SUCCESS;
}
-bool enterMountNamespace(const Path &mntPath)
+int enterMountNamespace(const Path &mntPath)
{
int fd = open(mntPath.c_str(), O_RDONLY);
- if (fd < 0)
- return false;
+ if (fd < 0) {
+ LogError("Failed to open " << mntPath << ": " << GetErrnoString(errno));
+ return SECURITY_MANAGER_ERROR_FILE_OPEN_FAILED;
+ }
// 0 == allow any type of namespace
int ret = setns(fd, 0);
close(fd);
+ if (ret != 0) {
+ LogError("Failed to setns " << mntPath << ": " << GetErrnoString(errno));
+ return SECURITY_MANAGER_ERROR_MOUNT_ERROR;
+ }
- return ret >= 0;
+ return SECURITY_MANAGER_SUCCESS;
}
int makeMountSlave(const Path &mountPoint)
for (auto &entry : entries) {
try {
auto appNamespace = MountNS::getUserAppServiceMountPointPath(entry.uid, entry.smackLabel, entry.pid);
- if (MountNS::enterMountNamespace(appNamespace)) {
+ int ret = MountNS::enterMountNamespace(appNamespace);
+ if (ret == SECURITY_MANAGER_SUCCESS) {
inGlobalNamespace = false;
- } else {
+ } else if (ret == SECURITY_MANAGER_ERROR_MOUNT_ERROR) {
status = -1;
LogError("Error entering app mount namespace. Environment of application: "
- << entry.smackLabel << "for user: " << entry.uid << " will not be setup correctly.");
+ << entry.smackLabel << " for user: " << entry.uid << " will not be setup correctly.");
+ continue;
+ } else {
continue;
}
}
if (SECURITY_MANAGER_SUCCESS != applyPrivilegePath(allowed, privilegePath)) {
status = -1;
- LogError("Environment of application: " << entry.smackLabel << "for user: "
+ LogError("Environment of application: " << entry.smackLabel << " for user: "
<< entry.uid << " will not be setup correctly.");
}
}
}
} catch (...) {
status = -1;
- LogError("Environment of application: " << entry.smackLabel << "for user: "
+ LogError("Environment of application: " << entry.smackLabel << " for user: "
<< entry.uid << " will not be setup correctly.");
}
- if (!inGlobalNamespace && !MountNS::enterMountNamespace(MountNS::MAIN_MOUNT_NAMESPACE)) {
+ if (!inGlobalNamespace && MountNS::enterMountNamespace(MountNS::MAIN_MOUNT_NAMESPACE) != SECURITY_MANAGER_SUCCESS) {
status = -1;
LogError("Error entering global mount namespace.");
}