Skip to content

Commit

Permalink
wsd: re-create the jail directory when mounting fails
Browse files Browse the repository at this point in the history
This guarantees that the jail directory is always
created, especially in case mounting fails and
we cleanup and fallback.

Also, move the directory creation and setting
the perms into a helper, and reuse.

Change-Id: If6e9ef86afa5107638aa27050554e94c0af22b6e
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
  • Loading branch information
Ashod authored and mmeeks committed Sep 23, 2022
1 parent e200533 commit 19c70b8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
9 changes: 8 additions & 1 deletion common/JailUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,18 @@ void cleanupJails(const std::string& root)
LOG_WRN("Jails root directory [" << root << "] is not empty. Will not remove it.");
}

void createJailPath(const std::string& path)
{
LOG_INF("Creating jail path (if missing): " << path);
Poco::File(path).createDirectories();
chmod(path.c_str(), S_IXUSR | S_IWUSR | S_IRUSR);
}

void setupChildRoot(bool bindMount, const std::string& childRoot, const std::string& sysTemplate)
{
// Start with a clean slate.
cleanupJails(childRoot);
Poco::File(childRoot + CHILDROOT_TMP_INCOMING_PATH).createDirectories();
createJailPath(childRoot + CHILDROOT_TMP_INCOMING_PATH);

disableBindMounting(); // Clear to avoid surprises.

Expand Down
3 changes: 3 additions & 0 deletions common/JailUtil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ void removeJail(const std::string& root);
/// Remove all jails.
void cleanupJails(const std::string& jailRoot);

/// Creates the jail directory path recursively.
void createJailPath(const std::string& path);

/// Setup the Child-Root directory.
void setupChildRoot(bool bindMount, const std::string& jailRoot, const std::string& sysTemplate);

Expand Down
9 changes: 5 additions & 4 deletions kit/Kit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2627,9 +2627,7 @@ void lokit_main(
#if !MOBILEAPP
const Path jailPath = Path::forDirectory(childRoot + '/' + jailId);
const std::string jailPathStr = jailPath.toString();
LOG_INF("Jail path: " << jailPathStr);
File(jailPath).createDirectories();
chmod(jailPathStr.c_str(), S_IXUSR | S_IWUSR | S_IRUSR);
JailUtil::createJailPath(jailPathStr);

if (!ChildSession::NoCapsForKit)
{
Expand Down Expand Up @@ -2658,7 +2656,7 @@ void lokit_main(

// Mount loTemplate inside it.
LOG_INF("Mounting " << loTemplate << " -> " << loJailDestPath);
Poco::File(loJailDestPath).createDirectories();
JailUtil::createJailPath(loJailDestPath);
if (!JailUtil::bind(loTemplate, loJailDestPath)
|| !JailUtil::remountReadonly(loTemplate, loJailDestPath))
{
Expand Down Expand Up @@ -2707,6 +2705,9 @@ void lokit_main(
LOG_INF("Mounting is disabled, will link/copy " << sysTemplate << " -> "
<< jailPathStr);

// Make sure we have the jail directory.
JailUtil::createJailPath(jailPathStr);

// Create a file to mark this a copied jail.
JailUtil::markJailCopied(jailPathStr);

Expand Down

0 comments on commit 19c70b8

Please sign in to comment.