OSDN Git Service

Sync parent directory in storeKeyAtomically()
authorEric Biggers <ebiggers@google.com>
Tue, 16 Feb 2021 23:59:17 +0000 (15:59 -0800)
committerEric Biggers <ebiggers@google.com>
Wed, 17 Feb 2021 00:05:38 +0000 (16:05 -0800)
commit3345a2a98c2867bb8c34b8a22a6cd2a1d35aeea8
tree5b25e2f0617371c830ca160ab2694eca2a356e8c
parentbd138dd08a905231b003576642337e712c131e1c
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
FsCrypt.cpp
KeyStorage.cpp
KeyStorage.h
Utils.cpp
Utils.h