110 Commits

Author SHA1 Message Date
Milan Broz
8364178b38 Update copyright year. 2025-01-15 23:09:36 +01:00
Milan Broz
b0be186f9e Fix leaked fd gcc analyzer warning.
These are actually false positives (fd 0 is always open as stdin),
but code is even more readable with this fix.
2024-07-10 09:48:08 +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
bd0ef58b3a Update copyright notice to include 2024 year. 2024-01-23 16:10:44 +01:00
Milan Broz
cac3184da3 Add a few tainted data info for coverity to avoid warnings.
If sysconf is lying, then anything can happen.
But check for overflow anyway.

Device/partition offset overflow for IV can only cause
bad decryption (expected).
2024-01-17 21:25:00 +01:00
Milan Broz
899bad8c06 Try to avoid OOM killer on low-memory systems without swap.
Benchmark for memory-hard KDF is tricky, seems that relying
on maximum half of physical memory is not enough.

Let's allow only free physical available space if there is no swap.
This should not cause changes on normal systems, at least.
2023-03-04 20:06:11 +01:00
Milan Broz
72f799b393 Update Copyright year. 2023-02-09 17:11:18 +01:00
Khem Raj
8e7f07841e Replace off64_t with off_t
AC_SYS_LARGEFILE autoconf macro is in use in configure script which will
add needed feature macros on commandline to enable 64bit off_t.

Also replace lseek64 with lseek, since it will be same when
_FILE_OFFSET_BITS=64 is defined on relevant platforms via AC_SYS_LARGEFILE

This fixes build with latest musl, where LFS64 interfaces are moved out
of _GNU_SOURCE feature test macros namespace [1]

[1] https://git.musl-libc.org/cgit/musl/commit/?id=25e6fee27f4a293728dd15b659170e7b9c7db9bc

Signed-off-by: Khem Raj <raj.khem@gmail.com>
2022-12-23 15:49:00 +01:00
Milan Broz
88d9524e6c Mark crypt_memory_lock() API call deprecated.
And remove its implementation.
2022-08-16 19:56:32 +02:00
Milan Broz
b9bf657449 Set process priority only for PBKDF benchmark.
Do not increase priority for the whole run, only
increase it when we calculate PBKDF paramaters.
2022-08-16 19:56:24 +02:00
Milan Broz
db65a5ceac Lock memory in crypt_safe alloc functions.
This patch locks all memory ranges in safe allocations.

While crypto backend can have some secure memory calls,
it is usually limited by intitial config.

For our use is enough to keep keys in memory and prevent
swapping it out.

If the lock fails (because of limits) we quietly
stay with plain malloc.
2022-08-16 19:56:00 +02:00
Milan Broz
ab975bc1c4 Update copyright year.
And unify format in several places.
2022-01-29 10:43:02 +01:00
Milan Broz
f5dd3c8e32 Rename label in utils for consistency. 2021-02-17 10:03:18 +01:00
Milan Broz
12ff94c02f Rename verion function to avoid conflict with crypto backend. 2021-02-11 11:12:11 +00:00
Milan Broz
d1d9dd8e20 Update Copyright year. 2021-01-25 22:00:25 +01: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
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
Ondrej Kozina
b216a6a30e Introduce crypt_strcmp function (allows NULL). 2019-07-31 14:58:55 +02:00
Ondrej Kozina
011ee5b180 Introduce crypt_string_in internal helper.
And replace custom name_in_list function with new helper.
2019-06-27 10:18:47 +02:00
Milan Broz
a6f5ce8c7b Update copyright year.
And unify name copyright format.
2019-01-25 09:45: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
268dc97857 Emit error when there's nothing to read from key file. 2018-07-20 15:24:16 +02:00
Ondrej Kozina
9895edefff Fix misleading parameter name in crypt_keyfile_device_read.
This patch has no functional impact. It only renames misleading
parameter 'keyfile_size_max' to 'key_size' because that's
how it's actually interpreted since beginning. Also updated
API documentation accordingly.
2018-07-18 11:55:20 +02:00
Milan Broz
b00a87d8fa Remove trailing EOL for verbose and error messages. 2018-04-26 10:38:17 +02:00
Ondrej Kozina
869767a5cf Move general i/o code to stand-alone utility file.
Get rid of internal library stuff linked to the utilities.
Also rename 'count' param to 'length' clarifying handling
of the parameter internally.
2018-04-11 15:33:43 +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
Ondrej Kozina
598dd672bc Detect kernel version for dm-crypt kernel key bugfix.
When loading first dm-crypt table (or action that triggers dm-crypt
module load) we do not know dm-crypt version yet. Let's assume all
kernels before 4.15.0 are flawed and reject VK load via kernel keyring
service.

When dm-crypt is already in kernel, check for correct target version
instead (v1.18.1 or later).
2018-01-18 14:17:00 +01:00
Milan Broz
f34ce81f25 Introduce new 64bit *keyfile_device_offset functions.
The keyfile interface was designed, well, for keyfiles.

Unfortunately, a keyfile can be placed on a device and the size_t offset
can overflow.

We have to introduce new set of fucntions that allows 64bit offsets even on 32bit systems:
 - crypt_resume_by_keyfile_device_offset
 - crypt_keyslot_add_by_keyfile_device_offset
 - crypt_activate_by_keyfile_device_offset
 - crypt_keyfile_device_read

The new functions have added _device_ in name.

Old functions are just internall wrappers around these.

Also cryptsetup --keyfile-offset and --new-keyfile-offset must now
process 64bit offsets.

For more info see issue 359.
2018-01-17 22:07:23 +01:00
Milan Broz
fa1f8c0d87 Limit KDF memory by available physical memory.
On some systems the requested amount of memory causes OOM killer
to kill the process (instead of returning ENOMEM).

For now, we never try to use more than half of available
physical memory.
2017-12-07 10:43:52 +01:00
Ondrej Kozina
304bdd7d0d luks2: add json_object_new_uint64 wrapper
json doesn't support 64 bits integers. We workaround it by storing
large numbers as string and validate the value internally.
2017-11-23 16:18:14 +01:00
Andrea Gelmini
a97de38b6b Fix typos. 2017-11-08 10:22:49 +01:00
Milan Broz
9f2727bb77 Add libLUKS2. 2017-09-24 19:50:12 +02:00
Milan Broz
a0d2d4c0b1 Add uint64_to_str helper. 2017-09-24 19:50:01 +02:00
Milan Broz
57825365fe Fix another signed/unsigned compilation warnings. 2017-09-23 23:30:28 +02:00
angelomariafederichini191269@protonmail.com
e2fee206c2 Allocate suitable sized buffer when reading a keyfile
If the keyfile size is explicitly given, then allocate a suitable sized
buffer right from the start instead of increasing it in 4k steps. This
speeds up reading larger keyfiles.
2017-08-15 08:49:44 +02:00
angelomariafederichini191269@protonmail.com
596e374313 Use bulk read when reading keyfile
If reading a keyfile use bulk read operations instead of reading one
character at the time. This speeds up reading larger keyfiles.

If read should stop at a EOL, then fallback to reading one character at
the time to not read anything beyond the EOL character.
2017-08-15 08:39:53 +02:00
Milan Broz
503956707c Move crypt_keyfile_read() to libcryptsetup internal file.
The utils_crypt.c file is directly linked to userpsace tools,
we should use library call and not local implementation.
2017-08-15 08:35:10 +02:00
Milan Broz
0abf57be5d Change PBKDF interface API.
Prepare API for PBKDF that can set three costs
  - time (similar to iterations in PBKDF2)
  - memory (required memory for memory-hard function)
  - threads (required number of threads/CPUs).

This patch also removes wrongly designed API call
crypt_benchmark_kdf and replaces it with the new call
crypt_benchmark_pbkdf.

Two functions for PBKDF per context setting
are introduced: crypt_set_pbkdf_type and crypt_get_pbkdf_type.

The patch should be backward compatible when using
crypt_set_iteration_time function (works only for PBKDF2).

Signed-off-by: Milan Broz <gmazyland@gmail.com>
2017-08-06 21:24:05 +02:00
Milan Broz
e853aa2e7c Fix blockwise access functions for systems with big page size.
Initially cryptsetup expected underlying device that was, by definition,
always aligned to a sector size (and length was always multiple of sectors).

For the images in file, we can now access the image directly.
Expecting that the image is always aligned to the whole block is now false
(the last block in file image can be incomplete).

Moreover, we cannot easily detect underlying block device sector (block) size
(the storage stack can be complex with various RAID and loop block sizes),
so code uses systyem PAGE_SIZE in this situation (should be the safest way).

Unfortunately, PAGE_SIZE can be bigger (1MB) than device sector (4k) and
the blockwise functions then fails because the image in file is not
aligned to PAGE_SIZE multiple..

Fix it by checking that read/write for the last part of an image is
the exact requested size and not a full block.

(The problem is for example for an unaligned hidden Truecrypt header
on PPC64LE systems, where page size is 64k.)
2017-07-24 14:17:21 +02:00
Milan Broz
73030aa5fb Make block size size_t type.
And fix all related comparisons and functions.
2017-06-08 14:39:54 +02:00
Milan Broz
34bf809e51 Use device alignment wrapper.
And cache the value to not call ioctl on every block read/write.
2017-06-08 09:30:53 +02:00
Milan Broz
3f9346836e Get rid of old alignment code and use posix_memalign.
We require posix_memalign already for some time so it makes
no sense to keep old workarounds.
2017-04-30 13:13:46 +02:00
Milan Broz
eb59311136 Fix access to unaligned hidden TrueCrypt header.
On native 4k-sector device the old hidden header is not aligned
with hw sector size and derect-io access with SEEK_END fails.

Let's extend blockwise functions to support a negative offset
and use the same logic as normal unaligned writes.

Fixes problem mentioned in
https://gitlab.com/cryptsetup/cryptsetup/merge_requests/18
2017-03-27 12:04:31 +02:00
Milan Broz
98368c4770 Update copyright years. 2017-03-12 13:17:15 +01:00
Eduardo Villanueva Che
2c833c2342 Fixed veritysetup bug with hash offsets bigger than 2gb.
The lseek in function write_blockwise() could return value
that is greater than integer for result so it can overflow
and fail the whole write.
[comment added by mbroz]
2016-10-22 09:24:09 +02:00
Milan Broz
229497871d Fix write_lseek prototype and avoid using void in arithmetic warning. 2016-01-03 16:05:17 +01:00
Ondrej Kozina
8e160562ee read_lseek_blockwise: use void pointer 2015-12-12 17:02:27 +01:00
Ondrej Kozina
091dfa0c26 Slight code style improvements for blockwise functions. 2015-12-01 10:57:04 +01:00