Commit Graph

76 Commits

Author SHA1 Message Date
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
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
Rafael Fontenelle
f35ec9771e Fix typos
A bunch of typos reported by codespell, most of them comments in the code
2018-07-21 07:24:25 -03:00
Ondrej Kozina
1bf5ff3e6e Open files in read-write mode for posix_fallocate.
Unfortunately there exists some weird NFS variations requiring read
permissions for fallocate.
2018-07-07 10:25:01 +02:00
Milan Broz
b00a87d8fa Remove trailing EOL for verbose and error messages. 2018-04-26 10:38:17 +02:00
Milan Broz
874c573bd4 Do not allow used block size larger than page size.
Some filesystems (NFS) returns bogus blocksize (1MB).
Page-size io should always work and avoids increasing IO beyond aligned LUKS header.
2018-04-24 16:36:11 +02:00
Milan Broz
23b01621ff Print better debug message for open with write mode. 2018-04-10 15:33:30 +02:00
Milan Broz
1fe014dbae Update copyright year. 2018-01-20 17:55:21 +01:00
Milan Broz
1ca439f4e0 Fix some warnings found during static analysis. 2018-01-20 14:42:05 +01:00
Milan Broz
b80278c04f Ignore device opt-io alignment if it is not multiple of minimal-io.
Some USB enclosures seems to report bogus topology info.
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1513820
2017-11-21 15:39:36 +01:00
Milan Broz
12908709bb Resize loop device after fallocate.
On old systems we have a loop mapped so the loop must be resized as well.
2017-10-10 19:48:29 +02:00
Milan Broz
b42d183b08 Create LUKS header file in luksFormat if it does not exist. 2017-10-10 13:52:50 +02:00
Milan Broz
de2f07b82f Do not try to load LUKS2 header if backup_file is LUKS1.
Also do not allow header restore if a different version is requested.
2017-10-06 12:28:59 +02:00
Milan Broz
3ccbb8fe84 Fix some problems found by Coverity analysis. 2017-09-27 10:18:38 +02:00
Milan Broz
5536b3a58d Add implementation of device/file locking for metadata.
To be used later.
2017-09-24 19:49:46 +02:00
Milan Broz
4bcba41d77 Fix crypt_init(cd, NULL) case in the previous commit. 2017-07-27 13:36:53 +02:00
Milan Broz
12040570ca Allow to open device without read check.
In some specific situation we do not want to read the devices
before initialization.

Here it is integrity checking that will produce warning, because
the device is not yet initialized.

Used only in wipe function (here we must use direct-io anyway)
and expect the device is capable of direct-io.
2017-07-27 12:56:07 +02:00
Milan Broz
5824e8d242 Simplify device block size check. 2017-07-26 14:53:37 +02:00