summaryrefslogtreecommitdiff
path: root/KeyStorage.cpp
diff options
context:
space:
mode:
authorEric Biggers <ebiggers@google.com>2021-02-16 15:59:17 -0800
committerEric Biggers <ebiggers@google.com>2021-02-16 16:05:38 -0800
commit3345a2a98c2867bb8c34b8a22a6cd2a1d35aeea8 (patch)
tree5b25e2f0617371c830ca160ab2694eca2a356e8c /KeyStorage.cpp
parentbd138dd08a905231b003576642337e712c131e1c (diff)
downloadvold-3345a2a98c2867bb8c34b8a22a6cd2a1d35aeea8.tar.gz
Sync parent directory in storeKeyAtomically()
When an FBE or metadata encryption key is created, it's important that it be persisted to disk right away; otherwise the device may fail to boot after an unclean shutdown. storeKey() has the needed fsync()s. However, storeKeyAtomically() doesn't, as it doesn't fsync() the parent directory of key_path after it renames tmp_path to it. Two callers do fsync() the parent directory themselves, but others don't. E.g., the metadata encryption key doesn't get properly synced. Therefore, add the needed fsync() to storeKeyAtomically() so that it gets done for everyone. Also remove the now-unneeded fsync()s from the two callers that did it themselves. Change-Id: I342ebd94f0a3d2bf3a7a443c35b6bda0f12e1ab2
Diffstat (limited to 'KeyStorage.cpp')
-rw-r--r--KeyStorage.cpp1
1 files changed, 1 insertions, 0 deletions
diff --git a/KeyStorage.cpp b/KeyStorage.cpp
index fb94ae51..457bb667 100644
--- a/KeyStorage.cpp
+++ b/KeyStorage.cpp
@@ -661,6 +661,7 @@ bool storeKeyAtomically(const std::string& key_path, const std::string& tmp_path
PLOG(ERROR) << "Unable to move new key to location: " << key_path;
return false;
}
+ if (!FsyncParentDirectory(key_path)) return false;
LOG(DEBUG) << "Created key: " << key_path;
return true;
}