643 Commits

Author SHA1 Message Date
Ondrej Kozina
07f8dfc46d Write updated LUKS2 reencrypt keyslot immediately. 2022-06-09 12:03:14 +02:00
Ondrej Kozina
99a3d328f0 Harden checksum resilience parameters verification. 2022-06-09 12:03:14 +02:00
Ondrej Kozina
e8ec3e1005 Allocate buffer for checksum resilience on-demand. 2022-06-09 12:03:14 +02:00
Ondrej Kozina
007e56727c Refactor reencrypt_recover_segment. 2022-06-09 12:03:14 +02:00
Ondrej Kozina
4de09ace8f Minor code refactoring in reencryption loop. 2022-06-09 12:03:14 +02:00
Ondrej Kozina
97b88d878e Refactor internal reencrypt_hotzone_protect_final.
Avoid passing whole reencryption context when not
needed.
2022-06-09 12:03:14 +02:00
Ondrej Kozina
b43ca18c64 Postpone reencryption dm segments refresh.
Refresh (and therefore suspend hotzone) reencryption dm
segments in-before actual hotzone reencryption takes place.

This commit shortens time window during which hotzone is
suspended. Also it avoids eventual deadlock if reencryption process
triggers page miss during storage wrapper reinitialization and required
data is stored in (previously) suspended hotzone (corner case).
2022-06-09 12:03:14 +02:00
Ondrej Kozina
0768d3be84 Cleanup existing assert usage in LUKS2 json code. 2022-06-09 12:03:14 +02:00
Ondrej Kozina
828cfdb6a2 Reduce code duplication in LUKS2 requirements handling. 2022-06-09 12:03:14 +02:00
Ondrej Kozina
582f2c3449 Replace memset with crypt_safe_memzero where reasonable.
Better safe than sorry.
2022-06-09 12:03:14 +02:00
Ondrej Kozina
bf0d0203e8 Add routine for erasing resilience structure. 2022-06-09 12:03:14 +02:00
Ondrej Kozina
cfb54be9a3 Refactor reencrypt_length() function. 2022-06-09 12:03:14 +02:00
Milan Broz
dd3fe9f5fd Check cipher before LUKS conversion to LUKS2.
There are some historic incompatibilities that are ignored
for LUKS1 but do not work for LUKS2.

Check the cipher before conversion through crypto backend.

Also it switches LUKS2_check_cipher to use userspace backend only
(this should be ok for the reencryption code that uses it too).

Fixes: #641
2022-06-09 08:50:15 +00:00
Ondrej Kozina
692bb8a455 Properly define uint32_t constants in API.
We do not change any value but it was not declared properly
and limit values had to be type cast to avoid compiler warnings
with strict options.
2022-06-07 11:30:34 +02:00
Ondrej Kozina
a1734e2d52 Revalidate LUKS2 reencrypt keyslot after update. 2022-05-26 12:13:06 +00:00
Ondrej Kozina
8f97d9b6e6 Do not refresh reencryption digest when not needed.
Due to commit 0113ac2d88
we recalculate reencryption digest whenever LUKS2 reencryption
keyslot gets updated. Until now we perform reencryption digest
refresh every time we call LUKS2_keyslot_reencrypt_update even
when no metadata was updated.

This improves on it and should speed up reencryption resume
process.
2022-05-26 12:13:06 +00:00
Ondrej Kozina
fa12a0a490 Add missing translation tag. 2022-05-26 12:13:06 +00:00
Ondrej Kozina
d9dad29149 Move LUKS2 reencrypt keyslot update procedure.
The LUKS2 reencrypt keyslot update process should
not be performed in crypt_reencrypt_run() loop where
data reencryption takes place.

The proper location is reencryption process initialization
when we validate reencryption metadata and decide if
new user provided resilience metadata are valid.
2022-05-26 12:13:06 +00:00
Ondrej Kozina
fc4b2cab25 Store proper resilience data in LUKS2 reencrypt initialization.
Prior to commit 0113ac2d88 it did
not matter what resilince metadata we stored during initialization.
So we stored 'none' type unless 'datashift' operation was initialized.

After the commit, it triggered reencryption metadata digest refresh
almost each time (except 'datashift') which was suboptimal.

By storing proper resilience type during reencryption initialization
we will avoid the needless reencryption digest refresh later (after
update optimization).
2022-05-26 12:13:06 +00:00
Ondrej Kozina
d9eff7ffd7 Test passed resilience parameter is not NULL. 2022-05-26 12:13:06 +00:00
Ondrej Kozina
2820626f5e Move LUKS2_keyslot_reencrypt_allocate function.
It does not fit internal LUKS2 keyslot API so
there's no need to hook it in it.
2022-05-26 12:13:06 +00:00
Ondrej Kozina
1cdb7da2ad Fix mem leaks on error path in reenc_keyslot_alloc. 2022-05-26 12:13:06 +00:00
Ondrej Kozina
e00eecf9ca Remove unused union member. 2022-05-26 12:13:06 +00:00
Ondrej Kozina
346f104f26 Move internal structure definition to internal header file. 2022-05-26 12:13:06 +00:00
Ondrej Kozina
082d23af92 Store data_shift value in rp structure.
data_shift value is part of recovery data
and should be stored in rp structure instead.
2022-05-26 12:13:06 +00:00
Ondrej Kozina
392b0136dc Store checksum protection data block size in rp structure.
The structure is supposed to store all data necessary to perform
reencryption crash recovery. The data block size stored
in LUKS2 metadata was missing and stored in reencryption top level handle
instead.
2022-05-26 12:13:06 +00:00
Ondrej Kozina
3a4ced84a6 Release lock on reencryption initialization error path. 2022-05-26 12:13:06 +00:00
Milan Broz
39fda3bed1 Properly deactivate integrity device even if LUKS2 header is not available.
If LUKS2 is used with integrity protection, there is always a dm-integrity
device underneath.

We should deactivate the device if DM status return tag size (it means,
that dm-crypt uses dm-integrity DIF).

This allows "cryptsetup close <name>" peroperly remove both stacked devices
even if LUKS2 header is no longer available (like in detached header activation).
2022-05-26 06:44:53 +00: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
Ondrej Kozina
1ac6a58475 Simplify LUKS2_segment_first_unused_id(). 2022-04-27 11:50:48 +02:00
Ondrej Kozina
2dbd96ebbf Fix LUKS2_get_data_size function.
The function wrongly expected segment objects being
ordered (ascending order) in segments container.

The LUKS2 format never guaranteed that and it could
lead to wrong LUKS2 device size calculation in case
last segment (by key) was stored before any other segment
with fixed size.
2022-04-27 11:44:51 +02: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
Milan Broz
e89071e73f Fix keyslot JSON validation.
If keyslot JSON is corrupted (kdf,af,area objects),
validate function can crash.

Fix it by always using JSON type check.

Fixes: #731
2022-04-14 10:28:20 +00:00
daniel.zatovic
9c26a73d96 Validate JSON area root objects' types. 2022-04-07 15:29:05 +00:00
Milan Broz
08aa2ca242 Replace master on a few more places. 2022-03-29 19:06:38 +00:00
Ondrej Kozina
2a5483d8c3 Add progress function init before reencryption loop.
Otherwise elapsed time tracking is off and also breaks
speed estimation.
2022-03-07 12:35:38 +01:00
Ondrej Kozina
8340d0cb1a Remove useless condition in reencryption loop.
(always true)
2022-03-07 12:35:38 +01:00
Milan Broz
677e06c48a Check all snprintf calls for returning values. 2022-02-24 20:28:18 +01:00
Ondrej Kozina
8ab41e0776 Improve debug messages while verifying reencryption metadata. 2022-02-23 15:00:11 +01:00
Milan Broz
e4091fe8a5 Fix some benign warnings with gcc-12.
The string buffer is large enough, but gcc do not understant it.
Easy to avoid these warnings with a larger buffer here.
2022-02-06 18:03:49 +01:00
Ondrej Kozina
8798aa0a75 Do not upload keys in keyring during offline reencryption.
Fixes: #696.
2022-02-05 10:29:55 +00:00
Ondrej Kozina
7ca1a233f1 Split reencrypt_verify_and_upload_keys function. 2022-02-05 10:29:55 +00:00
Ondrej Kozina
416f1343fe Split LUKS2_activate_by_token. 2022-02-04 13:32:45 +01: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
9a1b3a8aff Remove old base64 implementation and switch to crypto_backend.
This completely removes old base64 implementation.
Code was originally taken from coreutils but recent changes
added many new funtions we do not need.
2022-01-18 12:15:20 +01:00
Ondrej Kozina
ea47937187 Add CRYPT_REENCRYPT_REPAIR_NEEDED flag.
crypt_reencrypt_status() returns this flag if old
online-reencrypt requirement is detected and reencryption
keyslot digest is missing.

crypt_reencrypt_init_by_passphrase() with same flag applied
repairs (upgrade) reencryption metadata so that
automatic reencryption recovery during activation
is again possible and reencryption operation can be resumed
post CVE-2021-4122 fix.
2022-01-12 18:38:17 +01:00
Ondrej Kozina
6c8314b297 Make reencryption flag and keyslot inseparable.
LUKS2 validation code now requires reencrypt keyslot together with
online-reencryption flag or none of those.
2022-01-12 18:38:10 +01:00
Ondrej Kozina
59e39e484a Rename LUKS2_keyslot_reencrypt_create function.
The function never writes on-disk. Also removed validation
function call-in since it will be called later before
writing on-disk and metadata does not have to be complete
at the moment of LUKS2_keyslot_reencrypt_allocate call.
2022-01-12 18:38:06 +01:00
Ondrej Kozina
b61ec23e48 Add segments validation for reencryption.
Effective segments during LUKS2 reencryption must
match key characteristics of backup segment
(cipher, sector_size, segment type).
2022-01-12 18:37:52 +01:00