summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2019-04-16 22:41:51 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2019-04-16 22:41:51 +0000
commita736dde3f4625ffbc6487065c53545e76f7433b4 (patch)
tree830448980a242aef2cd8625c383adf926034fd94
parent74b92dc85f060d2bd88246c8e187ad3ae8e8b8d1 (diff)
parent0496e3698f279bedf9d2ce86aa883e5f4a4351f7 (diff)
downloadvold-pie-qpr3-release.tar.gz
Merge cherrypicks of [7077329, 7077440, 7077330, 7077468, 7076852, 7077469, 7077580, 7077581, 7077582, 7074025, 7077706, 7077707, 7077708, 7077388, 7077583, 7077584, 7077585, 7077726, 7077727, 7077331, 7077332, 7077459, 7077709, 7077710, 7077711, 7077712, 7077460, 7077461, 7077333, 7077334, 7077696] into pi-qpr3-releaseandroid-9.0.0_r46android-9.0.0_r44android-9.0.0_r43android-9.0.0_r41android-9.0.0_r40pie-qpr3-s1-releasepie-qpr3-release
Change-Id: Icfc00a7020e3f0589ff268071c8f6d18b6f2a445
-rw-r--r--Ext4Crypt.cpp2
-rw-r--r--KeyStorage.cpp5
-rw-r--r--Utils.cpp19
-rw-r--r--Utils.h2
4 files changed, 28 insertions, 0 deletions
diff --git a/Ext4Crypt.cpp b/Ext4Crypt.cpp
index 67b7e907..68439c0f 100644
--- a/Ext4Crypt.cpp
+++ b/Ext4Crypt.cpp
@@ -177,6 +177,7 @@ static void fixate_user_ce_key(const std::string& directory_path, const std::str
PLOG(WARNING) << "Unable to rename " << to_fix << " to " << current_path;
}
}
+ android::vold::FsyncDirectory(directory_path);
}
static bool read_and_fixate_user_ce_key(userid_t user_id,
@@ -569,6 +570,7 @@ bool e4crypt_add_user_key_auth(userid_t user_id, int serial, const std::string&
std::string ce_key_path;
if (!get_ce_key_new_path(directory_path, paths, &ce_key_path)) return false;
if (!android::vold::storeKeyAtomically(ce_key_path, user_key_temp, auth, ce_key)) return false;
+ if (!android::vold::FsyncDirectory(directory_path)) return false;
return true;
}
diff --git a/KeyStorage.cpp b/KeyStorage.cpp
index 05189300..6fc7250e 100644
--- a/KeyStorage.cpp
+++ b/KeyStorage.cpp
@@ -223,6 +223,10 @@ static KeymasterOperation begin(Keymaster& keymaster, const std::string& dir,
PLOG(ERROR) << "Unable to move upgraded key to location: " << kmKeyPath;
return KeymasterOperation();
}
+ if (!android::vold::FsyncDirectory(dir)) {
+ LOG(ERROR) << "Key dir sync failed: " << dir;
+ return KeymasterOperation();
+ }
if (!keymaster.deleteKey(kmKey)) {
LOG(ERROR) << "Key deletion failed during upgrade, continuing anyway: " << dir;
}
@@ -480,6 +484,7 @@ bool storeKey(const std::string& dir, const KeyAuthentication& auth, const KeyBu
if (!encryptWithoutKeymaster(appId, key, &encryptedKey)) return false;
}
if (!writeStringToFile(encryptedKey, dir + "/" + kFn_encrypted_key)) return false;
+ if (!FsyncDirectory(dir)) return false;
return true;
}
diff --git a/Utils.cpp b/Utils.cpp
index 98e8a9b7..d578d79b 100644
--- a/Utils.cpp
+++ b/Utils.cpp
@@ -24,6 +24,7 @@
#include <android-base/properties.h>
#include <android-base/strings.h>
#include <android-base/stringprintf.h>
+#include <android-base/unique_fd.h>
#include <cutils/fs.h>
#include <logwrap/logwrap.h>
#include <private/android_filesystem_config.h>
@@ -731,5 +732,23 @@ bool IsRunningInEmulator() {
return android::base::GetBoolProperty("ro.kernel.qemu", false);
}
+bool FsyncDirectory(const std::string& dirname) {
+ android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(dirname.c_str(), O_RDONLY | O_CLOEXEC)));
+ if (fd == -1) {
+ PLOG(ERROR) << "Failed to open " << dirname;
+ return false;
+ }
+ if (fsync(fd) == -1) {
+ if (errno == EROFS || errno == EINVAL) {
+ PLOG(WARNING) << "Skip fsync " << dirname
+ << " on a file system does not support synchronization";
+ } else {
+ PLOG(ERROR) << "Failed to fsync " << dirname;
+ return false;
+ }
+ }
+ return true;
+}
+
} // namespace vold
} // namespace android
diff --git a/Utils.h b/Utils.h
index 5caa4e99..533e17c0 100644
--- a/Utils.h
+++ b/Utils.h
@@ -125,6 +125,8 @@ bool Readlinkat(int dirfd, const std::string& path, std::string* result);
/* Checks if Android is running in QEMU */
bool IsRunningInEmulator();
+bool FsyncDirectory(const std::string& dirname);
+
} // namespace vold
} // namespace android