Commit Graph

650 Commits

Author SHA1 Message Date
Milan Broz
97a22c27dd Make crypt_load quiet if metadata is not detected.
Ths will allow automatic scan of known formats.

Errors are printed only if something is wrong with already detected metadata.

This change means that it is responsibility of the caller to print an error
message if needed.

Also fix some places without a message.

Fixes: #642
2022-05-26 10:17:32 +02:00
Vojtech Trefny
6c73057156 integrity: Fix integrity_key_size for algorithms without keys
INTEGRITY_key_size returns -EINVAL for algorithms without a key
and because crypt_params_integrity.integrity_key_size is an
unsigned integer we get key size 4294967274 instead of more
appropriate 0 for these algorithms.
2022-05-22 19:58:00 +02:00
Milan Broz
251eb37c4a Do not try to print NULL string in destructor. 2022-05-18 16:39:38 +02:00
Milan Broz
9e7894081f Verity: dump device sizes.
Calculating device sizes for verity devices is a little bit tricky,
Data, hash and FEC can share devices or it can be a separate devices.

This patch prints used device sizes in veritysetup dump command,
but it requires that user specifies all values that are not stored
in superblock (like a FEC device and FEC roots).
2022-05-09 22:48:59 +02:00
Milan Broz
0c80ee6c28 Move verity dump to per-format directory. 2022-05-09 13:47:16 +02:00
Milan Broz
853abf53f5 Fix debug message for crypt_activate_by_signed_key.
If name is not uses, there are two spaces.
Also it is more readable now.
2022-05-09 13:46:58 +02:00
Milan Broz
2bf0f537f6 Add constant time memcmp and use it for comparing keys.
There is perhaps no problem now, but it is a good practise to use
constant time for key comaprison to avoid possible side channel
issues.
2022-04-28 15:19:23 +00:00
Milan Broz
ceed3c0c3b Introduce crypt_log_hex helper and use it for log_std output. 2022-04-28 08:11:58 +00:00
Ondrej Kozina
cc107ee20e Silent crypt_volume_key_verify call.
And moves the error message in tools instead.
2022-04-25 19:47:09 +00:00
Milan Broz
f391f4baf1 Fix memory leaks in integrity resize with keyed parameters.
The whole game with reallocating keys is not needed.

(Perhaps not even for crypt type, but that is not part of this patch).
2022-04-22 11:34:13 +02:00
Milan Broz
ed13852899 Fix reload integrity device.
The offset cannot be referenced from the crypt union for integrity type.

Keyring setting key works only for crypt devices.

Also reformat long lines.
2022-04-21 08:21:01 +00:00
Milan Broz
efc1590405 Fix formatting warning for a 32bit arch. 2022-04-21 08:21:01 +00:00
Milan Broz
f1eea3a4b3 Clean reencrypt status struct for API call.
This function should not return unitialized struct as there
is no indication that it failed and caller can access it.

Also fixes a Coverity warning.
2022-04-19 08:53:44 +00:00
daniel.zatovic
d20d41c7a5 Add log messages, when kernel doesn't support resize. 2022-03-24 11:38:16 +01:00
daniel.zatovic
9b8a872006 Add support for resizing raw integrity devices. 2022-03-24 11:38:16 +01:00
daniel.zatovic
45b808c186 Move checking for detached integrity metadata device.
To allow resizing integrity devices with detached metadata device, the
check has to be moved from _compare_integrity_devices to
_reload_device_with_integrity.
2022-03-24 11:38:16 +01:00
daniel.zatovic
87afb9d783 Remove size parameter comparison for integrity devices.
To support device resize, we can not compare the device size (it is
already not compared for crypt devices).
2022-03-24 11:38:16 +01:00
daniel.zatovic
64e7c3d3b1 Add support for refreshing integrity devices.
If the provided key is NULL, we load it from the active device. This is
always available, since keyring keys are not supported in kernel for
integrity devices.
2022-03-24 11:38:16 +01:00
Ondrej Kozina
6b774e617b Remove unused funtion prototype and few useless comments. 2022-02-23 12:28:20 +01:00
Ondrej Kozina
bef46c950d Properly detect optimal encryption sector size.
Move code setting data device during format so that
we can properly detect optimal encryption sector size
for data device instead of metadata device (header).

Fixes: #708.
2022-02-09 15:43:25 +01:00
Ondrej Kozina
ce6f6a48e8 Add crypt_resume_by_token_pin API. 2022-02-04 13:40:20 +01:00
Luca Boccassi
2938c1f077 Add crypt_get_label/subsystem
There's an API to set the label and subsystem, and they are
dumped with luksDump, but there's no programmatic interface
to query them.
2022-02-03 10:23:57 +00:00
Milan Broz
ab975bc1c4 Update copyright year.
And unify format in several places.
2022-01-29 10:43:02 +01:00
Ondrej Kozina
230b80404d Remove parameters annotated by __attribute__((unused)).
Attribute unused is useless and makes code imcomprehensible
when decorates internal functions not exposed via API.

Let's cleanup internal funtion prototypes whenever possible.
2022-01-28 17:27:00 +00:00
Milan Broz
139d663541 Add disable-luks2 reencryption configure option.
The option --disable-luks2-reencryption completely disable
LUKS2 reencryption code.

When used, the libcryptsetup library can read metadata with
reencryption code, but all reencryption API calls and cryptsetup
reencrypt commands are disabled.

Devices with online reencryption in progress cannot be activated.

This option can cause some incompatibilities. Please use with care.
2022-01-12 13:58:35 +01:00
Ondrej Kozina
0113ac2d88 Fix CVE-2021-4122 - LUKS2 reencryption crash recovery attack
Fix possible attacks against data confidentiality through LUKS2 online
reencryption extension crash recovery.

An attacker can modify on-disk metadata to simulate decryption in
progress with crashed (unfinished) reencryption step and persistently
decrypt part of the LUKS device.

This attack requires repeated physical access to the LUKS device but
no knowledge of user passphrases.

The decryption step is performed after a valid user activates
the device with a correct passphrase and modified metadata.
There are no visible warnings for the user that such recovery happened
(except using the luksDump command). The attack can also be reversed
afterward (simulating crashed encryption from a plaintext) with
possible modification of revealed plaintext.

The problem was caused by reusing a mechanism designed for actual
reencryption operation without reassessing the security impact for new
encryption and decryption operations. While the reencryption requires
calculating and verifying both key digests, no digest was needed to
initiate decryption recovery if the destination is plaintext (no
encryption key). Also, some metadata (like encryption cipher) is not
protected, and an attacker could change it. Note that LUKS2 protects
visible metadata only when a random change occurs. It does not protect
against intentional modification but such modification must not cause
a violation of data confidentiality.

The fix introduces additional digest protection of reencryption
metadata. The digest is calculated from known keys and critical
reencryption metadata. Now an attacker cannot create correct metadata
digest without knowledge of a passphrase for used keyslots.
For more details, see LUKS2 On-Disk Format Specification version 1.1.0.
2022-01-12 13:50:37 +01:00
Milan Broz
f8eb7b225a Do not load own OpenSSL backend context in FIPS mode.
In the FIPS mode keep configuration up to the system wide config.
2021-09-13 21:56:59 +02:00
Guilhem Moulin
6a14f52e5d Fix minor spelling errors.
(Found by Lintian.)
2021-07-30 02:56:38 +02:00
Ondrej Kozina
f364990b9b Do not fallback to pasphrase based activation when device exists.
If token based device activation activation fails with -EEXIST
report proper error and do not fallback to passphrase based
activation in cli.
2021-07-29 14:47:16 +00:00
Vojtech Trefny
bfe0c7fc5f Fix error message for invalid key slot with LUKS2
Fixes: #651
2021-07-13 07:22:16 +02:00
Ondrej Kozina
df7a995fa2 Remove redundant (unreleased) API for token based activation.
Reverts commit 96d83455ca partially. It is not necessary to
have specific crypt_activate_by_token_type call. Users
may use crypt_activate_by_token_pin with pin argument set to NULL
and achieve same goal as with crypt_activate_by_token_type.
2021-06-29 14:13:37 +00:00
Milan Broz
4cdd826282 Check exit value for snprintf where it makes sense. 2021-05-18 22:07:47 +02:00
Milan Broz
413b484774 Add some fixes and workarounds for gcc-11 static analyzer.
Not everything is a real bug (false positive rate is very high here),
but the code is actually more readable.
2021-05-18 17:28:47 +02:00
Ondrej Kozina
8f2b23cd94 Refactor LUKS2 token activation.
Replace LUKS2_token_open_and_activate and
LUKS2_token_open_and_activavate_any with single function
instead.
2021-04-15 21:41:06 +02:00
Ondrej Kozina
e6089dd9c9 Reflect on some incompatible changes in GCC 10.
Starting with GCC10 and LTO enabled, current symbols
versioning hack does not work anymore. This patch
reflects on that and should be compatible with older
compilers that does not support __attribute__((symver))
yet.

Inspired by following code:
https://github.com/linux-rdma/rdma-core/blob/master/util/symver.h
2021-04-12 20:38:19 +02:00
Ondrej Kozina
bd4f374b47 Fix supposed debug message. 2021-03-25 08:44:42 +01:00
Ondrej Kozina
8d0e90b90a Autodetect optimal encryption sector size on LUKS2 format. 2021-03-24 16:14:35 +01:00
Ondrej Kozina
1aeb0a1f6e Set data device loop block size to encryption sector size. 2021-03-23 16:40:57 +01:00
Ondrej Kozina
78797ae078 Rename PIN enable token activation API function. 2021-03-19 15:26:36 +01:00
Ondrej Kozina
96d83455ca Add API for activating device by specific token type. 2021-03-19 15:26:35 +01:00
Ondrej Kozina
5d0a11a21b Add pin size parameter in crypt_active_by_pin_token.
Well, after all it really should have supported binary data
of arbitrary length.
2021-03-18 18:06:13 +01:00
Ondrej Kozina
8e8ecd50de Fix luksResume when called on non-LUKS device. 2021-02-24 16:06:19 +01:00
Ondrej Kozina
6a8bade7e6 Allow LUKS resume for device with cipher_null. 2021-02-24 15:57:11 +01:00
Ondrej Kozina
3367b78958 Unify crypt_resume_by internal code. 2021-02-24 15:57:11 +01:00
Ondrej Kozina
28603e4de7 Do not upload VK in keyring when data cipher is null. 2021-02-24 15:57:11 +01:00
Ondrej Kozina
d8cf203d46 Remove redundant check.
It can't be non-LUKS2 device at this branching.
2021-02-24 15:57:11 +01:00
Milan Broz
6dd347ddb4 Rewrite reload code to avoid two goto labels. 2021-02-17 10:03:18 +01:00
Milan Broz
639ffa36a5 Rename goto err to out, it is not error path only.
Also try to use the same "goto out" pattern everywhere.
2021-02-17 10:03:18 +01:00
Milan Broz
05f9297141 Avoid goto patern in crypt_init.
Also device_free is not needed, it never allocates anything in error path.
2021-02-17 10:03:18 +01:00
Ondrej Kozina
ed2117c724 Fix device comparison for dm-crypt with cipher_null.
Do not compare volume keys if segment uses cipher_null.
The key is ignored by lower layer (internal libdevmapper)
anyway.
2021-02-16 18:08:35 +01:00