Fsync directories after creating files
Bug: 112145641
Bug: 124279741
Bug: 120248692
Test: adb shell locksettings set-pin 1111 && \
adb shell "echo b > /proc/sysrq-trigger"
Change-Id: I53d252942c21365983b4f8b6e0948b1864f195c1
Merged-In: I53d252942c21365983b4f8b6e0948b1864f195c1
(cherry picked from commit 2e58acb412
)
This commit is contained in:
parent
74b92dc85f
commit
4b9c47d70f
4 changed files with 24 additions and 0 deletions
|
@ -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;
|
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,
|
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;
|
std::string ce_key_path;
|
||||||
if (!get_ce_key_new_path(directory_path, paths, &ce_key_path)) return false;
|
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::storeKeyAtomically(ce_key_path, user_key_temp, auth, ce_key)) return false;
|
||||||
|
if (!android::vold::FsyncDirectory(directory_path)) return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -480,6 +480,7 @@ bool storeKey(const std::string& dir, const KeyAuthentication& auth, const KeyBu
|
||||||
if (!encryptWithoutKeymaster(appId, key, &encryptedKey)) return false;
|
if (!encryptWithoutKeymaster(appId, key, &encryptedKey)) return false;
|
||||||
}
|
}
|
||||||
if (!writeStringToFile(encryptedKey, dir + "/" + kFn_encrypted_key)) return false;
|
if (!writeStringToFile(encryptedKey, dir + "/" + kFn_encrypted_key)) return false;
|
||||||
|
if (!FsyncDirectory(dir)) return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
19
Utils.cpp
19
Utils.cpp
|
@ -24,6 +24,7 @@
|
||||||
#include <android-base/properties.h>
|
#include <android-base/properties.h>
|
||||||
#include <android-base/strings.h>
|
#include <android-base/strings.h>
|
||||||
#include <android-base/stringprintf.h>
|
#include <android-base/stringprintf.h>
|
||||||
|
#include <android-base/unique_fd.h>
|
||||||
#include <cutils/fs.h>
|
#include <cutils/fs.h>
|
||||||
#include <logwrap/logwrap.h>
|
#include <logwrap/logwrap.h>
|
||||||
#include <private/android_filesystem_config.h>
|
#include <private/android_filesystem_config.h>
|
||||||
|
@ -731,5 +732,23 @@ bool IsRunningInEmulator() {
|
||||||
return android::base::GetBoolProperty("ro.kernel.qemu", false);
|
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 vold
|
||||||
} // namespace android
|
} // namespace android
|
||||||
|
|
2
Utils.h
2
Utils.h
|
@ -125,6 +125,8 @@ bool Readlinkat(int dirfd, const std::string& path, std::string* result);
|
||||||
/* Checks if Android is running in QEMU */
|
/* Checks if Android is running in QEMU */
|
||||||
bool IsRunningInEmulator();
|
bool IsRunningInEmulator();
|
||||||
|
|
||||||
|
bool FsyncDirectory(const std::string& dirname);
|
||||||
|
|
||||||
} // namespace vold
|
} // namespace vold
|
||||||
} // namespace android
|
} // namespace android
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue