Commit Graph

132 Commits

Author SHA1 Message Date
Milan Broz
487e85fdec Wipe buffers to be sure padding is always empty.
Detected by valgrind as writing unitialized data.
2022-11-27 23:18:36 +01:00
Milan Broz
e96588b8b5 Check and allocate header early so wipe fails only for IO errors.
The device_check is done in header write functions,
but these are not recached in normal format path as wipe call
is called earlier.

Call the device check also from wipe function to get better error
description.

This situation happens for example when a block device is too small
(regular file can be enlarged by falloc(); block device cannot).
2022-11-18 13:03:52 +00:00
Ondrej Kozina
81c56a8395 Move assert include in internal header files. 2022-11-16 16:54:33 +01:00
Milan Broz
21d87a246e Do not use safe_malloc for LUKS header backup.
The content of LUKS header is not a key material, no need
to lock memory for possibly big header and big memory area locks.

Just ensure we wipe buffer before release of memory.
2022-08-16 19:56:20 +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
773fc0195f Fix typos found by codespell.
Thanks Dimitri Papadopoulos Orfanos for the patch.

Fixes: #734.
2022-04-20 14:37:13 +00:00
Milan Broz
08aa2ca242 Replace master on a few more places. 2022-03-29 19:06:38 +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
669ad1933a Fix possible use of unallocated parameter.
(Introduced in previous patches.)
2021-08-30 12:39:17 +02:00
Milan Broz
f6fb530121 Repair also lowercase hash in LUKS1 header.
This patch removes magic for backup load that quietly
run lowecase conversion and add this possibility to repair command.

Most of crypto backends allow uppercase though.
2021-08-25 16:45:00 +00:00
Milan Broz
0066f9dd83 Fix LUKS1 repair to repair wrong ECB mode.
1) Crypsetup repair should try to call crypt_repair() even
if crypt_load is ok - it has no validate system unlike LUKS2
and some errors cannot be hard load errors.

2) Move ECB fix to repair code, do not try magic on load that
no longer works.

And do not use ECB :)

Fixes: #664
2021-08-25 16:45:00 +00:00
Milan Broz
9209d7e3b5 Use internal bit operations instead of network byte order functions. 2021-03-01 18:26:06 +01:00
Milan Broz
1592f1e274 Fix allocation of volume key in LUKS1 open_key.
This function should not return allocated key on error path.

Recent patch (suspend/resume) introduced a memory leak because of this.
2021-02-24 22:54:55 +01:00
Ondrej Kozina
1fe2d3d92b Use crypt_is_cipher_null check where possible. 2021-02-18 14:19:09 +01:00
Milan Broz
76301cef4c Use one file for macros and basic constants for the whole project.
And avoid some dual definitions between tools and library.
2021-02-11 11:12:11 +00:00
Milan Broz
5a252c9166 Fix LUKS1 repair code.
We cannot trust possibly broken keyslots metadata here through LUKS_keyslots_offset().
Expect first keyslot is aligned, if not, then manual repair is neccessary.

(This situation happen if partition table signarture overwrites slot 4 area).

Also, if keyslot order is different, current repair code does not work properly
(this can happen only with downconverting LUKS2 device).
2021-02-01 10:50:08 +01:00
Milan Broz
d1d9dd8e20 Update Copyright year. 2021-01-25 22:00:25 +01:00
lixiaokeng
02d13d7257 lib: fix potential segfault in _keyslot_repair
The value of vk may be NULL in _keyslot_repair. It will
be dereferenced in LUKS_generate_phdr. Check it to avoid
segfault.

Signed-off-by: Lixiaokeng <lixiaokeng@huawei.com>
Signed-off-by: Linfeilong <linfeilong@huawei.com>
2020-11-09 09:57:13 +08:00
Milan Broz
b5fbd682f2 Move fcntl.h to internal defines and check for O_CLOEXEC. 2020-02-21 10:10:11 +01:00
Milan Broz
8f7e898341 Print error message if LUKS1 keyslot cannot be processed.
If crypto backend is missing support for hash algorithms used
in PBKDF2 during slot derivatiom the fail was not visible.

Print at least error message to user in this case.

Fixes: #536
2020-02-20 14:19:53 +01:00
Ondrej Kozina
47d0cf495d Fail crypt_keyslot_get_pbkdf for inactive LUKS1 keyslot.
With LUKS1 we returned pbkdf values even for inactive keyslot.
Only iterations count was wrong. Remaining values are not
specific keyslot bound with LUKS1.

Fixes: #528.
2020-01-31 13:52:38 +01:00
Milan Broz
165e6c234c Fix some error and debug messages.
Use BITLK as format name.

Avoid using doesn't -> does not.
2020-01-11 22:10:59 +01:00
Milan Broz
080566a1fd Update copyright year. 2020-01-03 13:04:55 +01:00
Milan Broz
6b1be52e6b Fix LUKS1 format if pkbdf benchamr is disabled.
We use minimum iteration for key digest in this case
(the same already used in LUKS2).

Fixes: #478.
2019-11-22 13:02:41 +01:00
Milan Broz
b03cb3f3d8 Export memory safe functions.
Make crypt_safe_alloc/realloc/free and memzero part of API.
2019-11-16 21:28:54 +01:00
Ondrej Kozina
83c227d53c Sync device using internal write enabled descriptor. 2019-05-10 21:05:31 +02:00
Ondrej Kozina
ee57b865b0 Reuse device file desriptors. 2019-05-10 21:05:31 +02:00
Milan Broz
787066c292 Report error if no LUKS keyslots are available.
Also fix LUKS1 keyslot function to proper return -ENOENT errno in this case.

This change means, that user can distinguish between bad passphrase and
no keyslot available. (But this information was avalilable with luksDump
even before the change.)
2019-02-13 13:19:48 +01:00
Milan Broz
319fd19b5e Add implementation of crypt_keyslot_pbkdf().
This function allows to get PBKDF parameters per-keyslot.
2019-02-07 12:55:12 +01:00
Milan Broz
a6f5ce8c7b Update copyright year.
And unify name copyright format.
2019-01-25 09:45:57 +01:00
Ondrej Kozina
39a014f601 dm backend with support for multi-segment devices.
Support for multi-segment devices is requirement for online
reencryption to work. Introducing modififed dm backend that
splits data structures describing active device and individual
dm target (or segment).
2019-01-07 13:07:45 +01:00
Ondrej Kozina
5c0ad86f19 Move device_block_adjust() check lower in code. 2019-01-01 21:42:46 +01:00
Ondrej Kozina
bdce4b84d8 Add new internal crypt_get_cipher_spec.
Add function for getting cipher spec (cipher
and mode) in convenient single string format.
2019-01-01 21:42:46 +01:00
Ondrej Kozina
5c67ca015b Add CRYPT_ACTIVATE_REFRESH flag to activation calls.
The new flag is supposed to refresh (reload) active dm-crypt
mapping with new set of activation flags. CRYPT_ACTIVATE_READONLY
can not be switched for already active device.

The flag is silently ignored for tcrypt, verity and integrity
devices. LUKS2 with authenticated encryption support is added in
later commit.
2019-01-01 21:42:46 +01:00
Ondrej Kozina
120ebea917 Split low level code for creating dm devices.
The separate code for reloading device tables
will be used in later features.
2019-01-01 21:42:46 +01:00
Milan Broz
fd02dca60e Add crypt_set_metadata_size / crypt_get_metadata_size API. 2018-12-11 21:59:59 +01:00
Milan Broz
03edcd2bfd Add crypt_set_data_offset API function.
The crypt_set_data_offset sets the data offset for LUKS and LUKS2 devices
to specified value in 512-byte sectors.

This value should replace alignment calculation in LUKS param structures.
2018-12-06 11:10:21 +01:00
Milan Broz
991ab5de64 Fixe more context propagation paths. 2018-11-27 16:09:45 +01:00
Milan Broz
7812214db6 Add context to device handling functions. 2018-11-27 14:19:57 +01:00
Milan Broz
a5a8467993 Use context in debug log messages.
To use per-context logging even for debug messages
we need to use the same macro as for error logging.
2018-11-27 13:37:20 +01:00
Ondrej Kozina
c00811a846 Run LUKS2 validation code before header areas wiping.
Also drops redundant checks peformed in general validation code.
2018-10-18 08:48:48 +02:00
Milan Broz
27eaf46c8a Fix issues found by Coverity scan.
- possible overflow of data offset calculation in wipe and
- dereferencing of pointer in a keyring error path.
2018-10-14 21:50:06 +02:00
Milan Broz
c2bce3e93e Wipe full header areas (including unused) during LUKS format.
All previous version of cryptsetup wiped only first 4k for LUKS1
and both JSON areas for LUKS2 (first 32k) and the allocated
keyslot area (as it contained the generated key).

Remaining areas (unused keyslots, padding, and alignment) were
not wiped and could contain some previous data.

Since this commit, the whole area up to the data offset is zeroed,
and subsequently, all keyslots areas are wiped with random data.

Only exceptions are
 - padding/alignment areas for detached header
   if the data offset is set to 0
 - bogus LUKS1 keyslot areas (upstream code never
   created such keyslots but someone could use that).

This operation could slow down luksFormat on some devices, but
it guarantees that after this operation LUKS header does not
contain any foreign data.
2018-10-14 13:11:50 +02:00
Milan Broz
69a844c654 Remove O_SYNC from device open and use fsync().
This speed up wipe operation considerably.
2018-08-09 12:01:20 +02:00
Milan Broz
eabd23f31e Print verbose message about keyslot and token numbers.
Move all messages to cryptsetup tools and print these
verbose messages:

  - Key slot X unlocked.
  - Key slot X created.
  - Key slot X removed.
and
  - Token X created.
  - Token X removed.

Also print error, if unknown token is tried to be removed.
2018-07-19 14:45:16 +02:00
Milan Broz
b00a87d8fa Remove trailing EOL for verbose and error messages. 2018-04-26 10:38:17 +02:00
Milan Broz
187170ec51 Check cipher before writing metadata (LUKS2).
Some ciphers and key sizes created on-disk metadata that cannot be used.
Use the same test for length-preserving cipher as LUKS1.

Also check if key for integrity algorithm is not too small.

Fixes #373.
2018-04-06 12:57:58 +02:00
Milan Broz
af0887fb48 Remove no passphrase error message from library.
And move it to tools.

This will unify LUKS1/2 error messages.
2018-03-25 14:14:37 +02:00
Milan Broz
1fe014dbae Update copyright year. 2018-01-20 17:55:21 +01:00