Commit Graph

194 Commits

Author SHA1 Message Date
Milan Broz
8440e59b7b Fix possible integer overflow (for unused variable). 2025-05-22 10:31:22 +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
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
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
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
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
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
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
Ondrej Kozina
3c5aa4ef59 Remove unused code.
Due to complete shift to device activation via keyslot context,
remove all remaining internal code activating device by passphrase
or by token.
2024-11-08 15:46:28 +01:00
Ondrej Kozina
dd3441621a Fix reencryption keys loading in kernel keyring.
Manage keys upload in kernel keyring (internal logon type for dm-crypt
segments) in single location in-before device activation.
2024-11-08 15:46:09 +01:00
Milan Broz
33ed0d587e Fix typos found by lintian. 2024-10-30 19:11:29 +01:00
Ondrej Kozina
651a089f38 Add crypt_reencrypt_init_by_keyslot_context.
It allows initializing reencryption operation by
providing access to volume keys via keyslot context.
2024-10-30 13:25:57 +01:00
Ondrej Kozina
81d8c12cbe Fix LUKS2 decryption when volume key digest id not zero.
During the initialization phase future moved data segments
were incorrectly assigned (hardcoded) to digest with id 0.

When the default segment was assigned to a different value,
the initialization failed and was aborted.

This patch fixes the issue by assigning intermediary segments
to corect digest id.

Reported-by: 谢致邦 (XIE Zhibang) <Yeking@Red54.com>
2024-10-11 14:55:08 +02:00
Ondrej Kozina
63bb997b41 Abort online reencryption for misconfigured devices.
Hard abort is justified here. The online reencryption on
data devices that do not support O_DIRECT io flag is
dangerous and leads to data corruption. This should be
impossible to hit due to a patch that handles it
in initialization phase. Better safe than sorry.
2024-08-27 14:00:41 +00:00
Ondrej Kozina
9991cbc306 Harden online reencryption checks in initialization phase.
Verify the data device supports O_DIRECT io flag in
the initialization phase. Online reencryption is not
safe unless we can read and write the data in direct
mode.
2024-08-27 14:00:41 +00:00
Milan Broz
5fb6d711c1 Fix clang possible rh NULL dereference warning. 2024-07-10 09:48:10 +02:00
Milan Broz
661f57def4 Use SPDX license identifiers.
This patch switches code to SPDX one-line license identifiers according to
https://spdx.dev/learn/handling-license-info/
and replacing long license text headers.

I used C++ format on the first line in style
// SPDX-License-Identifier: <id>
except exported libcryptsetup.h, when only C comments are used.

The only additional changes are:
- switch backend utf8.c from LGPL2+ to LGPL2.1+ (as in systemd)
- add some additional formatting lines.
2024-06-03 16:38:15 +00:00
Milan Broz
bd0ef58b3a Update copyright notice to include 2024 year. 2024-01-23 16:10:44 +01:00
Ondrej Kozina
135ed491d1 Do not drop keys from keyring on successfull reencryption recovery.
The key might be needed in activation of ordinary LUKS2 device
provided the recovery took place in before device activation
and actually finished LUKS2 device reencryption.

Fixes: #863.
2024-01-22 12:13:40 +01:00
Daniel Zatovic
7fb98caa79 Allow activating multi key devices using VKs in keyring.
We already support activation of a device using a volume key in keyring.
However, in case of multi-key devices (i.e. device with reencryption
running) we need to supply two volume keys.
2024-01-19 16:26:30 +00:00
Daniel Zatovic
5814b39cdd Allow linking multiple VKs (also in reencryption).
If the device is in reencryption, it has two active volume keys. Linking
the VK to keyring is not supported for such devices, because the API
only counts with one key. This commit modifies the API
crypt_set_keyring_to_link to allow passing multiple keyring key names.
2024-01-19 16:26:30 +00:00
Ondrej Kozina
bd0768a42a Respect CRYPT_ACTIVATE_SHARED in reencryption. 2024-01-05 14:22:07 +01:00
Milan Broz
5d50617594 Tweak some error messages. 2023-11-29 09:21:01 +01:00
Ondrej Kozina
f623eb2e99 Add more onlyLUKS helpers for convenience. 2023-11-06 14:47:41 +01:00
Ondrej Kozina
6296e8d4f8 Improve debug output for kernel keyring.
Add more context to possibly failing kernel keyring routines
in log debug output.

Mostly split debug output for errors while trying to search the kernel
key by description and errors while trying to read/unlink the key
by its id.
2023-09-27 19:37:35 +00:00
Ondrej Kozina
f147c823ea Reduce code duplication in kernel keyring utilities. 2023-09-25 18:59:09 +00:00
Milan Broz
5628de1f65 Fix unused parameter in LUKS2 reencryption handlers. 2023-08-28 12:42:37 +02:00
Milan Broz
e14316f132 Mark unused parameters. 2023-08-28 12:42:37 +02:00
Ondrej Kozina
fd91de82ad Move integrity fields in json_segment_create_crypt segment helper.
The integrity is optional parameter of dm-crypt segment definition.
Move the low level json code in appropriate json helper.

It will make adding new segment easier. The future hw-opal-crypt
segment will inherit all crypt fields.
2023-05-29 11:09:04 +02:00
Ondrej Kozina
c81c3d1fc0 Remove unused code in reencryption. 2023-04-19 10:01:51 +02:00
Milan Broz
a617c23ccc Disable reencryption for DAX devices.
Device-mapper is not capable to stack DAX/non-DAX devices
in mapping table, so online reencryption cannot work.

Fixes: #760
2023-03-31 10:51:34 +00:00
Milan Broz
a752e571ab reencrypt: fix checking of context name arguments. 2023-03-09 17:06:58 +01:00
Ondrej Kozina
cb177c5076 Improve code clarity a bit.
It also silences false positive warning with older compilers.
2023-03-08 15:23:32 +01:00
Ondrej Kozina
4ebc6a1616 Correct error paths in LUKS2 reencryption code path. 2023-03-08 15:23:25 +01:00
Milan Broz
72f799b393 Update Copyright year. 2023-02-09 17:11:18 +01:00
Ondrej Kozina
b0779c6529 Fix --disable-luks2-reencryption configuration option. 2022-11-18 16:40:48 +01:00
Ondrej Kozina
81c56a8395 Move assert include in internal header files. 2022-11-16 16:54:33 +01:00
Milan Broz
f312ba6256 Fix json_object_copy return value check.
Reported by Coverity scan.
2022-11-14 13:05:04 +00:00
Milan Broz
82b56300cd Wrap some very long lines. 2022-10-01 22:35:57 +02:00
Ondrej Kozina
01c032df04 Do not reload LUKS2 metadata when not necessary.
Following API calls trigerred LUKS2 metadata reload
from storage in case of failure:

crypt_convert
crypt_keyslot_add_by_key
crypt_keyslot_add_by_keyfile_device_offset
crypt_keyslot_add_by_passphrase
crypt_keyslot_change_by_passphrase
crypt_reencrypt_init_by_keyring
crypt_reencrypt_init_by_passphrase

This patch replaces LUKS2 metadata reload with
backup LUKS2 metadata copy kept in memory that is updated on
each sucessfull metadata write and rolled back to it whenever
needed in any of those calls listed above.
2022-08-19 14:46:42 +02:00
Ondrej Kozina
093adfc5f9 Fix user defined moved segment size in LUKS2 decryption.
--hotzone-size argument was ignored in cases where actual data size
was less than original LUKS2 data offset.
2022-08-01 07:05:06 +00:00
Ondrej Kozina
25b877a403 Fix bug in reencryption parameters verification. 2022-07-28 07:57:36 +00:00
Ondrej Kozina
13f6dfa61f Add proper version data to reencryption verification digest.
LUKS2 decryption requires new online-reencrypt version
flag (v3).

The verification digest performs coding
for version suffix in "online-reencrypt-v" flag string
as follows:

'v1' :  unused (no digest)
'v2' :  0x30 + 2   = 0x32 = '2'
'v3' :  0x30 + 3   = 0x33 = '3'
(...)
'v10':  0x30 + 10  = 0x3A = ':'
'v11':  0x30 + 11  = 0x3B = ';'
(...)
'v207': 0x30 + 207 = 0xFF
2022-07-12 14:03:25 +02:00
Ondrej Kozina
8493f6afd5 Change size of requirement version to 1 byte.
Mostly due to reencryption verification routine
currently expects only single byte of version
data to create digest from.
2022-07-12 13:54:24 +02:00
Milan Broz
1a55b69a0f Fix leak of dm target structure.
The dmd_source need to be cleared with dm_targets_free().
2022-07-07 09:17:13 +00:00