Commit Graph

4475 Commits

Author SHA1 Message Date
Milan Broz
e6f6ee9291 Do not allow PBKDF benchmark over maximum allowed threads.
Unfortunatelly the benchmark function cannot return
corrected parallel cost, so it must fail.

Note that some backends (like OpenSSL) also limits maximal thread count,
so currently it was clapped at 4 for luksFormat and 8 for benchmark.

This patch set it all to PBKDF internal parallel limit.
2025-05-26 11:30:37 +02:00
Milan Broz
6b832b8d03 Add keyslot check code.
This patch adds keyslot randomness analysis to cryptsetup repair command
to check for a detectable corruption of binary area.

It uses Chi2 analysis. This check basically replaces external keyslot
checker program.
2025-05-22 16:09:50 +02:00
Milan Broz
f29337aa9f Define opaques crypt_device struct in local header. 2025-05-22 16:09:50 +02:00
Milan Broz
f5bbc499d4 Move LUKS_STRIPES definition to macros definitions.
To be used in repair code later.
2025-05-22 16:09:50 +02:00
Milan Broz
4fd3db5e93 Fix cryptsetup repair to use header device and UUID spec. 2025-05-22 16:09:50 +02:00
Milan Broz
cbf6fa9d07 Fix external slot checker to work with LUKS2. 2025-05-22 16:09:50 +02:00
Milan Broz
9e4a31887e ci: retry update for Ubuntu repos 2025-05-22 16:08:45 +02:00
Milan Broz
680567615a tests: add LUKS2 integrity tests 2025-05-22 14:53:27 +02:00
Milan Broz
24b126252b tests: add integritysetup inline tags tests 2025-05-22 14:53:21 +02:00
Milan Broz
324926e2d8 LUKS2: support Inline tags format and activation for integrity protection 2025-05-22 14:53:16 +02:00
Milan Broz
3ec14c8668 Move (and rename) UUID helpers to libdevmapper source. 2025-05-22 14:53:12 +02:00
Milan Broz
d967c9aaf0 Unify checking for LUKS2 intermediate device.
Use dm_get_active_iname that should be used on all places.

This function return integrioty device name if it shoudl be
maintained by LUKS2 context directly.

Code must not touch other devices that it does not own.
2025-05-22 14:53:03 +02:00
Milan Broz
352cda0302 integrity: Detect PI/DIF capable devices in inline mode.
And print better error if not.
2025-05-22 14:48:56 +02:00
Milan Broz
006ebd832f integrity: support Inline tags format and activation
Support inline format in API with crypt_format_inline().

Add --integrity-inline option to integritysetup.
2025-05-22 14:48:56 +02:00
Milan Broz
49ccafe38a integrity: Add inline flag to API
Process new dm-integrity flag (hw inline mode).
2025-05-22 14:48:56 +02:00
Milan Broz
29fcd88d86 integrity: Support superblock V6
This one include inline flag support.
2025-05-22 14:48:56 +02:00
Milan Broz
c4ce270568 Avoid false positive for static scan (integer overflow).
Avoid adding signed type to unsigned one.
2025-05-22 10:31:22 +02:00
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