From: Krzysztof Jackiewicz Date: Tue, 30 Jan 2018 12:26:24 +0000 (+0100) Subject: Improve internal memory unmounting X-Git-Tag: submit/tizen/20180207.102416~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f1f4c07a556f530a7bcbe9e8e46dc34727d66d15;p=platform%2Fcore%2Fsecurity%2Fode.git Improve internal memory unmounting On some devices there are multiple mounts under /opt/usr. We have to unmount all the others to unlock the /opt/usr unmounting. With this commit ode will iterate over all matching entries and try to unmount all of them. Some of them are unmounted externally and may disappear before the call to umount() in ode causing EINVAL error. Ode will ignore it. Change-Id: I306cc61436e4c151a8396a6d26fefc32a9f93826 --- diff --git a/server/internal-encryption.cpp b/server/internal-encryption.cpp index c542ddb..4ff4539 100644 --- a/server/internal-encryption.cpp +++ b/server/internal-encryption.cpp @@ -193,6 +193,29 @@ void setOptions(unsigned int options) ::vconf_set_bool(VCONFKEY_ODE_FAST_ENCRYPTION, value); } +void unmountInternalStorage(const std::string& source) +{ + while(true) { + auto mntPaths = findMountPointsByDevice(source); + if(mntPaths.empty()) + break; + + bool unmounted = true; + for(const auto& path : mntPaths) { + INFO(SINK, "Unmounting " + path); + if (::umount(path.c_str()) == -1) { + // If it's busy or was already unmounted ignore the error + if (errno != EBUSY && errno != EINVAL) { + throw runtime::Exception("umount() error: " + runtime::GetSystemErrorMessage()); + } + unmounted = false; + } + } + if (!unmounted) + stopDependedSystemdServices(); + } +} + } InternalEncryptionServer::InternalEncryptionServer(ServerContext& srv, @@ -312,24 +335,16 @@ int InternalEncryptionServer::encrypt(const std::string& password, unsigned int auto encryptWorker = [masterKey, options, this]() { try { std::string source = engine->getSource(); - std::string mntPath = findMountPointByDevice(source); + auto mntPaths = findMountPointsByDevice(source); - if (!mntPath.empty()) { + if (!mntPaths.empty()) { INFO(SINK, "Closing all known systemd services that might be using internal storage."); stopKnownSystemdServices(); INFO(SINK, "Closing all processes using internal storage."); stopDependedSystemdServices(); - } - while (!mntPath.empty()) { - INFO(SINK, "Umounting internal storage."); - while (::umount(mntPath.c_str()) == -1) { - if (errno != EBUSY) { - throw runtime::Exception("Umount error: " + runtime::GetSystemErrorMessage()); - } - stopDependedSystemdServices(); - } - mntPath = findMountPointByDevice(source); + INFO(SINK, "Unmounting internal storage."); + unmountInternalStorage(source); } showProgressUI("Encrypting"); diff --git a/server/misc.cpp b/server/misc.cpp index 5533432..51a250f 100644 --- a/server/misc.cpp +++ b/server/misc.cpp @@ -40,17 +40,15 @@ struct ::mntent* Mtab::next() { } -std::string findMountPointByDevice(const std::string &devPath) +std::vector findMountPointsByDevice(const std::string &devPath) { - std::string ret; + std::vector ret; Mtab mtab; struct ::mntent* entry = NULL; while ((entry = mtab.next()) != NULL) { - if (devPath == entry->mnt_fsname) { - ret = entry->mnt_dir; - break; - } + if (devPath == entry->mnt_fsname) + ret.push_back(entry->mnt_dir); } return ret; diff --git a/server/misc.h b/server/misc.h index 13c380e..04ec0ba 100644 --- a/server/misc.h +++ b/server/misc.h @@ -21,6 +21,8 @@ #include #include +#include + namespace ode { class Mtab { @@ -34,7 +36,7 @@ private: FILE* mtab; }; -std::string findMountPointByDevice(const std::string &devPath); +std::vector findMountPointsByDevice(const std::string &devPath); void killDependentApplications(const std::string &mntPath); } // namespace ode