2116 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
Kfir Kahanov
72173b2777 bitlocker: Handle getting NULL passwords 2025-11-21 22:07:01 +02:00
Kfir Kahanov
f304132b2b bitlocker: Support clearkey
Clearkey does not mean partially encrypted, and may be on fully
encrypted volumes.
2025-11-21 22:07:01 +02:00
Milan Broz
0779c8ceed Explicitly mention units (bytes) for volume key in header. 2025-11-21 16:34:47 +01: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
Milan Broz
ccc0c69cd7 Add fips_mode check for kernel.
Akso add a separate function so we can detect that kernel and crypto
lib is in different FIPS state (only for testing).
2025-11-19 22:09:27 +01:00
Ondrej Kozina
bbc053682a Do not read test hotzone device repeatadly.
While allocating internal data structure for a device
overlaying reencryption hotzone we accidentally read
tested the device in each reencryption step. This
was suboptimal so now the device is read only once
while initializing the reencryption device-mapper stack.
2025-11-17 13:56:39 +01:00
Ondrej Kozina
5490d28aa4 Drop never used code in storage wrapper utils.
It was never used...
2025-11-13 15:24:12 +01:00
Ingo Franzki
296eb39c60 Changes to support PHMAC with integritysetup and cryptsetup
Make the PHMAC integrity algorithm know to libcryptsetup.

The size of a key for PHMAC is not known, because PHMAC gets an opaque
blob as key, who's physical size has nothing to do with the cryptographic
size. Thus, let INTEGRITY_key_size() and crypt_parse_integrity_mode()
return the required_key_size as key size for PHMAC, or -EINVAL if
required_key_size is zero, to indicate that the size is unknown.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2025-11-13 09:21:40 +01:00
Ondrej Kozina
917b6836a9 Always use json-c types in internal code.
Sometimes we used "struct json_foo_bar" and sometimes "json_foo_bar"
json-c defined type. Stick with one notation in internal code.
2025-11-12 13:13:02 +01:00
Ondrej Kozina
b36d4be8fa opal: supress confusing debug messages.
Do not print sed-opal spefic debug messages with confusing
error codes if ioctl() call failed with -1. Usually that means
the kernel does not support sed-opal interface or the requested
ioctl number is not implemented.
2025-11-06 11:14:56 +01:00
Ondrej Kozina
0a8e7da7ae opal: fix debug message on failed sed-opal ioctl.
ioctl syscall always returns -1 on error (see ioctl(2)).
On error the actual reason is reported via errno varible.
Let's store the original errno code in the variable
so that it can be printed out in debug mode.

Before this fix the debug message always reported "Operation not
permited" (the translation of errno EPERM (1)).
2025-11-06 11:09:43 +01:00
Ondrej Kozina
83a7310ca2 opal: do not initialize LRs array in activation.
The lr member in opal_lr_act kernel structure is
ingnored unless the device is being activated in SUM
mode.

See kernel implementation of IOC_OPAL_ACTIVATE_LSP
in block/sed-opal.c
2025-11-03 16:05:08 +01:00
Ondrej Kozina
441802773f opal: simplify User setup routine.
Reduce memory copying by reusing nested structure in opal_lock.
2025-11-03 16:05:08 +01:00
Ondrej Kozina
cc66b1fa52 opal: pull User setup in separate function. 2025-11-03 16:05:08 +01:00
Ondrej Kozina
a0d5d2bf5e opal: pull individual range setup in separate function. 2025-11-03 16:05:08 +01:00
Ondrej Kozina
61dbb69319 opal: pull reuse of active device in separate function. 2025-11-03 16:05:08 +01:00
Ondrej Kozina
32b33541a8 opal: pull LSP activation in separate function. 2025-11-03 16:05:08 +01:00
Ondrej Kozina
346db2e42a opal: add a named constant for TCG FAIL status.
Will be checked upon later when we add support
for OPAL2 SUM Reactivate method.
2025-11-03 16:05:08 +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
Ondrej Kozina
9810c6fb2f Read integrity profile info from top level device.
When formating device with --integrity-inline option
there's a check if underlying device properly advertise
integrity profile support. The check did not work
properly for partition device nodes. We have to read
integrity profile info from top level block device.

Fixes: #964.
2025-10-17 15:25:32 +02:00
Ondrej Kozina
4d98add260 opal: Submit PSID reset command to R/W file descriptor.
The PSID reset erases the block device it's submitted to
succesfully.

By submitting the command to read-only fd previously
there were partition device nodes still visible in
the /dev directory because kernel does not trigger rescan
after OPAL2 PSID reset. Even though all the partition were
actually erased (including the partition table).

We workaround the issue by submitting the PSID reset
to R/W fd so that it triggers rescan event on close.
2025-10-06 10:37:37 +02:00
Milan Broz
0eaaa4553e Fix handling of too long label and subsystem fields
These LUKS2 labels are stored in the binary header area that has limited size.

While we have been silently truncating strings here, it is something that
is not expected, as the final label is then different than expected.

Let's fix the code to explicitly print and return error here.

Also remove the comment about duplicate check. It is incorrect  optimization,
as some users will expect a real write on disk, we should no skip it.

Fixes: #958
2025-10-01 21:41:55 +02:00
Ondrej Kozina
3a8feb8be7 Improve check for a function attribute support.
The compiler may advertise function attribute support
with __has_attribute operator even though it does
not implement the feature on some architecture.

This fixes the issue with  GCC 11 on ppc64le with
__attribute__((zero_call_used_regs("used"))).

Fixes: #959.
2025-09-11 14:18:39 +02:00
Maxim Suhanov
68d4749d8a bitlk: implement validation of FVE metadata
This commit implements FVE metadata block validation based on:
* CRC-32 (to detect random corruption);
* AES-CCM-encrypted SHA-256 (to detect malicious manipulations).

The hash-based validation requires us to decrypt the VMK first, so
it's only performed when obtaining the volume key.

This allows us to detect corrupted/altered FVE metadata blocks and
pick the valid one (before this commit: the first FVE metadata block
is always selected).

Fixes: #953

tests: add BitLocker image with corrupted headers

The image contains 2 manually corrupted metadata blocks (out of 3),
the library should use the third one to correctly load the volume.

Signed-off-by: Maxim Suhanov <dfirblog@gmail.com>
2025-08-29 15:16:36 +02:00
Milan Broz
b0821b11a5 Add the same cipher_null restriction to LUKS2 keyslot as in LUKS1.
LUKS2 keyslot cannot be created with cipher_null using standard
tools, but activation of such a keyslot is allowed.

As this can be confusing and create a false sense of security,
let's apply the same restriction as in LUKS1 - such a keyslot
is used only with an empty passphrase.

This will reject activation with a real password, avoiding
possible activation of insecure LUKS containers.

Fixes: #954
2025-08-18 08:22:51 +02:00
Milan Broz
098d2122e5 Remove redundant test in LUKS2 keyslot cipher incompatible test.
The null_cipher is tested twice there.
2025-08-18 08:22:51 +02:00
Milan Broz
10e5ab1a87 tcrypt: Fix detecting status of chained modes
The function dm_uuid_cmp cannot be used for TCRYPT, it expects
LUKS UUID, not a device name.

Fixes: #952
2025-08-08 11:15:32 +02:00
Milan Broz
b0d38f932f Add (ugly) wrorkaround for musl broken macro
Nobody fixes this for years, there are multiple discussions.
Let's just ignore it.
2025-08-01 16:48:08 +02:00
Milan Broz
b7e3ea592b Avoid warning about unused parameter.
This fixes compilation warning:
   error: unused parameter 'version' [-Werror=unused-parameter]
2025-08-01 16:48:08 +02:00
Milan Broz
c618a50de8 Avoid truncatted NULL ternminator gcc warning
This prevents gcc warnings:
  warning: initializer-string for array of 'unsigned char' truncates
  NUL terminator but destination lacks 'nonstring' attribute

While there is "nonstring" attribute, clang does not support it,
so this is the simplest solution.
2025-08-01 16:48:08 +02:00
Milan Broz
4a67af439e Do not silently decrease PBKDF parallel cost (threads)
The maximum parallel cost is set since the introduction of Argon2 to 4.

Do not silently decrease the value (if explicitly set by the option)
but fail instead.
2025-08-01 12:31:02 +02:00
Vojtech Trefny
04d307d9c0 bitlk: Fix unlocking bitlocker with multibyte utf8 characters
Fixes: #950

Co-authored-by: Thomas Lidén
2025-07-30 13:43:14 +02:00
Ondrej Kozina
6c7c8d36bb Fix bug in parsing of tcrypt device in crypt_init_by_name.
When TCRYPT subdevices was moved to use SUBDEV dm uuid prefix
we did not correctly modified the TCRYPT_status_one routine
to correctly expect the SUBDEV uuid prefix.

Fixes: cf630f578d
Fixes: #952.
2025-07-29 13:49:37 +02:00
Ondrej Kozina
b6ddaa40bf Refactor tcrypt subdev check in a helper routine.
Add comments what parts will be removed later.
2025-07-29 13:49:37 +02:00
Vojtech Trefny
cdc451a61a Fix expected keyslot context for LUKS1 activate_by_keyring 2025-06-23 14:22:13 +02: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
Milan Broz
c7f3f32ec9 Avoid zero-length read in read_lseek_blockwise
Found by Valgrind. Similar fix already exists
for write_lseek_blockwise.
2025-06-04 14:07:24 +02:00
Ondrej Kozina
773ac1ce55 Support encryption with reduced device size and data shift.
The only mising bit in library is a check if reduced data
size is smaller than real device size minus data shift.
2025-06-02 17:08:43 +02:00
Ondrej Kozina
ed50d30e7e Decouple data device size from reencryption operation data size.
Encryption with data shift and moved segment used to change
data size attribute later than necessary. Make it obvious in
upper layers.
2025-06-02 17:05:38 +02:00
Ondrej Kozina
5973694311 Correctly suffix device related variables.
We introduced _bytes and _sectors variables some time ago.
2025-06-02 17:05:03 +02:00
Milan Broz
b81c84bd8f Do not allow null cipher for LUKS2 keyslot even in conversion. 2025-06-02 13:58:33 +02:00
Milan Broz
21e0680abf Disallow conversion to LUKS1 if capi string is specified.
While it works, it is a bug and we block it already in luksFormat.
2025-05-29 13:55:56 +02:00
Milan Broz
e136a0a40a Support capi format in crypt_storage wrapper.
Fixes: #944
2025-05-29 13:55:56 +02:00
Milan Broz
5b3ff3c0a7 Explicitly disallow capi format for LUKS2 keyslot encryption
NO functional change as it fails in IV check anyway, but the
code should not reach this funtion at all.
2025-05-29 13:55:56 +02:00
Milan Broz
55c44cd3fd Fix warning for hidden global variable
The requirements_flags is a global array, do not
name a local variable the same (CodeQL fix).
2025-05-28 14:05:30 +02:00
Ondrej Kozina
a6c9c28208 Return -EINVAL if keyslot context can not access keyring key. 2025-05-27 16:24:27 +02:00
Ondrej Kozina
b6f43890f2 Add better errno hint in debug message. 2025-05-27 14:27:14 +02:00