Merge "Add timeout for mount on untrusted media" into main
diff --git a/MetadataCrypt.cpp b/MetadataCrypt.cpp
index 38dd112..8d83541 100644
--- a/MetadataCrypt.cpp
+++ b/MetadataCrypt.cpp
@@ -17,6 +17,7 @@
 #include "MetadataCrypt.h"
 #include "KeyBuffer.h"
 
+#include <fstream>
 #include <string>
 
 #include <fcntl.h>
@@ -244,6 +245,48 @@
     return true;
 }
 
+class EncryptionInProgress {
+  private:
+    std::string file_path_;
+    bool need_cleanup_ = false;
+
+  public:
+    EncryptionInProgress(const FstabEntry& entry) {
+        file_path_ = fs_mgr_metadata_encryption_in_progress_file_name(entry);
+    }
+
+    [[nodiscard]] bool Mark() {
+        {
+            std::ofstream touch(file_path_);
+            if (!touch.is_open()) {
+                PLOG(ERROR) << "Failed to mark metadata encryption in progress " << file_path_;
+                return false;
+            }
+            need_cleanup_ = true;
+        }
+        if (!android::vold::FsyncParentDirectory(file_path_)) return false;
+
+        LOG(INFO) << "Marked metadata encryption in progress (" << file_path_ << ")";
+        return true;
+    }
+
+    [[nodiscard]] bool Remove() {
+        need_cleanup_ = false;
+        if (unlink(file_path_.c_str()) != 0) {
+            PLOG(ERROR) << "Failed to clear metadata encryption in progress (" << file_path_ << ")";
+            return false;
+        }
+        if (!android::vold::FsyncParentDirectory(file_path_)) return false;
+
+        LOG(INFO) << "Cleared metadata encryption in progress (" << file_path_ << ")";
+        return true;
+    }
+
+    ~EncryptionInProgress() {
+        if (need_cleanup_) (void)Remove();
+    }
+};
+
 bool fscrypt_mount_metadata_encrypted(const std::string& blk_device, const std::string& mount_point,
                                       bool needs_encrypt, bool should_format,
                                       const std::string& fs_type, bool is_zoned,
@@ -334,6 +377,8 @@
     }
 
     if (needs_encrypt) {
+        EncryptionInProgress marker(*data_rec);
+        if (!marker.Mark()) return false;
         if (should_format) {
             status_t error;
 
@@ -362,6 +407,7 @@
                 return false;
             }
         }
+        if (!marker.Remove()) return false;
     }
 
     LOG(DEBUG) << "Mounting metadata-encrypted filesystem:" << mount_point;
diff --git a/NetlinkManager.cpp b/NetlinkManager.cpp
index 56d9df6..ee0c2f8 100644
--- a/NetlinkManager.cpp
+++ b/NetlinkManager.cpp
@@ -46,7 +46,7 @@
 
 int NetlinkManager::start() {
     struct sockaddr_nl nladdr;
-    int sz = 64 * 1024;
+    int sz = 256 * 1024;
     int on = 1;
 
     memset(&nladdr, 0, sizeof(nladdr));
diff --git a/VolumeManager.cpp b/VolumeManager.cpp
index 2171717..7c2b2f2 100644
--- a/VolumeManager.cpp
+++ b/VolumeManager.cpp
@@ -101,8 +101,6 @@
 
 static const char* kPropVirtualDisk = "persist.sys.virtual_disk";
 
-static const std::string kEmptyString("");
-
 /* 512MiB is large enough for testing purposes */
 static const unsigned int kSizeVirtualDisk = 536870912;
 
@@ -1311,4 +1309,4 @@
 
     *storageSize *= 512;
     return OK;
-}
\ No newline at end of file
+}
diff --git a/fs/Ext4.cpp b/fs/Ext4.cpp
index 293efc4..800f903 100644
--- a/fs/Ext4.cpp
+++ b/fs/Ext4.cpp
@@ -68,7 +68,7 @@
     const char* c_target = target.c_str();
     int ret;
     long tmpmnt_flags = MS_NOATIME | MS_NOEXEC | MS_NOSUID;
-    char* tmpmnt_opts = (char*)"nomblk_io_submit,errors=remount-ro";
+    char* tmpmnt_opts = (char*)"errors=remount-ro";
 
     /*
      * First try to mount and unmount the filesystem.  We do this because
diff --git a/tests/corpus/seed-2024-08-29-0 b/tests/corpus/seed-2024-08-29-0
new file mode 100644
index 0000000..3ee0dc4
--- /dev/null
+++ b/tests/corpus/seed-2024-08-29-0
Binary files differ
diff --git a/tests/corpus/seed-2024-08-29-1 b/tests/corpus/seed-2024-08-29-1
new file mode 100644
index 0000000..612a60c
--- /dev/null
+++ b/tests/corpus/seed-2024-08-29-1
Binary files differ
diff --git a/tests/corpus/seed-2024-08-29-10 b/tests/corpus/seed-2024-08-29-10
new file mode 100644
index 0000000..f5a5c0f
--- /dev/null
+++ b/tests/corpus/seed-2024-08-29-10
Binary files differ
diff --git a/tests/corpus/seed-2024-08-29-11 b/tests/corpus/seed-2024-08-29-11
new file mode 100644
index 0000000..c497a4b
--- /dev/null
+++ b/tests/corpus/seed-2024-08-29-11
Binary files differ
diff --git a/tests/corpus/seed-2024-08-29-12 b/tests/corpus/seed-2024-08-29-12
new file mode 100644
index 0000000..3a20bc5
--- /dev/null
+++ b/tests/corpus/seed-2024-08-29-12
Binary files differ
diff --git a/tests/corpus/seed-2024-08-29-13 b/tests/corpus/seed-2024-08-29-13
new file mode 100644
index 0000000..4bce6ed
--- /dev/null
+++ b/tests/corpus/seed-2024-08-29-13
Binary files differ
diff --git a/tests/corpus/seed-2024-08-29-14 b/tests/corpus/seed-2024-08-29-14
new file mode 100644
index 0000000..1680af0
--- /dev/null
+++ b/tests/corpus/seed-2024-08-29-14
Binary files differ
diff --git a/tests/corpus/seed-2024-08-29-15 b/tests/corpus/seed-2024-08-29-15
new file mode 100644
index 0000000..21b99f0
--- /dev/null
+++ b/tests/corpus/seed-2024-08-29-15
Binary files differ
diff --git a/tests/corpus/seed-2024-08-29-2 b/tests/corpus/seed-2024-08-29-2
new file mode 100644
index 0000000..9ea7969
--- /dev/null
+++ b/tests/corpus/seed-2024-08-29-2
Binary files differ
diff --git a/tests/corpus/seed-2024-08-29-3 b/tests/corpus/seed-2024-08-29-3
new file mode 100644
index 0000000..d679dd4
--- /dev/null
+++ b/tests/corpus/seed-2024-08-29-3
Binary files differ
diff --git a/tests/corpus/seed-2024-08-29-4 b/tests/corpus/seed-2024-08-29-4
new file mode 100644
index 0000000..3734101
--- /dev/null
+++ b/tests/corpus/seed-2024-08-29-4
Binary files differ
diff --git a/tests/corpus/seed-2024-08-29-5 b/tests/corpus/seed-2024-08-29-5
new file mode 100644
index 0000000..f6ddcd8
--- /dev/null
+++ b/tests/corpus/seed-2024-08-29-5
Binary files differ
diff --git a/tests/corpus/seed-2024-08-29-6 b/tests/corpus/seed-2024-08-29-6
new file mode 100644
index 0000000..bdd6fb5
--- /dev/null
+++ b/tests/corpus/seed-2024-08-29-6
Binary files differ
diff --git a/tests/corpus/seed-2024-08-29-7 b/tests/corpus/seed-2024-08-29-7
new file mode 100644
index 0000000..2e1d6cb
--- /dev/null
+++ b/tests/corpus/seed-2024-08-29-7
Binary files differ
diff --git a/tests/corpus/seed-2024-08-29-8 b/tests/corpus/seed-2024-08-29-8
new file mode 100644
index 0000000..9491bf0
--- /dev/null
+++ b/tests/corpus/seed-2024-08-29-8
Binary files differ
diff --git a/tests/corpus/seed-2024-08-29-9 b/tests/corpus/seed-2024-08-29-9
new file mode 100644
index 0000000..7366c8c
--- /dev/null
+++ b/tests/corpus/seed-2024-08-29-9
Binary files differ