Skip to content

Commit

Permalink
init: remove session keyring workaround for old kernels
Browse files Browse the repository at this point in the history
The android-4.14-stable and later kernels support the
FS_IOC_ADD_ENCRYPTION_KEY and FS_IOC_REMOVE_ENCRYPTION_KEY ioctls.  This
has superseded the old way of adding fscrypt keys to the kernel, which
was to use the add_key() syscall to add keys to the "session" keyring.
On kernels that support the ioctls, Android doesn't use the obsolete
way.  Since upgrading even just to Android 14 requires at minimum a
android-4.14-stable kernel (according to
https://source.android.com/docs/core/architecture/kernel/android-common#compatibility-matrix),
there is no need to support the obsolete way anymore.

Therefore, this commit removes the code from init that created a keyring
named "fscrypt" in the session keyring.  It also removes the code that
created the session keyring itself, since the only reason that Android
even created a session keyring was just to hold the "fscrypt" keyring.

Flag: N/A for the following reasons:
      - Removing obsolete code, which is fairly safe
      - Very early code, so runtime flag cannot be used
      - Even a build-time flag cannot be used, since init needs
        recovery_available, which aconfig libraries do not support

Bug: 311736104
Test: Build and boot Cuttlefish
Change-Id: Id9a184c68cf16d5c4b1d889444cf637c95a91413
  • Loading branch information
ebiggers committed Nov 27, 2023
1 parent bc907c0 commit 5d7c35c
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 28 deletions.
1 change: 0 additions & 1 deletion init/Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ libinit_cc_defaults {
"libfs_mgr",
"libgsi",
"libhidl-gen-utils",
"libkeyutils",
"liblog",
"liblogwrap",
"liblp",
Expand Down
3 changes: 0 additions & 3 deletions init/builtins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,9 +592,6 @@ static Result<void> queue_fs_event(int code) {
} else if (code == FS_MGR_MNTALL_DEV_FILE_ENCRYPTED ||
code == FS_MGR_MNTALL_DEV_IS_METADATA_ENCRYPTED ||
code == FS_MGR_MNTALL_DEV_NEEDS_METADATA_ENCRYPTION) {
if (!FscryptInstallKeyring()) {
return Error() << "FscryptInstallKeyring() failed";
}
SetProperty("ro.crypto.state", "encrypted");

// Although encrypted, vold has already set the device up, so we do not need to
Expand Down
16 changes: 0 additions & 16 deletions init/fscrypt_init_extensions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,12 @@
#include <cutils/properties.h>
#include <cutils/sockets.h>
#include <fscrypt/fscrypt.h>
#include <keyutils.h>
#include <logwrap/logwrap.h>

#define TAG "fscrypt"

using namespace android::fscrypt;

bool FscryptInstallKeyring() {
if (keyctl_search(KEY_SPEC_SESSION_KEYRING, "keyring", "fscrypt", 0) != -1) {
LOG(INFO) << "Keyring is already created";
return true;
}
key_serial_t device_keyring = add_key("keyring", "fscrypt", 0, 0, KEY_SPEC_SESSION_KEYRING);

if (device_keyring == -1) {
PLOG(ERROR) << "Failed to create keyring";
return false;
}
LOG(INFO) << "Keyring created with id " << device_keyring << " in process " << getpid();
return true;
}

// TODO(b/139378601): use a single central implementation of this.
static void delete_dir_contents(const std::string& dir) {
char* const paths[2] = {const_cast<char*>(dir.c_str()), nullptr};
Expand Down
1 change: 0 additions & 1 deletion init/fscrypt_init_extensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,5 @@ enum class FscryptAction {
kDeleteIfNecessary,
};

bool FscryptInstallKeyring();
bool FscryptSetDirectoryPolicy(const std::string& ref_basename, FscryptAction action,
const std::string& dir);
1 change: 0 additions & 1 deletion init/fuzzer/Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ cc_defaults {
"libbase",
"libfs_mgr",
"libhidl-gen-utils",
"libkeyutils",
"liblog",
"libprocessgroup",
"libselinux",
Expand Down
6 changes: 0 additions & 6 deletions init/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
#include <android-base/thread_annotations.h>
#include <fs_avb/fs_avb.h>
#include <fs_mgr_vendor_overlay.h>
#include <keyutils.h>
#include <libavb/libavb.h>
#include <libgsi/libgsi.h>
#include <libsnapshot/snapshot.h>
Expand Down Expand Up @@ -971,11 +970,6 @@ int SecondStageMain(int argc, char** argv) {
<< " to /proc/1/oom_score_adj: " << result.error();
}

// Set up a session keyring that all processes will have access to. It
// will hold things like FBE encryption keys. No process should override
// its session keyring.
keyctl_get_keyring_ID(KEY_SPEC_SESSION_KEYRING, 1);

// Indicate that booting is in progress to background fw loaders, etc.
close(open("/dev/.booting", O_WRONLY | O_CREAT | O_CLOEXEC, 0000));

Expand Down

0 comments on commit 5d7c35c

Please sign in to comment.