2116 Commits

Author SHA1 Message Date
Vojtech Trefny
8573eb515d Fix docstring for crypt_persistent_flags_set
Add all persistent flags and use full name of the flags.
2025-03-06 17:14:11 +01:00
Milan Broz
41b8b02ccf verity: Add support for restart/panic on error flag.
Introduced in kernel 6.12.
2025-02-16 20:53:35 +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
036ed52999 Remove volume key internals from internal API. 2025-02-16 18:00:20 +00: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
843fac813f Indicate volume key with initialized key content.
volume key does not have to always contain properly
initialized key content (binary buffer). Add helper
to notify callers about it.
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
f86ab28ad6 Add crypt_safe_alloc_size helper.
Returns size of the payload. Zero means error.
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
fd9be9e777 Add severeal helpers (get methods) for volume key.
crypt_volume_key_length() for key length
crypt_volume_key_get_key() to access key data (if initialized)
crypt_volume_key_description() for kernel key description
crypt_volume_key_kernel_key_type() for kernel keyring key type
2025-02-16 18:00:20 +00:00
Milan Broz
a2b2c6a8ae Add workaround for memory sanitizer that cannot recognize explicit_bzero.
Otherwise it produces a lot of false positives in OSS-Fuzz.
2025-02-08 15:06:36 +01:00
Ondrej Kozina
a965a88992 Add const to pointer in blob_serialize() function.
the data is read-only in this context.
2025-02-06 11:41:30 +01: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
4f90213a5b Drop redundant member initialization in volume key.
The memory is already initialized to zeroes after allocation.
2025-02-06 11:30:18 +01:00
Ondrej Kozina
5ee549de1e Remove volume_key struct from fvault2 code.
No volume_key feature is used in the code and it
will make further changes easier.
2025-02-06 11:30:18 +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
Ondrej Kozina
ab9d4fec3b Do not parse emtpy '-' key string with null ciphers.
The loop is not entered but for later patche lets make
it obvious it is not needed.
2025-02-06 11:21:42 +01:00
Ondrej Kozina
da84c79a5b Use crypt_volume_key_next helper in bitlk. 2025-02-06 11:21:42 +01:00
Milan Broz
e257def910 Remove redundant check for dm-integrity mapping table params section.
The dm-integrity table always contains number of feature arguments
(since introduction in kernel 4.12).

Moreover, the code already dereferences params field, so the test
make no sense.

Found by CodeQL check.
2025-01-28 13:03:10 +00:00
Milan Broz
a45fb0a90d Do not include dlfcn.h if external token support is disabled.
Fixes: #925
2025-01-27 12:33:52 +00:00
Milan Broz
29741d91e6 Use #if in bitops.h. 2025-01-27 11:05:08 +00:00
Milan Broz
1e441bf75c Use #if for rest of defines. 2025-01-27 11:05:08 +00:00
Milan Broz
d9404821a6 Use #if for HAVE_BLKID_* defines. 2025-01-27 11:05:08 +00:00
Milan Broz
e5405f2fd8 Use #if for HAVE*_H defines. 2025-01-27 11:05:08 +00:00
Milan Broz
37d52876b9 Use #if for other ENABLE* options. 2025-01-27 11:05:08 +00:00
Milan Broz
ff81791308 Use #if for ENABLE_AF_ALG. 2025-01-27 11:05:08 +00:00
Milan Broz
c21c746eff Use #if for USE_UDEV. 2025-01-27 11:05:08 +00:00
Milan Broz
bb304f45bd Use #if for KERNEL_KEYRING. 2025-01-27 11:05:08 +00:00
Milan Broz
f64f6fb9e8 opal: Fix error table offset
The error table was partially wrong (for codes >0x0b)

Let's use exact enum codes according to TCG Core spec (5.1.5).

This also fixes CodeQL warning.
2025-01-27 11:04:25 +00:00
Milan Broz
5c795885c5 opal: update copyright 2025-01-27 11:04:25 +00:00
Milan Broz
6a8f88ea99 Fix leaks detected by Coverity. 2025-01-27 09:11:40 +00:00
Milan Broz
7ffa8ee28a Fix integer cast for sector_size.
Found by Coverity scan.
2025-01-27 09:11:40 +00:00
Milan Broz
36574dd114 Avoid if (not NULL) free().
This fixes some COdeQL warnings.
2025-01-16 15:54:09 +01:00
Milan Broz
8364178b38 Update copyright year. 2025-01-15 23:09:36 +01:00
Milan Broz
bfae421c52 bitlk: Clarify activation error message if clear key is present.
Fixes: #929
2025-01-15 13:35:29 +01:00
Milan Broz
b18cefcc71 Detect out of memory in KDF in keyslot derivation.
For OpenSSL and gcrypt we can detect that Argon2 failed on malloc,
report it to user (and return ENOMEM instead of EINVAL).
2024-12-12 22:45:21 +00:00
Milan Broz
7cabaa5d70 pbkdf: Do not allow memory cost that cannot be used in size_t
For 32bit platforms size_t is 32bit integer and unfortunately
our maximum hard limit overflows by 1.

Stop validation if this happens (it cannot be passed to malloc()
and similar functions anyway).

There should be no compatibility change, as such memory
is not allocatable on 32bit anyway.
Other platforms have 64bit size_t.
2024-12-12 22:45:21 +00:00
Milan Broz
f8788f347e Mark all sizes in status and dump output in the correct units.
NOTE: This is possibly an incompatible change as it changes text output.

Since the support of --sector-size option, the description "sectors"
became ambiguous as it usually means 512-byte sectors (device-mapper unit).

Major confusion occurs when the sector size is 4096 bytes while units display
is in 512-bytes.

Unfortunately, there is no clear compatible way, so this patch adds
[512-byte units] marker and also additional byte size value.

All other fields that display units are changed to use the "[units]" format.

The integrity format is also unified with the common style with ':' as a separator.

Fixes: #884.
2024-12-12 15:56:00 +00: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
Ondrej Kozina
1bea029cef Lock volume key structure in memory.
This was probably oversight in original commit
introducing support for selective memory locking
on sensitive data only.

Fixes: db65a5ceac
2024-12-03 13:33:59 +01:00