From db980ba1c68c48fb972035e6bd3930e55961d5ce Mon Sep 17 00:00:00 2001 From: Milan Broz Date: Mon, 27 May 2024 11:50:47 +0200 Subject: [PATCH] Opal: Check for bogus logical size also in activation For existing devices we only print warning, but the device is probably completely misconfigured. --- lib/luks2/hw_opal/hw_opal.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/luks2/hw_opal/hw_opal.c b/lib/luks2/hw_opal/hw_opal.c index cc672a61..eaae4a7c 100644 --- a/lib/luks2/hw_opal/hw_opal.c +++ b/lib/luks2/hw_opal/hw_opal.c @@ -41,6 +41,7 @@ #if HAVE_HW_OPAL #include +#include /* Error codes are defined in the specification: * TCG_Storage_Architecture_Core_Spec_v2.01_r1.00 @@ -290,6 +291,7 @@ static int opal_range_check_attributes_fd(struct crypt_device *cd, { int r; struct opal_lr_status *lrs; + int device_block_bytes; uint32_t opal_block_bytes = 0; uint64_t offset, length; bool read_locked, write_locked; @@ -304,6 +306,11 @@ static int opal_range_check_attributes_fd(struct crypt_device *cd, if (r != OPAL_STATUS_SUCCESS) return -EINVAL; + /* Keep this as warning only */ + if (ioctl(fd, BLKSSZGET, &device_block_bytes) < 0 || + (uint32_t)device_block_bytes != opal_block_bytes) + log_err(cd, _("Bogus OPAL logical block size differs from device block size.")); + lrs = crypt_safe_alloc(sizeof(*lrs)); if (!lrs) return -ENOMEM;