Commit Graph

4298 Commits

Author SHA1 Message Date
Milan Broz
46289f92ff argon2: Avoid cppcheck integer oveflow warning
This patch avoid warning in constant-time base64 function:

Error: CPPCHECK_WARNING (CWE-190): [#def2]
cryptsetup-main/lib/crypto_backend/argon2/encoding.c:86: error[integerOverflow]: Signed integer overflow for expression ''0'-52'.

The (x + ('0' - 52)) can be rewritten to (x - (52 - '0')) with the same effect.
Similar solution used in https://github.com/pornin/CTTK/blob/master/src/base64.c
2024-11-08 19:51:14 +00: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
Milan Broz
c0449fc24e Revert "Do not call safe erase on benchmark data."
This reverts commit 17f0261024.

The password can be set by user through expeorted API, we should
not keep traces of derived key from a real password.
2024-11-01 12:59:25 +01:00
Ondrej Kozina
17f0261024 Do not call safe erase on benchmark data.
In both pbkdf2 and argon2* benchmark key variable
is pointer to benchmark data and does not need to be erased
safely as regular key data would need to.
2024-11-01 10:27:24 +01:00
Ondrej Kozina
6daefa8222 api-test: Use minimal key size 14 bytes (112 bits).
As per SP800-132 minimal key length is 112 bits. Use it
while testing unbound keys stored in LUKS2 keyslots.
Otherwise the test fails in FIPS mode.
2024-10-31 17:26:38 +00:00
Milan Broz
33ed0d587e Fix typos found by lintian. 2024-10-30 19:11:29 +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
7db83f8fb3 Simplify fvault activation by volume key. 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
00b89c4862 Export expected fvault2 volume key size. 2024-10-30 13:28:56 +00:00
Ondrej Kozina
305aa376b6 Add crypt_reencrypt_init_by_keyslot_context API test. 2024-10-30 13:25:57 +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
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
0eccd6e194 Check also CRYPT_ANY_SLOT in LUKS2_keyslot_for_segment.
The function did not work properly if keyslot parameter
was set to CRYPT_ANY_SLOT and returned always error.

But it will be used later when we need to find if there's
at least one keyslot asigned to a specific segment.
2024-10-30 13:25:55 +01:00
Ondrej Kozina
4de453d6a5 Retain original error code when reading data from keyring.
If key description is not available we expect -ENOENT.
-EINVAL usually aborts all following effort to unlock
device/keyslot.
2024-10-29 13:26:35 +01:00
Milan Broz
66c1523163 ci: Make unreleased RHEL distro build optional. 2024-10-26 10:51:43 +02:00
Milan Broz
5f066777a1 ci: Print output for RHEL packages install. 2024-10-26 10:38:34 +02:00
Michal Privoznik
fb04611ff7 crypto_backend.h: Wrap APIs in extern C
It's a good practice to mark public APIs as extern "C" so that
projects written in C++ can use our library.

[mbroz] It is not public API in cryptsetup, but we use this backend
in other projects, this aligns the code changes.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2024-10-18 20:40:50 +02:00
Ondrej Kozina
b7cf60f229 Add regression test for decryption with datashift.
Test if decryption works when default segment
is assigned to volume key with digest id set
to non zero value.
2024-10-11 15:06:48 +02: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
e19030915b Unify integer format parameter in prompt.
There was only single occurence of the prompt
message with %u. Let's use %d as anywhere else.
2024-10-09 11:15:56 +00: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
Yiyuan Zhong
939b7c0a9e Mbed-TLS: implement PBKDF2
PBKDF2 has been implemented since 2.0.0 and a new API was introduced in 3.3.0
deprecating the old one. This implementation will use the new API if detected.
2024-10-08 20:21:21 +00:00
Milan Broz
443a555559 integrity: print debug message if superblock metadata read fails. 2024-10-08 12:22:46 +00:00
Milan Broz
79ef5bee86 Do not run direct-io read check on block devices.
Block devices must support direct-io. This check causes more problems
than it solves - for Opal locked device it disables direct-io
and we can later possible read wrong data (if kernel does not flush
cache).
2024-10-08 12:22:46 +00:00
Milan Broz
cd818156f6 Do not print debug message if device read check fails.
It really should not print "direct-io works" when it just failed :)
2024-10-08 12:22:46 +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
Milan Broz
d35fb1e671 ci: run vectors test when compiling crypto backends.
This should cost only few seconds but will verify
basic crypto backend operations as we do not run full testsuite
with all backends.
2024-10-04 21:57:09 +02:00
Ondrej Kozina
8ad28547ee Simplify keyslot context initialization code. 2024-09-29 19:14:56 +00:00
Jan Zerebecki
3c00305156 add warning to order luksChangeKey and reencrypt 2024-09-29 19:13:02 +00:00
Ondrej Kozina
31bf986084 Adapt cryptsetup to self-contained keyslot contexts. 2024-09-29 16:10:44 +00:00
Ondrej Kozina
6ef0650332 Rename internal keyslot context functions. 2024-09-29 16:10:44 +00:00
Ondrej Kozina
9311c923ca Make all keyslot context types fully self-contained.
Duplicate all dynamically allocated memory passed
keyslot context during initialization and make it
self contained.

Before current patch all pointers passed in keyslot
context initialization routines have to remain valid
for the duration of the keyslot context. Otherwise
memory violation could occur.

This patch fixes the issue in backward compatible
way so that we do not have to change API for all
keyslot contexts. As of now all dynamically allocated
memory can be freed right after keyslot context
initialization.
2024-09-29 16:10:44 +00:00
Eric Biggers
209e6167b5 Exclude cipher allocation time from benchmark
For each 1 MiB of data en/decrypted, 'cryptsetup benchmark' is setting
up a new AF_ALG socket, which involves 4 system calls and is included in
the data en/decryption time.  With high-speed ciphers (e.g. VAES
optimized AES-XTS) this can measure well over 10000 AF_ALG socket setups
per second.  This is not representative of dm-crypt, which only
allocates a cipher when the dm-crypt device is created.

Therefore, allocate the AF_ALG socket once, before doing the benchmark.

On AMD Ryzen 9 9950X this increases the 'cryptsetup benchmark' result of
AES-256-XTS slightly, from 14000 MiB/s to 14600 MiB/s.

Note that an in-kernel benchmark of the crypto API with the same block
size (65536 bytes) gives 34100 MiB/s, so AF_ALG still takes more time
than the en/decryption itself -- this cannot easily be addressed though.

Signed-off-by: Eric Biggers <ebiggers@google.com>
2024-09-17 10:31:10 -07:00
Milan Broz
b5f7176af1 CI: Install scsi_debug and other kernel modules for Ubuntu CI. 2024-09-12 10:20:21 +00:00
Ondrej Kozina
c0bf271bef Add crypt_safe_memcpy in reencrypt digest routine.
We copy volume keys for purpose of calculating LUKS2
reencryption digest. Add crypt_safe_memcpy in serialization
function as well.
2024-09-12 11:08:16 +02:00
Ondrej Kozina
41c72eaa65 Fix a bug in keyring keyslot context.
It always returned zero upon successful keyslot unlock
instead expected unlocked keyslot id.
2024-09-12 08:07:23 +00:00
Milan Broz
e48c74b77f Update Readme.md. 2024-09-03 11:54:48 +02:00
Milan Broz
46b8275ad9 Add 2.7.5 release notes. 2024-09-02 15:38:59 +02:00