|
|
a3e2b5 |
From 788fb775f7deb8c456868362454e2a5f50c6068f Mon Sep 17 00:00:00 2001
|
|
|
a3e2b5 |
From: Milan Broz <gmazyland@gmail.com>
|
|
|
a3e2b5 |
Date: Mon, 27 May 2019 09:43:03 +0200
|
|
|
a3e2b5 |
Subject: [PATCH] cryptsetup: call crypt_load() for LUKS only once
|
|
|
a3e2b5 |
|
|
|
a3e2b5 |
The crypt_load() for LUKS2 can read a quite big area of disk
|
|
|
a3e2b5 |
(metadata area size is configurable and can increase up to megabytes).
|
|
|
a3e2b5 |
|
|
|
a3e2b5 |
This initialization is not needed to be repeated, just use the existing context.
|
|
|
a3e2b5 |
|
|
|
a3e2b5 |
(This patch is also required for the following change.)
|
|
|
a3e2b5 |
|
|
|
a3e2b5 |
(cherry picked from commit ea9a9d49e4af31c49e5c216e7e5e2f533e727579)
|
|
|
a3e2b5 |
|
|
|
a3e2b5 |
Related: #1719153
|
|
|
a3e2b5 |
---
|
|
|
a3e2b5 |
src/cryptsetup/cryptsetup.c | 28 ++++++++++++----------------
|
|
|
a3e2b5 |
1 file changed, 12 insertions(+), 16 deletions(-)
|
|
|
a3e2b5 |
|
|
|
a3e2b5 |
diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c
|
|
|
a3e2b5 |
index 5be1469d69..a0bd80ea65 100644
|
|
|
a3e2b5 |
--- a/src/cryptsetup/cryptsetup.c
|
|
|
a3e2b5 |
+++ b/src/cryptsetup/cryptsetup.c
|
|
|
a3e2b5 |
@@ -475,7 +475,6 @@ static int attach_tcrypt(
|
|
|
a3e2b5 |
static int attach_luks_or_plain(struct crypt_device *cd,
|
|
|
a3e2b5 |
const char *name,
|
|
|
a3e2b5 |
const char *key_file,
|
|
|
a3e2b5 |
- const char *data_device,
|
|
|
a3e2b5 |
char **passwords,
|
|
|
a3e2b5 |
uint32_t flags) {
|
|
|
a3e2b5 |
int r = 0;
|
|
|
a3e2b5 |
@@ -485,20 +484,6 @@ static int attach_luks_or_plain(struct crypt_device *cd,
|
|
|
a3e2b5 |
assert(name);
|
|
|
a3e2b5 |
assert(key_file || passwords);
|
|
|
a3e2b5 |
|
|
|
a3e2b5 |
- if (!arg_type || STR_IN_SET(arg_type, ANY_LUKS, CRYPT_LUKS1)) {
|
|
|
a3e2b5 |
- r = crypt_load(cd, CRYPT_LUKS, NULL);
|
|
|
a3e2b5 |
- if (r < 0) {
|
|
|
a3e2b5 |
- log_error("crypt_load() failed on device %s.\n", crypt_get_device_name(cd));
|
|
|
a3e2b5 |
- return r;
|
|
|
a3e2b5 |
- }
|
|
|
a3e2b5 |
-
|
|
|
a3e2b5 |
- if (data_device) {
|
|
|
a3e2b5 |
- r = crypt_set_data_device(cd, data_device);
|
|
|
a3e2b5 |
- if (r < 0)
|
|
|
a3e2b5 |
- return log_error_errno(r, "Failed to set LUKS data device %s: %m", data_device);
|
|
|
a3e2b5 |
- }
|
|
|
a3e2b5 |
- }
|
|
|
a3e2b5 |
-
|
|
|
a3e2b5 |
if ((!arg_type && !crypt_get_type(cd)) || streq_ptr(arg_type, CRYPT_PLAIN)) {
|
|
|
a3e2b5 |
struct crypt_params_plain params = {
|
|
|
a3e2b5 |
.offset = arg_offset,
|
|
|
a3e2b5 |
@@ -687,6 +672,18 @@ int main(int argc, char *argv[]) {
|
|
|
a3e2b5 |
log_warning("Key file %s is world-readable. This is not a good idea!", key_file);
|
|
|
a3e2b5 |
}
|
|
|
a3e2b5 |
|
|
|
a3e2b5 |
+ if (!arg_type || STR_IN_SET(arg_type, ANY_LUKS, CRYPT_LUKS1)) {
|
|
|
a3e2b5 |
+ r = crypt_load(cd, CRYPT_LUKS, NULL);
|
|
|
a3e2b5 |
+ if (r < 0)
|
|
|
a3e2b5 |
+ return log_error_errno(r, "Failed to load LUKS superblock on device %s: %m", crypt_get_device_name(cd));
|
|
|
a3e2b5 |
+
|
|
|
a3e2b5 |
+ if (arg_header) {
|
|
|
a3e2b5 |
+ r = crypt_set_data_device(cd, argv[3]);
|
|
|
a3e2b5 |
+ if (r < 0)
|
|
|
a3e2b5 |
+ return log_error_errno(r, "Failed to set LUKS data device %s: %m", argv[3]);
|
|
|
a3e2b5 |
+ }
|
|
|
a3e2b5 |
+ }
|
|
|
a3e2b5 |
+
|
|
|
a3e2b5 |
for (tries = 0; arg_tries == 0 || tries < arg_tries; tries++) {
|
|
|
a3e2b5 |
_cleanup_strv_free_erase_ char **passwords = NULL;
|
|
|
a3e2b5 |
|
|
|
a3e2b5 |
@@ -704,7 +701,6 @@ int main(int argc, char *argv[]) {
|
|
|
a3e2b5 |
r = attach_luks_or_plain(cd,
|
|
|
a3e2b5 |
argv[2],
|
|
|
a3e2b5 |
key_file,
|
|
|
a3e2b5 |
- arg_header ? argv[3] : NULL,
|
|
|
a3e2b5 |
passwords,
|
|
|
a3e2b5 |
flags);
|
|
|
a3e2b5 |
if (r >= 0)
|