From dcbc38c916ebc6f024870c888536e55fc38b353c Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 31 Mar 2022 10:47:24 +0200 Subject: [PATCH 01/11] cryptsetup: rename functions that try to do FIDO2/TPM2/PKCS#11 via cryptsetup plugins to say so The are so many different flavours of functions that attach volumes, hence say explicitly that these are about libcryptsetup plugins, and nothing else. Just some renaming, no code changes beyond that. --- src/cryptsetup/cryptsetup.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c index 6c7b74037f..9db3f6f098 100644 --- a/src/cryptsetup/cryptsetup.c +++ b/src/cryptsetup/cryptsetup.c @@ -850,7 +850,7 @@ static int acquire_pins_from_env_variable(char ***ret_pins) { } #endif -static int attach_luks2_by_fido2( +static int attach_luks2_by_fido2_via_plugin( struct crypt_device *cd, const char *name, usec_t until, @@ -980,7 +980,7 @@ static int attach_luks_or_plain_or_bitlk_by_fido2( for (;;) { if (use_libcryptsetup_plugin && !arg_fido2_cid) { - r = attach_luks2_by_fido2(cd, name, until, arg_headless, arg_fido2_device, flags); + r = attach_luks2_by_fido2_via_plugin(cd, name, until, arg_headless, arg_fido2_device, flags); if (IN_SET(r, -ENOTUNIQ, -ENXIO, -ENOENT)) return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN), "Automatic FIDO2 metadata discovery was not possible because missing or not unique, falling back to traditional unlocking."); @@ -1053,7 +1053,7 @@ static int attach_luks_or_plain_or_bitlk_by_fido2( return 0; } -static int attach_luks2_by_pkcs11( +static int attach_luks2_by_pkcs11_via_plugin( struct crypt_device *cd, const char *name, const char *friendly_name, @@ -1133,7 +1133,7 @@ static int attach_luks_or_plain_or_bitlk_by_pkcs11( for (;;) { if (use_libcryptsetup_plugin && arg_pkcs11_uri_auto) - r = attach_luks2_by_pkcs11(cd, name, friendly, until, arg_headless, flags); + r = attach_luks2_by_pkcs11_via_plugin(cd, name, friendly, until, arg_headless, flags); else { r = decrypt_pkcs11_key( name, @@ -1246,7 +1246,7 @@ static int make_tpm2_device_monitor( return 0; } -static int attach_luks2_by_tpm2( +static int attach_luks2_by_tpm2_via_plugin( struct crypt_device *cd, const char *name, uint32_t flags) { @@ -1325,7 +1325,7 @@ static int attach_luks_or_plain_or_bitlk_by_tpm2( if (r != -EAGAIN) /* EAGAIN means: no tpm2 chip found */ return r; } else { - r = attach_luks2_by_tpm2(cd, name, flags); + r = attach_luks2_by_tpm2_via_plugin(cd, name, flags); /* EAGAIN means: no tpm2 chip found * EOPNOTSUPP means: no libcryptsetup plugins support */ if (r == -ENXIO) @@ -1338,7 +1338,7 @@ static int attach_luks_or_plain_or_bitlk_by_tpm2( return r; } - if (r == -EOPNOTSUPP) { + if (r == -EOPNOTSUPP) { /* Plugin not available, let's process TPM2 stuff right here instead */ _cleanup_free_ void *blob = NULL, *policy_hash = NULL; size_t blob_size, policy_hash_size; bool found_some = false; From 2fabbad8983bf012e73479b73ecd390794080c3d Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 31 Mar 2022 10:48:37 +0200 Subject: [PATCH 02/11] cryptsetup: add helper for mangling "none" option strings let's unify some code here, and let's do so in cryptsetup-util.h so that we can later reuse this in integritysetup/veritysetup --- src/cryptsetup/cryptsetup.c | 4 ++-- src/shared/cryptsetup-util.h | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c index 9db3f6f098..137e7ee95d 100644 --- a/src/cryptsetup/cryptsetup.c +++ b/src/cryptsetup/cryptsetup.c @@ -1750,8 +1750,8 @@ static int run(int argc, char *argv[]) { volume = argv[2]; source = argv[3]; - key_file = argc >= 5 && !STR_IN_SET(argv[4], "", "-", "none") ? argv[4] : NULL; - options = argc >= 6 && !STR_IN_SET(argv[5], "", "-", "none") ? argv[5] : NULL; + key_file = mangle_none(argc >= 5 ? argv[4] : NULL); + options = mangle_none(argc >= 6 ? argv[5] : NULL); if (!filename_is_valid(volume)) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Volume name '%s' is not valid.", volume); diff --git a/src/shared/cryptsetup-util.h b/src/shared/cryptsetup-util.h index ff44af8441..2a17820d63 100644 --- a/src/shared/cryptsetup-util.h +++ b/src/shared/cryptsetup-util.h @@ -86,3 +86,8 @@ static inline void sym_crypt_free(struct crypt_device* cd) {} static inline void sym_crypt_freep(struct crypt_device** cd) {} #endif + +static inline const char *mangle_none(const char *s) { + /* A helper that turns cryptsetup/integritysetup/veritysetup "options" strings into NULL if they are effectively empty */ + return isempty(s) || STR_IN_SET(s, "-", "none") ? NULL : s; +} From 2e4aae981e5860a830293d16bf28cc658d89110d Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 31 Mar 2022 10:49:30 +0200 Subject: [PATCH 03/11] cryptsetup: adjust some log levels Let's upgrade log levels of some noteworthy messages from LOG_DEBUG to LOG_NOTICE. These messages contain information that previous log messages in the error path didn't say, namely that we'll now fall back to traditional unlocking. Note that this leaves similar log messages for cases where TPM2/PKCS#11/FIDO2 support is disabled at build at LOG_DEBUG, since in that case nothing really failed, we just systematically can't do TPM2/PKCS#11/FIDO2 and hence it is pointless and not actionable for users to do anything about it... --- src/cryptsetup/cryptsetup.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c index 137e7ee95d..21430d4256 100644 --- a/src/cryptsetup/cryptsetup.c +++ b/src/cryptsetup/cryptsetup.c @@ -1329,8 +1329,8 @@ static int attach_luks_or_plain_or_bitlk_by_tpm2( /* EAGAIN means: no tpm2 chip found * EOPNOTSUPP means: no libcryptsetup plugins support */ if (r == -ENXIO) - return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN), - "No TPM2 metadata matching the current system state found in LUKS2 header, falling back to traditional unlocking."); + return log_notice_errno(SYNTHETIC_ERRNO(EAGAIN), + "No TPM2 metadata matching the current system state found in LUKS2 header, falling back to traditional unlocking."); if (r == -ENOENT) return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN), "No TPM2 metadata enrolled in LUKS2 header or TPM2 support not available, falling back to traditional unlocking."); @@ -1367,10 +1367,11 @@ static int attach_luks_or_plain_or_bitlk_by_tpm2( &tpm2_flags); if (r == -ENXIO) /* No further TPM2 tokens found in the LUKS2 header. */ - return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN), - found_some - ? "No TPM2 metadata matching the current system state found in LUKS2 header, falling back to traditional unlocking." - : "No TPM2 metadata enrolled in LUKS2 header, falling back to traditional unlocking."); + return log_full_errno(found_some ? LOG_NOTICE : LOG_DEBUG, + SYNTHETIC_ERRNO(EAGAIN), + found_some + ? "No TPM2 metadata matching the current system state found in LUKS2 header, falling back to traditional unlocking." + : "No TPM2 metadata enrolled in LUKS2 header, falling back to traditional unlocking."); if (ERRNO_IS_NOT_SUPPORTED(r)) /* TPM2 support not compiled in? */ return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN), "TPM2 support not available, falling back to traditional unlocking."); if (r < 0) @@ -1393,7 +1394,7 @@ static int attach_luks_or_plain_or_bitlk_by_tpm2( arg_ask_password_flags, &decrypted_key, &decrypted_key_size); if (IN_SET(r, -EACCES, -ENOLCK)) - return log_error_errno(SYNTHETIC_ERRNO(EAGAIN), "TPM2 PIN unlock failed, falling back to traditional unlocking."); + return log_notice_errno(SYNTHETIC_ERRNO(EAGAIN), "TPM2 PIN unlock failed, falling back to traditional unlocking."); if (r != -EPERM) break; From 49a4a81dd7616fe3e687a3694a0dd33c2c959314 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 31 Mar 2022 10:52:50 +0200 Subject: [PATCH 04/11] veritysetup: give command line parameters proper names Accessing the various arguments always through argv[] is nasty, since it's not obvious what we are talking about here. Let's give things nice names. We did the same in cryptsetup a while back. --- src/veritysetup/veritysetup.c | 43 +++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/src/veritysetup/veritysetup.c b/src/veritysetup/veritysetup.c index 3b5cb53b4a..5fc74f1c31 100644 --- a/src/veritysetup/veritysetup.c +++ b/src/veritysetup/veritysetup.c @@ -111,6 +111,7 @@ static int parse_options(const char *options) { static int run(int argc, char *argv[]) { _cleanup_(crypt_freep) struct crypt_device *cd = NULL; + const char *verb; int r; if (argc <= 1 || @@ -128,7 +129,10 @@ static int run(int argc, char *argv[]) { umask(0022); - if (streq(argv[1], "attach")) { + verb = argv[1]; + + if (streq(verb, "attach")) { + const char *volume, *data_device, *verity_device, *root_hash, *options; _cleanup_free_ void *m = NULL; crypt_status_info status; size_t l; @@ -136,24 +140,30 @@ static int run(int argc, char *argv[]) { if (argc < 6) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "attach requires at least four arguments."); - r = unhexmem(argv[5], strlen(argv[5]), &m, &l); + volume = argv[2]; + data_device = argv[3]; + verity_device = argv[4]; + root_hash = argv[5]; + options = argv[6]; + + r = unhexmem(root_hash, SIZE_MAX, &m, &l); if (r < 0) return log_error_errno(r, "Failed to parse root hash: %m"); - r = crypt_init(&cd, argv[4]); + r = crypt_init(&cd, verity_device); if (r < 0) - return log_error_errno(r, "Failed to open verity device %s: %m", argv[4]); + return log_error_errno(r, "Failed to open verity device %s: %m", verity_device); cryptsetup_enable_logging(cd); - status = crypt_status(cd, argv[2]); + status = crypt_status(cd, volume); if (IN_SET(status, CRYPT_ACTIVE, CRYPT_BUSY)) { - log_info("Volume %s already active.", argv[2]); + log_info("Volume %s already active.", volume); return 0; } if (argc > 6) { - r = parse_options(argv[6]); + r = parse_options(options); if (r < 0) return log_error_errno(r, "Failed to parse options: %m"); } @@ -162,7 +172,7 @@ static int run(int argc, char *argv[]) { if (r < 0) return log_error_errno(r, "Failed to load verity superblock: %m"); - r = crypt_set_data_device(cd, argv[3]); + r = crypt_set_data_device(cd, data_device); if (r < 0) return log_error_errno(r, "Failed to configure data device: %m"); @@ -186,20 +196,23 @@ static int run(int argc, char *argv[]) { return log_error_errno(r, "Failed to read root hash signature: %m"); } - r = crypt_activate_by_signed_key(cd, argv[2], m, l, hash_sig, hash_sig_size, arg_activate_flags); + r = crypt_activate_by_signed_key(cd, volume, m, l, hash_sig, hash_sig_size, arg_activate_flags); #else assert_not_reached(); #endif } else - r = crypt_activate_by_volume_key(cd, argv[2], m, l, arg_activate_flags); + r = crypt_activate_by_volume_key(cd, volume, m, l, arg_activate_flags); if (r < 0) return log_error_errno(r, "Failed to set up verity device: %m"); - } else if (streq(argv[1], "detach")) { + } else if (streq(verb, "detach")) { + const char *volume; - r = crypt_init_by_name(&cd, argv[2]); + volume = argv[2]; + + r = crypt_init_by_name(&cd, volume); if (r == -ENODEV) { - log_info("Volume %s already inactive.", argv[2]); + log_info("Volume %s already inactive.", volume); return 0; } if (r < 0) @@ -207,12 +220,12 @@ static int run(int argc, char *argv[]) { cryptsetup_enable_logging(cd); - r = crypt_deactivate(cd, argv[2]); + r = crypt_deactivate(cd, volume); if (r < 0) return log_error_errno(r, "Failed to deactivate: %m"); } else - return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Unknown verb %s.", argv[1]); + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Unknown verb %s.", verb); return 0; } From bb3ff7a9967db904c83f4f7be033f4d29ace4222 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 31 Mar 2022 11:01:52 +0200 Subject: [PATCH 05/11] veritysetup: mangle option strings like in cryptsetup --- src/veritysetup/veritysetup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/veritysetup/veritysetup.c b/src/veritysetup/veritysetup.c index 5fc74f1c31..3551ed4f3a 100644 --- a/src/veritysetup/veritysetup.c +++ b/src/veritysetup/veritysetup.c @@ -144,7 +144,7 @@ static int run(int argc, char *argv[]) { data_device = argv[3]; verity_device = argv[4]; root_hash = argv[5]; - options = argv[6]; + options = mangle_none(argc > 6 ? argv[6] : NULL); r = unhexmem(root_hash, SIZE_MAX, &m, &l); if (r < 0) @@ -162,7 +162,7 @@ static int run(int argc, char *argv[]) { return 0; } - if (argc > 6) { + if (options) { r = parse_options(options); if (r < 0) return log_error_errno(r, "Failed to parse options: %m"); From 9959d7828010d2a26de95509309587162770960d Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 31 Mar 2022 11:03:06 +0200 Subject: [PATCH 06/11] veritysetup: do some superficial checking on volume name cryptsetup does this too, so let's better be safe here, too. --- src/veritysetup/veritysetup.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/veritysetup/veritysetup.c b/src/veritysetup/veritysetup.c index 3551ed4f3a..a81e93cb75 100644 --- a/src/veritysetup/veritysetup.c +++ b/src/veritysetup/veritysetup.c @@ -146,6 +146,9 @@ static int run(int argc, char *argv[]) { root_hash = argv[5]; options = mangle_none(argc > 6 ? argv[6] : NULL); + if (!filename_is_valid(volume)) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Volume name '%s' is not valid.", volume); + r = unhexmem(root_hash, SIZE_MAX, &m, &l); if (r < 0) return log_error_errno(r, "Failed to parse root hash: %m"); @@ -210,6 +213,9 @@ static int run(int argc, char *argv[]) { volume = argv[2]; + if (!filename_is_valid(volume)) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Volume name '%s' is not valid.", volume); + r = crypt_init_by_name(&cd, volume); if (r == -ENODEV) { log_info("Volume %s already inactive.", volume); From 542bb9be7cd0c05e3fb1beb849b70d79fec42189 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 31 Mar 2022 11:09:48 +0200 Subject: [PATCH 07/11] tree-wide: unify some code that looks for --help in the command line --- src/backlight/backlight.c | 5 +++-- src/basic/process-util.c | 24 ++++++++++++++++++++++++ src/basic/process-util.h | 2 ++ src/cryptsetup/cryptsetup.c | 3 ++- src/integritysetup/integritysetup.c | 8 +++----- src/veritysetup/veritysetup.c | 6 ++---- 6 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/backlight/backlight.c b/src/backlight/backlight.c index 5a3095cbba..a4e5d77f6c 100644 --- a/src/backlight/backlight.c +++ b/src/backlight/backlight.c @@ -14,10 +14,11 @@ #include "mkdir.h" #include "parse-util.h" #include "pretty-print.h" -#include "terminal-util.h" +#include "process-util.h" #include "reboot-util.h" #include "string-util.h" #include "strv.h" +#include "terminal-util.h" #include "util.h" static int help(void) { @@ -368,7 +369,7 @@ static int run(int argc, char *argv[]) { log_setup(); - if (strv_contains(strv_skip(argv, 1), "--help")) + if (argv_looks_like_help(argc, argv)) return help(); if (argc != 3) diff --git a/src/basic/process-util.c b/src/basic/process-util.c index 72807d039c..10aec10bfa 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -1615,6 +1615,30 @@ _noreturn_ void freeze(void) { pause(); } +bool argv_looks_like_help(int argc, char **argv) { + char **l; + + /* Scans the command line for indications the user asks for help. This is supposed to be called by + * tools that do not implement getopt() style command line parsing because they are not primarily + * user-facing. Detects four ways of asking for help: + * + * 1. Passing zero arguments + * 2. Passing "help" as first argument + * 3. Passing --help as any argument + * 4. Passing -h as any argument + */ + + if (argc <= 1) + return true; + + if (streq_ptr(argv[1], "help")) + return true; + + l = strv_skip(argv, 1); + + return strv_contains(l, "--help") || + strv_contains(l, "-h"); +} static const char *const sigchld_code_table[] = { [CLD_EXITED] = "exited", diff --git a/src/basic/process-util.h b/src/basic/process-util.h index f22ff76ee8..c07575e580 100644 --- a/src/basic/process-util.h +++ b/src/basic/process-util.h @@ -191,3 +191,5 @@ int setpriority_closest(int priority); bool invoked_as(char *argv[], const char *token); _noreturn_ void freeze(void); + +bool argv_looks_like_help(int argc, char **argv); diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c index 21430d4256..408d7511bf 100644 --- a/src/cryptsetup/cryptsetup.c +++ b/src/cryptsetup/cryptsetup.c @@ -34,6 +34,7 @@ #include "path-util.h" #include "pkcs11-util.h" #include "pretty-print.h" +#include "process-util.h" #include "random-util.h" #include "string-util.h" #include "strv.h" @@ -1719,7 +1720,7 @@ static int run(int argc, char *argv[]) { const char *verb; int r; - if (argc <= 1) + if (argv_looks_like_help(argc, argv)) return help(); if (argc < 3) diff --git a/src/integritysetup/integritysetup.c b/src/integritysetup/integritysetup.c index d8cfd12e95..7eff0ce5dc 100644 --- a/src/integritysetup/integritysetup.c +++ b/src/integritysetup/integritysetup.c @@ -12,9 +12,10 @@ #include "log.h" #include "main-func.h" #include "memory-util.h" -#include "path-util.h" #include "parse-util.h" +#include "path-util.h" #include "pretty-print.h" +#include "process-util.h" #include "string-util.h" #include "terminal-util.h" @@ -90,10 +91,7 @@ static int run(int argc, char *argv[]) { int r; char *action, *volume; - if (argc <= 1 || - strv_contains(strv_skip(argv, 1), "--help") || - strv_contains(strv_skip(argv, 1), "-h") || - streq(argv[1], "help")) + if (argv_looks_like_help(argc, argv)) return help(); if (argc < 3) diff --git a/src/veritysetup/veritysetup.c b/src/veritysetup/veritysetup.c index a81e93cb75..1d1baaa59d 100644 --- a/src/veritysetup/veritysetup.c +++ b/src/veritysetup/veritysetup.c @@ -12,6 +12,7 @@ #include "main-func.h" #include "path-util.h" #include "pretty-print.h" +#include "process-util.h" #include "string-util.h" #include "terminal-util.h" @@ -114,10 +115,7 @@ static int run(int argc, char *argv[]) { const char *verb; int r; - if (argc <= 1 || - strv_contains(strv_skip(argv, 1), "--help") || - strv_contains(strv_skip(argv, 1), "-h") || - streq(argv[1], "help")) + if (argv_looks_like_help(argc, argv)) return help(); if (argc < 3) From 042fcbbf7e7f65d627f34f3e60dce1149e9f7f12 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 31 Mar 2022 11:20:01 +0200 Subject: [PATCH 08/11] =?UTF-8?q?integritysetup:=20rename=20action=20?= =?UTF-8?q?=E2=86=92=20verb,=20to=20match=20other=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/integritysetup/integritysetup.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/integritysetup/integritysetup.c b/src/integritysetup/integritysetup.c index 7eff0ce5dc..eeb5cdbdbb 100644 --- a/src/integritysetup/integritysetup.c +++ b/src/integritysetup/integritysetup.c @@ -88,8 +88,8 @@ static const char *integrity_algorithm_select(const void *key_file_buf) { static int run(int argc, char *argv[]) { _cleanup_(crypt_freep) struct crypt_device *cd = NULL; + char *verb, *volume; int r; - char *action, *volume; if (argv_looks_like_help(argc, argv)) return help(); @@ -97,7 +97,7 @@ static int run(int argc, char *argv[]) { if (argc < 3) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "This program requires at least two arguments."); - action = argv[1]; + verb = argv[1]; volume = argv[2]; log_setup(); @@ -106,7 +106,7 @@ static int run(int argc, char *argv[]) { umask(0022); - if (streq(action, "attach")) { + if (streq(verb, "attach")) { /* attach name device optional_key_file optional_options */ crypt_status_info status; @@ -169,7 +169,7 @@ static int run(int argc, char *argv[]) { if (r < 0) return log_error_errno(r, "Failed to set up integrity device: %m"); - } else if (streq(action, "detach")) { + } else if (streq(verb, "detach")) { if (argc > 3) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "detach has a maximum of two arguments."); @@ -187,7 +187,7 @@ static int run(int argc, char *argv[]) { return log_error_errno(r, "Failed to deactivate: %m"); } else - return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Unknown verb %s.", action); + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Unknown verb %s.", verb); return 0; } From 2b4b030044def68df1d3a9ef6966c7155808ba44 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 31 Mar 2022 11:20:25 +0200 Subject: [PATCH 09/11] integritysetup: log when attempted to detach already detached volume To make the tool behave more like cryptsetup/veritysetup --- src/integritysetup/integritysetup.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/integritysetup/integritysetup.c b/src/integritysetup/integritysetup.c index eeb5cdbdbb..5fd220c515 100644 --- a/src/integritysetup/integritysetup.c +++ b/src/integritysetup/integritysetup.c @@ -175,8 +175,10 @@ static int run(int argc, char *argv[]) { return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "detach has a maximum of two arguments."); r = crypt_init_by_name(&cd, volume); - if (r == -ENODEV) + if (r == -ENODEV) { + log_info("Volume %s already inactive.", volume); return 0; + } if (r < 0) return log_error_errno(r, "crypt_init_by_name() failed: %m"); From 752d8594427ff141293c27a0e9aa84fb3796c419 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 31 Mar 2022 11:21:37 +0200 Subject: [PATCH 10/11] integritysetup: also port to mangle_none() Let's make the tool work more like veritysetup/cryptsetup in this regard too. --- src/integritysetup/integritysetup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/integritysetup/integritysetup.c b/src/integritysetup/integritysetup.c index 5fd220c515..f95840a8d0 100644 --- a/src/integritysetup/integritysetup.c +++ b/src/integritysetup/integritysetup.c @@ -121,8 +121,8 @@ static int run(int argc, char *argv[]) { return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "attach has a maximum of five arguments."); device = argv[3]; - key_file = (argc > 4) ? empty_or_dash_to_null(argv[4]) : NULL; - options = (argc > 5) ? empty_or_dash_to_null(argv[5]) : NULL; + key_file = mangle_none(argc > 4 ? argv[4] : NULL); + options = mangle_none(argc > 5 ? argv[5] : NULL); if (key_file) { r = load_key_file(key_file, &key_buf, &key_buf_size); From e2bc5194af65cb8311d4572ab14367ddf42996d9 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 31 Mar 2022 11:22:07 +0200 Subject: [PATCH 11/11] integritysetup: also validate volume name Exactly like for veritysetup/cryptsetup --- src/integritysetup/integritysetup.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/integritysetup/integritysetup.c b/src/integritysetup/integritysetup.c index f95840a8d0..924c15b6eb 100644 --- a/src/integritysetup/integritysetup.c +++ b/src/integritysetup/integritysetup.c @@ -124,6 +124,9 @@ static int run(int argc, char *argv[]) { key_file = mangle_none(argc > 4 ? argv[4] : NULL); options = mangle_none(argc > 5 ? argv[5] : NULL); + if (!filename_is_valid(volume)) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Volume name '%s' is not valid.", volume); + if (key_file) { r = load_key_file(key_file, &key_buf, &key_buf_size); if (r < 0) @@ -174,6 +177,9 @@ static int run(int argc, char *argv[]) { if (argc > 3) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "detach has a maximum of two arguments."); + if (!filename_is_valid(volume)) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Volume name '%s' is not valid.", volume); + r = crypt_init_by_name(&cd, volume); if (r == -ENODEV) { log_info("Volume %s already inactive.", volume);