cryptohome: create tracked subdirectories before mounting ecryptfs

In b/115997660, files created behind ecryptfs' back are not
initially visible: this is probably because a negative ecryptfs
dentry doesn't effectively get revalidated.

Instead, create pass-through directories before mounting.
This should ensure that at the time of setting up the
ecryptfs mount, all of the tracked directories are still
present.

BUG=b:115997660
TEST=login with ecryptfs, unittests.

Change-Id: I79a206758fbc06e8d4296c91603b5f499f5da0cd
Reviewed-on: https://chromium-review.googlesource.com/1474779
Commit-Ready: Sarthak Kukreti <sarthakkukreti@chromium.org>
Tested-by: Sarthak Kukreti <sarthakkukreti@chromium.org>
Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
(cherry picked from commit 54a4cc9588ffa789bcedf42ca77ba8282b543eb3)
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/1531671
Reviewed-by: Gwendal Grignou <gwendal@google.com>
Commit-Queue: Gwendal Grignou <gwendal@google.com>
Tested-by: Gwendal Grignou <gwendal@google.com>
diff --git a/cryptohome/mount.cc b/cryptohome/mount.cc
index ef9fc6d..891c773 100644
--- a/cryptohome/mount.cc
+++ b/cryptohome/mount.cc
@@ -583,15 +583,6 @@
     // (encrypted) contents of vault_path into vault_path/user, create
     // vault_path/root.
     MigrateToUserHome(vault_path);
-
-    FilePath dest = mount_args.to_migrate_from_ecryptfs ?
-        GetUserTemporaryMountDirectory(obfuscated_username) : mount_point_;
-    if (!RememberMount(vault_path, dest, "ecryptfs", ecryptfs_options)) {
-      LOG(ERROR) << "Cryptohome mount failed";
-      UnmountAll();
-      *mount_error = MOUNT_ERROR_FATAL;
-      return false;
-    }
   }
   if (should_mount_dircrypto) {
     if (!platform_->SetDirCryptoKey(mount_point_, vault_keyset.fek_sig())) {
@@ -620,6 +611,19 @@
 
   const FilePath user_home = GetMountedUserHomePath(obfuscated_username);
   const FilePath root_home = GetMountedRootHomePath(obfuscated_username);
+
+  // b/115997660: Mount eCryptFs after creating the tracked subdirectories.
+  if (should_mount_ecryptfs) {
+    FilePath dest = mount_args.to_migrate_from_ecryptfs ?
+        GetUserTemporaryMountDirectory(obfuscated_username) : mount_point_;
+    if (!RememberMount(vault_path, dest, "ecryptfs", ecryptfs_options)) {
+      LOG(ERROR) << "Cryptohome mount failed";
+      UnmountAll();
+      *mount_error = MOUNT_ERROR_FATAL;
+      return false;
+    }
+  }
+
   if (created)
     CopySkeleton(user_home);