Commit Graph

4458 Commits

Author SHA1 Message Date
Milan Broz
8440e59b7b Fix possible integer overflow (for unused variable). 2025-05-22 10:31:22 +02:00
Milan Broz
465043300d Check for unbound keyslot in convert.
The type cannot be converted to LUKS1 if there is an unbound keyslot.

It is already covered by digest count check, but in some specific
use cases the explicit check can catch a new problem.
2025-05-20 18:24:01 +02:00
Milan Broz
50b762ab94 Add note to man page for LUKS convert requirements. 2025-05-20 18:23:55 +02:00
Milan Broz
11dd8d318c Add debug messages for incompatible LUKS1 conversion.
If LUKS2 keyslot is not compatible, print debug message with more
specific info.

Fixes: #850
2025-05-20 18:23:48 +02:00
Milan Broz
e5c2892cd5 cryptsetup: Adjust XTS keys size also if cipher is specified with capi: prefix.
Fixes: #776
2025-05-20 16:58:14 +02:00
Ondrej Kozina
bd2f7eb671 Harden digest verification when adding new unbound key.
While adding new unbound key there is a check whether the
passed key parameter matches current volume key or not. If it
matches the existing volume key we handle the LUKS2 keyslot
addition as an ordinary LUKS2 keyslot (not unbound).

If the check failed we continued with the operation of adding
LUKS2 unbound keyslot. But we did not check if the error
was not a more general issue for example with in-memory metadata.

Let's contine with the operation only if the return code is
expected -EPERM (not matching digest) or -ENOENT (not matching any
existing unbound key).
2025-05-20 16:57:45 +02:00
Milan Broz
a39a0d00e5 Do not use pagesize as fallback for block size.
Device must process MAX_SECTOR_SIZE as it is encryption
block size, so if it does not work with this value, it will
fail anyway.

Fixes: #943
2025-05-20 16:44:06 +02:00
Milan Broz
9484eee48a Move wipe debug message and add alignment info. 2025-05-20 16:44:06 +02:00
Ondrej Kozina
5689fb46e7 Add error message for missing volume key.
Add specific error message when user does not provide
all necessary volume keys via --volume-key-file or
--volume-key-keyring parameters.
2025-05-20 15:29:14 +02:00
Ondrej Kozina
4d5aa29955 Add tests for reencryption by keyslot context in CLI. 2025-05-20 15:29:14 +02:00
Ondrej Kozina
ad21502d06 Extend options for initializing reencrypiton from cli.
This patch extends available options for LUKS2 reencryption
initialization.

When no specific keyslot is selected by --key-slot option, all active
keyslots needs to be refreshed. With current patch user does not
have to provide passphrase via interactive prompt when token is
available and can unlock assigned keyslot. Only keyslots not assigned
to tokens (and unlocked by tokens) must be provided with passphrase.

Furthermore user may directly narrow down selection of keyslots
suitable for reencryption by specifying either --token-id, --token-type
or --token-only option. In that case only keyslots associated to the
specific token (--token-id) or specific type (--token-type) or any token
specified in LUKS2 metadata (--token-only) will be used for
reencryption and refreshed with new volume key. All other keyslots will
not be refreshed and will be erased after reencryption is finished. The token
association will be carried over to refreshed keyslots.

The third new method available in this patch is support for reencryption
by passing volume keys directly. The LUKS2 device may be reencrypted
by passing volume keys by --volume-key-file, --new-volume-key-file,
--volume-key-keyring or --new-volume-key-keyring options. With this
options user may reencrypt device with no active keyslots. If there's
any active keyslot and volume keys are passed directly user may enforce
volume key based reencryption by passing --force-no-keyslots option.
If --force-no-keyslots option is passed all active keyslots will be
erased after reencryption operation is finished and the device may be
unlocked only by passing new volume key directly.

Fixes: #774, #780.
2025-05-20 15:29:14 +02:00
Ondrej Kozina
0dc630b911 Allow reencryption resume by new methods.
The reencryption operation can now be resumed
using tokens or by specifying volume keys
directly.
2025-05-20 15:29:14 +02:00
Ondrej Kozina
cbcb8c6ee3 Allow device in reencryption to be activated by volume keys in files.
Allow to use up to two --volume-key-file options (paired with
two --key-size options) for device in-reencryption activation.
2025-05-20 15:29:14 +02:00
Ondrej Kozina
5a84dc87e3 Return -ENOENT if digest is missing.
If there is no digest associated with segment,
for example during reencryption mode encrypt initialization,
return -ENOENT in LUKS2_digest_verify_by_segment.
2025-05-20 15:29:14 +02:00
Ondrej Kozina
1a7e89c55d Allow crypt_reencrypt_init_by_keyslot_contexts with no active keyslots.
With this commit reencryption can run without any active
keyslot containing current (or optional future) volume key.

In such case new volume key must be provided via CRYPT_KC_TYPE_KEY
keyslot context and by adding CRYPT_REENCRYPT_CREATE_NEW_DIGEST flag in
reencryption parameters during reencryption initialization in
crypt_reencrypt_init_by_keyslot_contexts.

The new flag can not be combined with CRYPT_REENCRYPT_RESUME_ONLY
flag.
2025-05-20 15:29:14 +02:00
Ondrej Kozina
804ee74a46 Reduce memory allocations in vk keyring keyslot context. 2025-05-20 15:29:14 +02:00
Ondrej Kozina
b497306934 Add method in keyslot_context to get stored key size.
Only applicable for CRYPT_KC_TYPE_KEY and
CRYPT_KC_TYPE_VK_KEYRING.
2025-05-20 15:29:14 +02:00
Ondrej Kozina
6c74b6f9c8 Update crypt_keyring_get_key_by_name debug message. 2025-05-20 15:29:14 +02:00
Ondrej Kozina
548de244c5 Add internal helper to get key size by key description. 2025-05-20 15:29:14 +02:00
Ondrej Kozina
0363ea7c57 Add utils keyring helper to get keyring key size by id. 2025-05-20 15:29:14 +02:00
Ondrej Kozina
ae2a7cfc33 Use crypt_get_old_volume_key_size in action reencrypt. 2025-05-20 15:21:44 +02:00
Ondrej Kozina
4e94c8d809 Add crypt_get_old_volume_key_size API.
It allows to get former (old) volume key size
from LUKS2 device in reencryption state when
there's at least one keyslot containing encrypted
volume key.
2025-05-20 15:21:44 +02:00
Milan Broz
3dcb532bd3 verity: Check hash device size in advance
Let's check block device size required for Merkle tree and superblock.
If it is a file, allocate the size in advance with fallocate.

This should print better error message if hash device is too small.

Fixes: #808
2025-05-20 14:59:09 +02:00
Milan Broz
02a48caf7e Print better error message for unsupported LUKS2 AEAD device resize.
Fixes: #804
2025-05-15 15:49:28 +02:00
Milan Broz
bc6c3092fa ci: call dnf clean all before install 2025-05-12 14:30:36 +02:00
Ondrej Kozina
0cf87a4151 Add support for --decrypt init by keyslot contexts. 2025-05-12 11:46:16 +02:00
Ondrej Kozina
cf29d51589 Refactor activation by volume key(s) in helper routine. 2025-05-12 11:46:16 +02:00
Ondrej Kozina
8fcd8a78d8 Make changes in token unlock for further changes in reencrypt action.
The token preference condition is moved outside the
try_token_unlock routine body.
2025-05-12 11:46:16 +02:00
Ondrej Kozina
5f48657f4d Move try_token_unlock to luks utils.
and rename it to luks_try_token_unlock.
2025-05-12 11:46:16 +02:00
Ondrej Kozina
4493d9ad3e Switch reencrypt --encrypt initialization to keyslot context.
This allows to simplify init_keyslot_context and we can only
pass single pointer from luksFormat routine.
2025-05-12 11:46:16 +02:00
Ondrej Kozina
9f0dd9cc4c Move init_keyslot_context in luks utils.
and rename it to luks_init_keyslot_context.
2025-05-12 11:46:16 +02:00
Ondrej Kozina
261bef3409 Fix mistake in reencryption change detection logic.
There's no reason to have bool variable for
key size change specifically.
2025-05-12 11:46:16 +02:00
Ondrej Kozina
ff7a21eb94 Refactor get_adjusted_key_size. 2025-05-12 11:46:16 +02:00
Ondrej Kozina
48683f7316 Fix memory leak on error path in luksAddKey. 2025-05-12 10:25:01 +02:00
Ondrej Kozina
e48d5b6d19 Verify volume key passed by kernel keyring.
Verify volume key passed by --volume-key-keyring before
trying to add new keyslot.
2025-05-12 10:25:01 +02:00
Ondrej Kozina
723ad6afdf Print error message in cryptetup cli.
Prints "Volume key does not match the volume" when
passed VK's digest does match the stored one.
2025-05-12 10:25:01 +02:00
Ondrej Kozina
79d8a8b840 Drop error message about mismatching volume key.
crypt_activate_by_keyslot_context() returns -EPERM
when key was passed either by CRYPT_KC_TYPE_KEY or
CRYPT_KC_TYPE_VK_KEYRING and does not match the digest
stored in metadata.

Sometimes caller might want to verify if the passed
keyslot contexts matches the effective volume key
or not without the error message. It can be
printed from command line tools when needed.
2025-05-12 10:25:01 +02:00
Milan Broz
5f8cab5d4a FAQ: add volume key example.
And remove requests for private mails.
2025-05-11 21:20:44 +02:00
Milan Broz
dd68e53082 ci: check FIPS mode without fips-mode-setup 2025-05-01 17:27:36 +02:00
Milan Broz
9153c9c3c0 Fix unused PIM query actions list. 2025-04-29 08:16:26 +02:00
Ondrej Kozina
c1b5e412c9 Drop unreachable error message.
LUKS2_reencrypt_status can not return CRYPT_REENCRYPT_INVALID.
2025-04-27 14:14:13 +02:00
Ondrej Kozina
fa84cb8a55 Fix LUKS2_config_get_requirements prototype.
It never returns any error. Make it void.
2025-04-27 14:14:13 +02:00
Milan Broz
221d6ac345 ci: disable rhel10-fips job
Someone decided to remove fips-mode-setup instead
of providing backward compatibility (and just set fips=1).

Upstream is not a RH testbed, remove this job.
2025-04-27 14:09:45 +02:00
Milan Broz
d2fc31da28 ci: update compiler versions 2025-04-27 11:21:30 +02:00
Milan Broz
8b14558b94 ci: Run lintian and codespell. 2025-04-27 11:21:30 +02:00
Milan Broz
e936d4395b Opal: limit PSID keyfile read if not set otherwise
PSID length is de-facto always 32 alphanumeric characters.

Limit the read of PSID from keyfile to this limit
(if not set by explicit size option).

This eliminates mistakes when the keyfile contains EOL characters.

Also, some OPAL drives accepts PSID with any suffix, this patch
unifies processing (it works everywhere the same).
2025-04-22 15:30:38 +02:00
Milan Broz
b166747fee ci: Run rawhide csmock.
Switch to rawhide version of csmock.
2025-03-25 22:54:16 +01:00
Milan Broz
3e114bcb1e Fix warning about NULL argument in setsockopt()
This should fix a warning produced by scan-build-20

warning: The 4th argument to 'setsockopt' is NULL but should
not be NULL [unix.StdCLibraryFunctions]
2025-03-24 13:46:59 +01:00
Milan Broz
1df9a4c566 Fix dirfd() handling.
Detected by scan-build-20.
2025-03-24 13:46:59 +01:00
Milan Broz
7f0724f46c Opal2: Do not use IOC_OPAL_ERASE_LR
The IOC_OPAL_ERASE_LR uses Erase method, that is defined only
in Single user mode (SUM) and works only on SUM-enabled LRs.

As we do not use SUM yet, this always fails.

Moreover, Erase has many side effects - it resets user password to ""
and disables locking for LR.

We already use fallback to IOC_OPAL_SECURE_ERASE_LR, which is GenKey
method (defined in Core spec) that must be always available.
It effectively regenerates the LR encryption key.
2025-03-24 12:34:43 +01:00