Commit Graph

20 Commits

Author SHA1 Message Date
Milan Broz
e5405f2fd8 Use #if for HAVE*_H defines. 2025-01-27 11:05:08 +00:00
Milan Broz
f64f6fb9e8 opal: Fix error table offset
The error table was partially wrong (for codes >0x0b)

Let's use exact enum codes according to TCG Core spec (5.1.5).

This also fixes CodeQL warning.
2025-01-27 11:04:25 +00:00
Milan Broz
5c795885c5 opal: update copyright 2025-01-27 11:04:25 +00: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
8448448aa2 Opal: Check for bogus logical size also in activation
For existing devices we only print warning, but the device is
probably completely misconfigured.
2024-06-03 11:14:27 +00:00
Milan Broz
329fa3c54e Opal: Require locking range attributes in range check function.
The check will be required mandatory in the next patch.
2024-06-03 11:14:27 +00:00
Milan Broz
40e5c7d095 Use crypt_safe_memcpy for operations with key. 2024-05-03 11:52:09 +00:00
Ondrej Kozina
a462dbeb4e Check HW OPAL range parameters in proper units.
The opal_range_check_attributes_fd function expected both
offset and length parameters of a LR to be passed in sectors (512B).
During format we passed it wrongly in OPAL blocks which caused
bogus check provided OPAL block size was not 512B.

Fixes: #871.
2024-03-26 11:55:31 +01:00
Milan Broz
f87f6226aa opal: Fix benign gcc warning for possible uninitialized value. 2023-12-19 13:40:29 +01:00
Ondrej Kozina
6b1f13fd0f opal: add comments to all lockless opal calls. 2023-12-18 17:26:47 +00:00
Ondrej Kozina
0ca1e680db opal: add exclusive lock to avoid race.
Activating LUKS2 device with OPAL support is multistep process.

1) read LR state
2) unlock LR
3) activate dm device
4) in case step 3) failed lock the device
   if in step 1) the device was locked.

Otherwise, in case parallel activation happened on one device
the process that failed to map dm device (device already active)
could relock the LR afterwards and effectively break already active
device.

To avoid that we do steps 1) through 4) protected by exclusive
opal lock unique per data block device configured for use with
LUKS2 OPAL support.
2023-12-13 20:59:14 +00:00
Ondrej Kozina
2e978c8776 opal: do not always re-lock range on failed activation.
If activation fails due to already active dm mapping
we must not automatically re-lock the OPAL range since
it would break the original active device.
2023-12-13 20:59:14 +00:00
Ondrej Kozina
997ef242a2 opal: no need to export internal opal_enabled function. 2023-12-13 15:16:02 +01:00
Ondrej Kozina
b869822c8b opal: erase key cached in kernel when LR gets locked.
It affects only HW OPAL locking range KEK.

After unlocking opal locking range we cache the key in kernel
so that we do not have to pass the key again for locking the
range later (the OPAL std requires key for lock command).

Unfortunately the key remains cached in kernel even after we
lock the range on purpose during crypt_deactivate* or crypt_suspend.

This had 2 side effects:

1) key remained in system memory even though the LUKS device was
   inactive (and all keys should be erased from memory).

2) when system gets suspended the locking range got automatically
   unlocked later after system resume because the key caching is used
   primarly to automatically unlock locking ranges that got locked
   after system suspend (due to power cut off on storage device).

Since kernel does not directly support dropping cached keys we achieve
that by overwritting the original key structure with empty one.
2023-12-04 19:02:11 +00:00
Ondrej Kozina
860550b3c6 Fix memory leaks detected in compat-test-opal. 2023-11-07 09:58:53 +01:00
Milan Broz
ab71eff3b9 opal: Remove key length debug msg. 2023-08-29 11:36:43 +02:00
Milan Broz
9b768cd401 Opal: add debug of Opal ioctl calls
This should print non-sensitive info only, no key info.
2023-08-29 11:36:39 +02:00
Milan Broz
c417c70a78 Opal: open device read-only as it is enough for ioctl.
This also solves the problem of using PSID reset
on write-protected device (some controllers lock the drive).
2023-08-29 11:36:35 +02:00
Milan Broz
f70bf71dff Fix unused parameter in crypto backend handlers. 2023-08-28 12:42:37 +02:00
Luca Boccassi
b9cc0129c9 libcryptsetup: add OPAL type and params
Signed-off-by: Luca Boccassi <bluca@debian.org>
Co-authored-by: Ondrej Kozina <okozina@redhat.com>
2023-07-17 13:14:52 +02:00