vold: Fix fsck on public volumes
* Fsck was hitting a neverallow on public volumes not formatted in vfat
because it was always using the trusted context
* Always run trusted fsck for private volumes and untrusted for public
Change-Id: I0a6ee9aea907bae9ed097b920df0559df7b45d7d
diff --git a/fs/Ext4.cpp b/fs/Ext4.cpp
index 0059233..29bbd73 100644
--- a/fs/Ext4.cpp
+++ b/fs/Ext4.cpp
@@ -60,7 +60,7 @@
IsFilesystemSupported("ext4");
}
-status_t Check(const std::string& source, const std::string& target) {
+status_t Check(const std::string& source, const std::string& target, bool trusted) {
// The following is shamelessly borrowed from fs_mgr.c, so it should be
// kept in sync with any changes over there.
@@ -116,8 +116,7 @@
cmd.push_back("-y");
cmd.push_back(c_source);
- // ext4 devices are currently always trusted
- return ForkExecvp(cmd, nullptr, sFsckContext);
+ return ForkExecvp(cmd, nullptr, trusted ? sFsckContext : sFsckUntrustedContext);
}
return 0;
diff --git a/fs/Ext4.h b/fs/Ext4.h
index 329f302..b458439 100644
--- a/fs/Ext4.h
+++ b/fs/Ext4.h
@@ -27,7 +27,7 @@
bool IsSupported();
-status_t Check(const std::string& source, const std::string& target);
+status_t Check(const std::string& source, const std::string& target, bool trusted);
status_t Mount(const std::string& source, const std::string& target, bool ro, bool remount,
bool executable);
status_t Format(const std::string& source, unsigned long numSectors, const std::string& target);
diff --git a/fs/F2fs.cpp b/fs/F2fs.cpp
index 9517dc9..c611eb7 100644
--- a/fs/F2fs.cpp
+++ b/fs/F2fs.cpp
@@ -41,14 +41,13 @@
IsFilesystemSupported("f2fs");
}
-status_t Check(const std::string& source) {
+status_t Check(const std::string& source, bool trusted) {
std::vector<std::string> cmd;
cmd.push_back(kFsckPath);
cmd.push_back("-a");
cmd.push_back(source);
- // f2fs devices are currently always trusted
- return ForkExecvp(cmd, nullptr, sFsckContext);
+ return ForkExecvp(cmd, nullptr, trusted ? sFsckContext : sFsckUntrustedContext);
}
status_t Mount(const std::string& source, const std::string& target) {
diff --git a/fs/F2fs.h b/fs/F2fs.h
index f710212..eb34afa 100644
--- a/fs/F2fs.h
+++ b/fs/F2fs.h
@@ -27,7 +27,7 @@
bool IsSupported();
-status_t Check(const std::string& source);
+status_t Check(const std::string& source, bool trusted);
status_t Mount(const std::string& source, const std::string& target);
status_t Format(const std::string& source);
diff --git a/model/PrivateVolume.cpp b/model/PrivateVolume.cpp
index d42a8e4..8c9a808 100644
--- a/model/PrivateVolume.cpp
+++ b/model/PrivateVolume.cpp
@@ -154,7 +154,7 @@
}
if (mFsType == "ext4") {
- int res = ext4::Check(mDmDevPath, mPath);
+ int res = ext4::Check(mDmDevPath, mPath, true);
if (res == 0 || res == 1) {
LOG(DEBUG) << getId() << " passed filesystem check";
} else {
@@ -168,7 +168,7 @@
}
} else if (mFsType == "f2fs") {
- int res = f2fs::Check(mDmDevPath);
+ int res = f2fs::Check(mDmDevPath, true);
if (res == 0) {
LOG(DEBUG) << getId() << " passed filesystem check";
} else {
diff --git a/model/PublicVolume.cpp b/model/PublicVolume.cpp
index 6df45af..7084b9d 100644
--- a/model/PublicVolume.cpp
+++ b/model/PublicVolume.cpp
@@ -132,9 +132,9 @@
if (mFsType == "exfat") {
ret = exfat::Check(mDevPath);
} else if (mFsType == "ext4") {
- ret = ext4::Check(mDevPath, mRawPath);
+ ret = ext4::Check(mDevPath, mRawPath, false);
} else if (mFsType == "f2fs") {
- ret = f2fs::Check(mDevPath);
+ ret = f2fs::Check(mDevPath, false);
} else if (mFsType == "ntfs") {
ret = ntfs::Check(mDevPath);
} else if (mFsType == "vfat") {