Add timeout for mount on untrusted media
Under some circumstances it seems mounting a device can take a long
time. We already abort fsck if it runs for too long, so this is the last
remaining spot this could happen.
Bug: 339740354
Test: Mount a very slow device, observe no Android restart
Change-Id: I3607be269d3aeb4c2391d1d8e2372e3a6795e7c4
diff --git a/fs/Exfat.cpp b/fs/Exfat.cpp
index ed53921..48fa6a3 100644
--- a/fs/Exfat.cpp
+++ b/fs/Exfat.cpp
@@ -58,8 +58,8 @@
}
}
-status_t Mount(const std::string& source, const std::string& target, int ownerUid, int ownerGid,
- int permMask) {
+status_t DoMount(const std::string& source, const std::string& target, int ownerUid, int ownerGid,
+ int permMask) {
int mountFlags = MS_NODEV | MS_NOSUID | MS_DIRSYNC | MS_NOATIME | MS_NOEXEC;
auto mountData = android::base::StringPrintf("uid=%d,gid=%d,fmask=%o,dmask=%o", ownerUid,
ownerGid, permMask, permMask);
@@ -77,6 +77,27 @@
return -1;
}
+struct mount_args {
+ const std::string& source;
+ const std::string& target;
+ int ownerUid;
+ int ownerGid;
+ int permMask;
+};
+
+int DoMountWrapper(void* args) {
+ struct mount_args* m_args = (struct mount_args*)args;
+
+ return DoMount(m_args->source, m_args->target, m_args->ownerUid, m_args->ownerGid,
+ m_args->permMask);
+}
+
+status_t Mount(const std::string& source, const std::string& target, int ownerUid, int ownerGid,
+ int permMask) {
+ struct mount_args args = {source, target, ownerUid, ownerGid, permMask};
+ return ForkTimeout(DoMountWrapper, &args, kUntrustedMountSleepTime);
+}
+
status_t Format(const std::string& source) {
std::vector<std::string> cmd;
cmd.push_back(kMkfsPath);