677 Commits

Author SHA1 Message Date
Ondrej Kozina
5d69c34f59 Reinstate pbkdf serialization flag in device activation.
crypt_activate_by_keyslot_context never respected pbkdf serialation
flag (CRYPT_ACTIVATE_SERIALIZE_MEMORY_HARD_PBKDF).

In fact it worked only when device was activated via passphrase or via
passphrase file. It was never respected when device was activated
by a token for example.

When the internal code was fully switched to activation via keyslot
context the legacy code for passphrase based activation was dropped
and we lost track of serialization flag completely.

This fixes all of the issues so now the serialization flag will be
respected also with tokens (and all other activation methods unlocking
LUKS2 keyslot with memory hard pbkdf).

Fixes: 58385d68d8 (Allow activation via keyslot context)
Fixes: #968.
2025-11-27 14:51:44 +01:00
Kfir Kahanov
4fe1601d9c bitlocker: Open bitlocker devices with clearkey
Always trying to open with clearkey when available
2025-11-21 22:07:01 +02:00
Milan Broz
8da66c3066 verity: Support status info about FEC repaired events
Kernel 6.19 will support additional info on dm-verity status
line that contains number of FEC successful repair events.

This patch adds support to libcryptsetup and veritysetup status command.

Ref. https://lore.kernel.org/dm-devel/074e1ecc-6690-1c22-0dba-454e191e1b6f@redhat.com/T/#m1af31c9c4263fe2b1fb58dee2fd7f0bdf045c463
2025-11-20 17:18:37 +01:00
Milan Broz
e4c498d15b Remove fips argument from crypt_backend_init()
It is really not needed, as it is detected automagically.
2025-11-19 22:09:27 +01:00
Ondrej Kozina
a8e8e39007 Fix possible use of uninitialized variable.
device_tag_size variable was not initialized and used
when device_is_nop_dif returned negative error code.
2025-10-30 13:59:54 +01:00
Milan Broz
232ba8dd3a Add missing crypto backend init in crypt_format_inline.
This triggers abort() in various crypto backends.
2025-06-22 09:35:18 +02:00
Ondrej Kozina
b6f43890f2 Add better errno hint in debug message. 2025-05-27 14:27:14 +02:00
Ondrej Kozina
c735c71ca1 keyring_find_key_id_by_name does not return negative values on error.
It returns 0 on error even if keyring support is compiled out.

There are valid negative constants for thread keyring, process keyring,
etc.
2025-05-27 14:27:14 +02:00
Ondrej Kozina
12eb040943 Create dm-integrity with CRYPT_SUBDEV prefix.
When activating dm-integrity device underneath dm-crypt
with LUKS2 authenticated encryption mode, annotate the
device correctly with CRYPT_SUBDEV prefix. This will help
us to clearly identify dependent device underneath LUKS2 top
level device and we can unify the deactivation code in future
releases.

We have general code deactivating dependent devices already for
LUKS2 reencrytion.

Deactivating newly created devices with pre 2.8.0 cryptsetup
will issue warning about missing devices but the deactivation
will succeed.
2025-05-26 15:35:41 +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
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
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
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
02a48caf7e Print better error message for unsupported LUKS2 AEAD device resize.
Fixes: #804
2025-05-15 15:49:28 +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
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
Ondrej Kozina
eccccfd9b5 Fix drop of volume key from kernel keyring on crypt_suspend.
We do not have to query device-mapper subsystem
twice in order to get volume key description in kernel keyring.

Also there was a bug that wrongly used kernel key type set by function
supposed to set custom user key type used only when linking volume key
in arbitrary kernel keyring on caller demand.
2025-03-06 17:17:36 +01:00
Ondrej Kozina
0a6ee8633a Switch to volume key keyring helpers.
And do not access volume key internals bearing
information whether the key payload was uploaded
in kernel keyring or not.
2025-03-06 17:17:36 +01:00
Ondrej Kozina
5615488196 Refactor and unify naming conventions for internal keyring helpers.
Functions related to uploading/unlinking volume keys in user
requested kernel keyrings are named as follows:

crypt_single_volume_key_load_in_custom_keyring
crypt_volume_key_load_in_custom_keyring
crypt_unlink_key_from_custom_keyring

helpers for unlinking LUKS2 volume keys from thread keyring:

crypt_unlink_key_from_thread_keyring
crypt_unlink_key_by_description_from_thread_keyring
2025-03-06 17:17:36 +01:00
Ondrej Kozina
c9edd942e8 Remove keyring_add_key_to_custom_keyring function.
The was identical function in keyring utilities already,
except the function name.
2025-03-06 17:17:36 +01:00
Milan Broz
d792de66d5 Fix typo in comment. 2025-03-06 17:16:25 +01:00
Milan Broz
f07854ab4f Make libdevmapper internal flags 64bit. 2025-02-16 20:52:37 +01:00
Milan Broz
c497945ab3 Make internal dm_flags 64bit. 2025-02-16 20:52:37 +01:00
Ondrej Kozina
1bec71dbe1 Add temporary helpers to indicate uploaded volume key.
To be removed later when we add clear implementation
to hide access to volume key uploaded attribute.
2025-02-16 18:00:20 +00:00
Ondrej Kozina
9e0bcedbaa Harden LUKS2 volume key compare helper. 2025-02-16 18:00:20 +00:00
Milan Broz
6123ea2e0b Add strict compare volume key comparison for non-LUKS2 devices.
[Modified by Ondrej Kozina]
2025-02-16 18:00:20 +00:00
Ondrej Kozina
f421ec0800 Simplify volume key compare helper.
Since we can now identify volume key not containing
real key data we can make _compare_volume_key more
comprehensible.
2025-02-16 18:00:20 +00:00
Ondrej Kozina
6ee76934fa Harden and limit access to volume key internals.
The volume key structure may often be in configuration
where 'key' member does not contain real data. Some
examples:

- volume key acquired by querring device-mapper where key
  was originaly passed by kernel keyring reference.

- volume key allocated by crypt_alloc_volume_key(size, NULL)

With this patch access to internal 'uninitialized' data result
in failed assert().

For use cases where key data are not needed (keyring reference wrapper,
key length info only) we do not have to allocate and lock the safe
buffer in memory.

Further improvements might to completely hide the volume key internals
and access only via setter and getter functions.
2025-02-16 18:00:20 +00:00
Ondrej Kozina
54d937dfc7 Switch away from accessing volume key internals directly.
Switch current code to use following volume key helpers
for accessing internal properties:

crypt_volume_key_length(), crypt_volume_key_get_key(),
crypt_volume_key_description() and crypt_volume_key_kernel_key_type()

Remaining direct access to volume key internals will be dealt with in
later commits since it requires some further changes.
2025-02-16 18:00:20 +00:00
Ondrej Kozina
88b3da6042 Use new crypt_generate_volume_key to generate weaker keys.
There were two different use cases for weaker keys:

1) empty keys (zero filled buffer)
2) weak 'random' keys not sucking entropy while being generated

Those key types must not be used to encrypt real data. It's used either
to check cipher can be configured sucessfully on the system or as
a fake envelope during metadata repair.
2025-02-06 11:41:26 +01:00
Ondrej Kozina
1326dfbac1 Add generic crypt_generate_volume_key function.
So that we can generate keys with different 'quality'
attribute at one place.
2025-02-06 11:37:04 +01:00
Ondrej Kozina
e9073e6b19 Add keyring key type in volume key comparison function. 2025-02-06 11:30:18 +01:00
Ondrej Kozina
dc75deff51 Drop bogus usage of vk->uploaded.
The volume key uploaded attribute is respected only with
regard to volume keys uploaded in the thread keyring in logon key type.

Here the uploaded attribute was set for volume keys uploaded in
custom user keyrings in custome key descriptions.
2025-02-06 11:21:42 +01:00
Milan Broz
6a8f88ea99 Fix leaks detected by Coverity. 2025-01-27 09:11:40 +00:00
Milan Broz
8364178b38 Update copyright year. 2025-01-15 23:09:36 +01:00
Milan Broz
5eda5f6a38 Fix compatibility for older dmcrypt without integrity_key_size
For older kernel an default HMAC key size we must not set
integrity_key_size option.
2024-12-03 20:28:00 +01:00
Milan Broz
b5672053f5 Use real integrity key size in format operation.
For now, we used zeroed key for dm-integrity format, as there was not
data area. In future, there can be wrapped key scheme, that will require
to setup real key even in this situation.

This patch modifies the integrity format flow that the real key is used
during format.

Mostly based on code from Ingo Franzki <ifranzki@linux.ibm.com>
2024-12-03 20:27:16 +01:00
Milan Broz
491f31c4d4 Add --integrity-key-size option to cryptsetup.
This patch adds support for --integrity-key-size option that can be used
to setup non-standard HMAC integrity key size.
2024-12-03 20:25:54 +01:00
Milan Broz
7b5ac650e5 Allow specific integrity key size.
This patch add support for setting of integrity key size
for LUKS2 devices.

It adds new (optional) JSON "key_size" attribute in segment.integrity JSON object.
If not set, the code use hash length size (backward compatible).

For LUKS2, we do not allow smaller keys than 128 bits.

Mostly based on code from Ingo Franzki <ifranzki@linux.ibm.com>
2024-12-03 20:25:54 +01:00
Milan Broz
ff3e2c6a43 libdevmapper: Support dm-crypt integrity_key_size option
This patch implement support for setting specific integrity key size
option in dm-crypt, available since dm-crypt version 1.28.0.

This can be used for setting non-standard HMAC key length.

Mostly based on code from Ingo Franzki <ifranzki@linux.ibm.com>
2024-12-03 20:25:54 +01:00
Milan Broz
690c22ac7b Switch isLUKS() testing order to avoid static analysis scan confusion.
There is no functional change in this patch except it avoids
strange confusion during some static tests.

The cd->type must be set in this function anyway.
2024-11-28 10:41:18 +01:00
Ondrej Kozina
9f1aee46d5 Rename 'keyring' member to 'keyring_key_type' in volume_key.
The keyring field is misleading since the
field indeed contains the type identification
id.
2024-11-27 12:24:59 +01:00
Milan Broz
768bca1df5 Support plain resize with keyring key. 2024-11-25 14:55:51 +01:00
Milan Broz
4b7920975c Support trusted & encrypted keyring for plain device. 2024-11-25 14:55:47 +01:00
Milan Broz
ae4b4ff4d7 Unlink only volume keys that were previously stored in keyring.
This is only preparation for an extension later, however, the volume
keys should not be unloaded unconditionally from keyring.

Note that all other places dropping keys already check that keys
were uploaded through key ID setting.
(And for suspend unconditional unlink make sense too.)
2024-11-25 13:20:36 +01:00