Commit Graph

653 Commits

Author SHA1 Message Date
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
Milan Broz
9575dadc8b Store keyring type in volume key.
The key_decripion always contains only a key name,
keyring then contains type of keyring as defned un keyring utils.

For now, only LOGON type is used in commands, it will be extended later.
2024-11-25 13:19:42 +01:00
Milan Broz
6be70a0157 Do not include luks2/luks2_internal.h ouside of LUKS2 internal implementation.
The luks2_internal.h contains specific JSON implementations while
luks2.h is generic. Code outside of luks2/ dir should not use internals.

Also luks2.h includes functions prototypes that are used from setup.c.
2024-11-23 20:52:24 +01:00
Ondrej Kozina
fb021bac3d Fix token assignement API.
There was a bug in both crypt_token_assign_keyslot and
crypt_token_unsassign_keyslot where CRYPT_ANY_TOKEN
special value could be passed in token parameter.

It would correctly assign/unassign all tokens to/from
the specified keyslot (or from any in case of CRYPT_ANY_SLOT),
but it returned -1 (CRYPT_ANY_TOKEN) which fited error return
values as per API documentation.

We fixed that by not supporting CRYPT_ANY_TOKEN since it does
not make much sense. It can be workarounded by iterating over
all available tokens and calling crypt_token_assign_keyslot or
crypt_token_unassign_keyslot accodingly.

Fixes: #914.
2024-11-15 15:24:14 +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
5e950924c3 Clarify unbound key parameter in verification routine. 2024-11-08 15:46:09 +01:00
Ondrej Kozina
76d66d6a01 Better name internal activation function. 2024-11-08 15:46:09 +01:00
Ondrej Kozina
ccbc53c169 Do not repeat volume keys upload in custom kernel keyring.
It is uploaded before call in to activation code.
2024-11-08 15:46:09 +01:00
Ondrej Kozina
61aaeaff5a On error drop crypt_key from kernel keyring. 2024-11-08 15:46:09 +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
Ondrej Kozina
d7512d738f Force reencryption keys verification after metadata reload.
After switching to reencryption by keyslot context,
the digest was not properly verified before crash recovery.
We need to reverify reencryption digest after metadata
reloads unconditionally.
2024-11-08 15:46:07 +01:00
Ondrej Kozina
6506d324ee Better name routine verifying any available digest.
also drop unused parameter from internal routine.
2024-11-08 14:09:08 +01:00
Ondrej Kozina
a93921c226 Avoid dereferencing NULL pointer. 2024-11-04 12:24:27 +01:00
Ondrej Kozina
f5b7a576b3 Do not dereference the context pointer before assert. 2024-11-04 12:24:20 +01:00
Ondrej Kozina
f85c31677c Simplify bitlk activation by volume key.
Let's not copy volume key again when not necessary.
2024-10-30 16:13:49 +01:00
Ondrej Kozina
5b83ae8ec2 Enable fvault activation by keyslot context. 2024-10-30 13:28:56 +00:00
Ondrej Kozina
652835a1f8 Verify fvault2 key size in before activation by volume key. 2024-10-30 13:28:56 +00: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
45af8de034 Allow shared activation of device in reencryption.
This would be regression when we later switch all internal
implementation to keyslot context.
2024-10-30 13:25:57 +01:00
Ondrej Kozina
e4bf1f91b9 Properly block opal devices from deferred deactivation.
The check did not work properly for stacked dm_crypt over
hw opal devices.

Also it did not work at all for active dm mappings with
missing (or detached) LUKS2 metadata.
2024-10-09 09:57:49 +00:00
Ondrej Kozina
7c83d4e639 Simplify internal crypt_get_hdr for LUKS2 type. 2024-10-09 08:04:19 +00:00
Milan Broz
faeb0c3483 Fix a possible segfault in deferred deactivation.
For device without a type code shoud not try to use
strcmp function.

This can happen for example if deferref flag is used
for device without proper DM-UUID where init_by_name
does not set know device type.

Thanks Clément Guérin for the report.

Fixes: #910
2024-10-08 13:08:18 +02:00
Ondrej Kozina
8ad28547ee Simplify keyslot context initialization code. 2024-09-29 19:14:56 +00:00
Ondrej Kozina
6ef0650332 Rename internal keyslot context functions. 2024-09-29 16:10:44 +00:00
Ondrej Kozina
e4d25d18eb Remove needless double statements. 2024-08-26 17:40:04 +00:00