All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sed-opal: if key is available from IOC_OPAL_SAVE use it when locking
@ 2022-12-02  0:36 luca.boccassi
  2022-12-02  8:48 ` Christian Brauner
                   ` (3 more replies)
  0 siblings, 4 replies; 14+ messages in thread
From: luca.boccassi @ 2022-12-02  0:36 UTC (permalink / raw)
  To: linux-block; +Cc: jonathan.derrick, gmazyland, axboe, brauner, stepan.horacek

From: Luca Boccassi <bluca@debian.org>

Usually when closing a crypto device (eg: dm-crypt with LUKS) the
volume key is not required, as it requires root privileges anyway, and
root can deny access to a disk in many ways regardless. Requiring the
volume key to lock the device is a peculiarity of the OPAL
specification.

Given we might already have saved the key if the user requested it via
the 'IOC_OPAL_SAVE' ioctl, we can use that key to lock the device if no
key was provided here and the locking range matches. This allows
integrating OPAL with tools and libraries that are used to the common
behaviour and do not ask for the volume key when closing a device.

If the caller provides a key on the other hand it will still be used as
before, no changes in that case.

Suggested-by: Štěpán Horáček <stepan.horacek@gmail.com>
Signed-off-by: Luca Boccassi <bluca@debian.org>
---
 block/sed-opal.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/block/sed-opal.c b/block/sed-opal.c
index 9bdb833e5817..b54bb76e4484 100644
--- a/block/sed-opal.c
+++ b/block/sed-opal.c
@@ -2470,6 +2470,35 @@ static int opal_lock_unlock(struct opal_dev *dev,
 		return -EINVAL;
 
 	mutex_lock(&dev->dev_lock);
+
+	/*
+	 * Usually when closing a crypto device (eg: dm-crypt with LUKS) the volume key
+	 * is not required, as it requires root privileges anyway, and root can deny
+	 * access to a disk in many ways regardless. Requiring the volume key to lock
+	 * the device is a peculiarity of the OPAL specification.
+	 * Given we might already have saved the key if the user requested it via the
+	 * 'IOC_OPAL_SAVE' ioctl, we can use that key to lock the device if no key was
+	 * provided here and the locking range matches. This allows integrating OPAL
+	 * with tools and libraries that are used to the common behaviour and do not
+	 * ask for the volume key when closing a device.
+	 */
+	if (lk_unlk->l_state == OPAL_LK && lk_unlk->session.opal_key.key_len == 0) {
+		struct opal_suspend_data *iter;
+
+		setup_opal_dev(dev);
+		list_for_each_entry(iter, &dev->unlk_lst, node) {
+			if (iter->lr == lk_unlk->session.opal_key.lr &&
+					iter->unlk.session.opal_key.key_len > 0) {
+				lk_unlk->session.opal_key.key_len =
+					iter->unlk.session.opal_key.key_len;
+				memcpy(lk_unlk->session.opal_key.key,
+					iter->unlk.session.opal_key.key,
+					iter->unlk.session.opal_key.key_len);
+				break;
+			}
+		}
+	}
+
 	ret = __opal_lock_unlock(dev, lk_unlk);
 	mutex_unlock(&dev->dev_lock);
 
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2022-12-08 16:20 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-02  0:36 [PATCH] sed-opal: if key is available from IOC_OPAL_SAVE use it when locking luca.boccassi
2022-12-02  8:48 ` Christian Brauner
2022-12-02  9:11   ` Christoph Hellwig
2022-12-02 10:28   ` Luca Boccassi
2022-12-02 10:37     ` Christian Brauner
2022-12-03  0:12 ` [PATCH v2] sed-opal: allow using IOC_OPAL_SAVE for locking too luca.boccassi
2022-12-05  7:09   ` Christoph Hellwig
2022-12-06  0:03 ` [PATCH v3] " luca.boccassi
2022-12-06  8:30   ` Christoph Hellwig
2022-12-06  9:23   ` Christian Brauner
2022-12-06  9:29 ` [PATCH v4] " luca.boccassi
2022-12-08 16:18   ` Jens Axboe
2022-12-08 16:19     ` Luca Boccassi
2022-12-08 16:20   ` Jens Axboe

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.