Skip to content

Commit 1f40c94

Browse files
committed
FscryptInstallKeyring: don't re-create keyring if it's already created
During userspace reboot FscryptInstallKeyring will be called again, this CL will make it second call a no-op, which IMHO is better than having a special logic in init to conditionally call FscryptInstallKeyring depending on whenever it's normal boot, or userspace reboot. Test: adb reboot userspace Test: checked in kernel logs that new keyring is not created Bug: 135984674 Change-Id: I4ad5aee6887b7318fb1cd02bf1c7be8da6ece599
1 parent 57d7bb6 commit 1f40c94

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

init/builtins.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ static Result<void> queue_fs_event(int code, bool userdata_remount) {
583583
return reboot_into_recovery(options);
584584
/* If reboot worked, there is no return. */
585585
} else if (code == FS_MGR_MNTALL_DEV_FILE_ENCRYPTED) {
586-
if (!userdata_remount && !FscryptInstallKeyring()) {
586+
if (!FscryptInstallKeyring()) {
587587
return Error() << "FscryptInstallKeyring() failed";
588588
}
589589
property_set("ro.crypto.state", "encrypted");
@@ -594,7 +594,7 @@ static Result<void> queue_fs_event(int code, bool userdata_remount) {
594594
ActionManager::GetInstance().QueueEventTrigger("nonencrypted");
595595
return {};
596596
} else if (code == FS_MGR_MNTALL_DEV_IS_METADATA_ENCRYPTED) {
597-
if (!userdata_remount && !FscryptInstallKeyring()) {
597+
if (!FscryptInstallKeyring()) {
598598
return Error() << "FscryptInstallKeyring() failed";
599599
}
600600
property_set("ro.crypto.state", "encrypted");
@@ -605,7 +605,7 @@ static Result<void> queue_fs_event(int code, bool userdata_remount) {
605605
ActionManager::GetInstance().QueueEventTrigger("nonencrypted");
606606
return {};
607607
} else if (code == FS_MGR_MNTALL_DEV_NEEDS_METADATA_ENCRYPTION) {
608-
if (!userdata_remount && !FscryptInstallKeyring()) {
608+
if (!FscryptInstallKeyring()) {
609609
return Error() << "FscryptInstallKeyring() failed";
610610
}
611611
property_set("ro.crypto.state", "encrypted");

init/fscrypt_init_extensions.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
using namespace android::fscrypt;
4343

4444
bool FscryptInstallKeyring() {
45+
if (keyctl_search(KEY_SPEC_SESSION_KEYRING, "keyring", "fscrypt", 0) != -1) {
46+
LOG(INFO) << "Keyring is already created";
47+
return true;
48+
}
4549
key_serial_t device_keyring = add_key("keyring", "fscrypt", 0, 0, KEY_SPEC_SESSION_KEYRING);
4650

4751
if (device_keyring == -1) {

0 commit comments

Comments
 (0)