Commit Graph

93 Commits

Author SHA1 Message Date
Milan Broz
4cdd022ba4 Fix detection of direct-io with suspended devices.
Currently, direct-io is disabled if underlying device is suspended.

This was an unfortunate change, as it is part of data corruption
problem in online reenryption.

Let's relax the test to assume that suspended device
(suspended =>  must be a device-mapper device) supports direct-io.

The read test is still needed as some network based devices
misbehaves if opened with direct-io flag.
2024-08-27 12:13:54 +02:00
Ondrej Kozina
53198bdea9 Do not handle device as suspended on error.
Consider device is suspended only if dm_status_suspended return code
is true.

This function returned -EEXIST for dm devices with target types unknown
to libcryptsetup (for example dm-cache) and turned off O_DIRECT flag
for devices unexpectedly.

Turned out ignoring direct-io was a problem after all :).

Fixes: 0f51b5bacb (Do not run sector read check on suspended device.)
2024-08-22 13:42:13 +02:00
Milan Broz
661f57def4 Use SPDX license identifiers.
This patch switches code to SPDX one-line license identifiers according to
https://spdx.dev/learn/handling-license-info/
and replacing long license text headers.

I used C++ format on the first line in style
// SPDX-License-Identifier: <id>
except exported libcryptsetup.h, when only C comments are used.

The only additional changes are:
- switch backend utf8.c from LGPL2+ to LGPL2.1+ (as in systemd)
- add some additional formatting lines.
2024-06-03 16:38:15 +00:00
Milan Broz
410a586284 Detect unsupported zoned devices for LUKS header device.
Zoned device cannot be written with direct-io
and cannot be used for LUKS header logic without
significant changes. Do not allow to use them for LUKS header
but allow it for data device, as dm-crypt supports it.

Fixes: #877
2024-05-03 14:03:47 +00:00
Milan Broz
bd0ef58b3a Update copyright notice to include 2024 year. 2024-01-23 16:10:44 +01:00
Milan Broz
0f51b5bacb Do not run sector read check on suspended device.
This can affect status command, but later also device
stack with authenticated encryption (*_dif device).

Ignoring direct-io should not be problem here.
The logic shoudl be simplified in future anyway...
2023-11-21 22:44:16 +01:00
Milan Broz
d3cc5e846a Do not require init_done for some deive helpers.
It processes only name, no need to depend on real device
checks (for direct-io) etc.
2023-11-21 22:44:16 +01:00
Milan Broz
e4c2aa64b5 Detect DAX devices and and warn in LUKS format.
DAX / persistent memory devices do not provide atomic sector updates,
any single modification can corrupt the whole encryption block.
2023-03-31 10:51:34 +00:00
Milan Broz
72f799b393 Update Copyright year. 2023-02-09 17:11:18 +01:00
Ondrej Kozina
81c56a8395 Move assert include in internal header files. 2022-11-16 16:54:33 +01:00
Milan Broz
82b56300cd Wrap some very long lines. 2022-10-01 22:35:57 +02:00
Milan Broz
e921991ba5 Annotate LGTM TOCTOU condition.
The race here is not avoidable.
2022-06-05 20:38:22 +02:00
Milan Broz
ab975bc1c4 Update copyright year.
And unify format in several places.
2022-01-29 10:43:02 +01: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
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
ce80f7c5b1 Add support for larger block size in loop. 2021-03-23 16:40:57 +01:00
Milan Broz
fea4074e8f Check internal device functions for NULL device.
Most of these functions already works even with device=NULL.

There can be some rare situations when this call could happen,
so be safe always.
(Like initialization for a device that disappears during init.)

Also see
https://bugzilla.redhat.com/show_bug.cgi?id=1932946
2021-03-01 20:38:52 +01:00
Milan Broz
d1d9dd8e20 Update Copyright year. 2021-01-25 22:00:25 +01:00
Milan Broz
0c29321407 Introduce crypt_header_is_detached API call.
crypt_header_is_detached checks if initialized LUKS context uses detached header
(LUKS header located on a different device than data.)

This is a runtime attribute, it does not say if a LUKS device requires detached header.
2020-12-29 23:23:32 +01:00
Ondrej Kozina
a730d56e66 Do not print opt_io_size warning needlessly.
In fallback path min_io_size and opt_io_size could be
same and the warning was confusing.
2020-09-19 17:20:46 +02:00
Milan Broz
57d0f19bda Fix error message in previous commit. 2020-08-26 13:27:00 +02:00
Milan Broz
4cf663a661 Ignore optimal-io if not aligned to minimal page size
This values is bogus on some systems and causes wrong alignment
for data area. Just ignore it there.

Fixes: #585.
2020-08-26 13:17:26 +02: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
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
b03cb3f3d8 Export memory safe functions.
Make crypt_safe_alloc/realloc/free and memzero part of API.
2019-11-16 21:28:54 +01:00
Yuri Chornoivan
4143d9871e Fix minor typos 2019-06-28 12:02:39 +00:00
Ondrej Kozina
d4682b3b38 Cleanup translated messages id.
- minimize count of almost identical message ids
- unify style for some messages
- remove some useless messages
2019-06-27 10:23:42 +02:00
Seong-Joong Kim
07df177332 Fix a typo of comment 2019-06-24 22:31:52 -07:00
Ondrej Kozina
96a87170f7 Return usage count from device locking functions. 2019-06-12 11:51:08 +02:00
Ondrej Kozina
e92e320956 Add explicit device_close routine. 2019-05-24 17:29:56 +02:00
Ondrej Kozina
9159b5b120 Add coverity toctou annotation in device_open_excl.
We can't avoid this race due to undefined behaviour if called with
O_EXCL flag on regular file.

Let's double-check fd with O_EXCL flag is actually open block device.
2019-05-13 18:23:20 +02:00
Ondrej Kozina
2d0079905e Adapt device_open_excl to reusing of fds. 2019-05-10 21:05:31 +02: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
Ondrej Kozina
a7f80a2770 Add resilient LUKS2 reencryption library code. 2019-05-02 16:44:23 +02:00
Ondrej Kozina
88b3924132 Update LUKS2 locks for atomic operations.
Atomic operation requires to hold a lock for longer period than
single metadata I/O. Update locks so that we can:

- lock a device more than once (lock ref counting)
- reaquire read lock on already held write lock (write lock
  is stronger than read lock)
2019-03-05 17:07:31 +01:00
Ondrej Kozina
a4d236eebe Add device_is_locked function. 2019-03-01 21:43:25 +01:00
Ondrej Kozina
b9c6a62437 Do not call fallocate on image file that is already large enough. 2019-02-07 18:41:06 +01:00
Milan Broz
a6f5ce8c7b Update copyright year.
And unify name copyright format.
2019-01-25 09:45:57 +01:00
Ondrej Kozina
1894d6e6ff Add devno comparison for bdevs in device_is_identical(). 2018-12-12 15:07:33 +01:00
Ondrej Kozina
1cc722d0cc Simplify device_is_identical.
If any argument is null return false (with higher
priority than trivial identity check).

Also device_path can't return null if device struct gets
allocated succesfully.
2018-12-12 15:06:59 +01:00
Milan Broz
2a1d58ed22 Check data device offset if it fits data device size in luksFormat. 2018-12-11 21:59:49 +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
Milan Broz
7f0df99511 Properly parse errno to error message for devices. 2018-10-12 12:03:56 +02:00
Milan Broz
f01d044618 Print file name size instead of a loop device in error messages. 2018-10-11 15:40:22 +02:00
Milan Broz
7514786b20 Add an error message if device is unusable. 2018-10-04 20:00:12 +02:00