SED OPAL Library
Subsystems (3)
v6 cover SED OPAL Library
Changes from v5->v6:
1) Fixed comments from last review From Christoph
2) Rebased code on top of Jens' for-next
3) Explicitly aligned the structs in the uapi
===============================================================================
This Patch series implements a large portion of the Opal protocol for self encrypting devices. The driver has the capability of storing a locking range's password. The password can then be replayed during a resume from previous suspend-to-RAM.
The driver also supports logic to bring the device out of a factory default-inactive state into a functional Opal state.
The following logic is supported in order to bring the tper into a working state:
1) Taking Ownership of the drive (Setting the Admin CPIN).
2) Activating the Locking SP (In Single User Mode or Normal Mode).
3) Setting up Locking Ranges (Single User or Normal Mode).
4) Adding users to Locking Ranges (Normal Mode Only).
5) Locking or Unlocking Locking Ranges (Single User Mode or Normal Mode).
6) Reverting the TPer (Restore to factory default).
7) Setting LR/User passwords (Single User Mode or Normal Mode).
8) Enabling/disabling Shadow MBR.
9) Enabling Users in the LockingSP (Normal Mode Only).
10) Saving Password for resume from suspend.
11) Erase and Secure erasing locking ranges.
Scott Bauer (3):
Include: Uapi: Add user ABI for Sed/Opal
block: Add Sed-opal library
nvme: Add Support for Opal: Unlock from S3 & Opal Allocation/Ioctls
MAINTAINERS | 11 + block/Kconfig | 7 + block/Makefile | 1 + block/opal_proto.h | 429 ++++++++ block/sed-opal.c | 2448 +++++++++++++++++++++++++++++++++++++++++ drivers/nvme/host/core.c | 25 + drivers/nvme/host/nvme.h | 14 + drivers/nvme/host/pci.c | 7 + include/linux/sed-opal.h | 178 +++ include/uapi/linux/sed-opal.h | 118 ++ 10 files changed, 3238 insertions(+) create mode 100644 block/opal_proto.h create mode 100644 block/sed-opal.c create mode 100644 include/linux/sed-opal.h create mode 100644 include/uapi/linux/sed-opal.h
Signature · 1 line
2.7.4
PATCH v6 1/3 Include: Uapi: Add user ABI for Sed/Opal
--- include/uapi/linux/sed-opal.h | 118 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 include/uapi/linux/sed-opal.h
include/uapi/linux/sed-opal.h new file +118 -0
@@ -0,0 +1,118 @@ +/* +* Copyright ? 2016 Intel Corporation +* +* Authors: +* Rafael Antognolli <rafael.antognolli at intel.com> +* Scott Bauer <scott.bauer at intel.com> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +*/ + +#ifndef _UAPI_SED_OPAL_H +#define _UAPI_SED_OPAL_H + +#include <linux/types.h> + +#define OPAL_KEY_MAX 256 +#define OPAL_MAX_LRS 9 + +enum opal_mbr { +OPAL_MBR_ENABLE =0x0 , +OPAL_MBR_DISABLE =0x01 , +}; + +enum opal_user { +OPAL_ADMIN1 =0x0 , +OPAL_USER1 =0x01 , +OPAL_USER2 =0x02 , +OPAL_USER3 =0x03 , +OPAL_USER4 =0x04 , +OPAL_USER5 =0x05 , +OPAL_USER6 =0x06 , +OPAL_USER7 =0x07 , +OPAL_USER8 =0x08 , +OPAL_USER9 =0x09 , +}; + +enum opal_lock_state { +OPAL_RO =0x01 ,/* 0001 */ +OPAL_RW =0x02 ,/* 0010 */ +OPAL_LK =0x04 ,/* 0100 */ +}; + +struct opal_key { +uint8_t lr; +uint8_t key_len; +char key[OPAL_KEY_MAX ]; +}; + +struct opal_lr_act { +int sum; +uint8_t num_lrs; +uint8_t lr[OPAL_MAX_LRS ]; +struct opal_key key; +}; + +struct opal_session_info { +int sum; +enum opal_user who; +struct opal_key opal_key; +uint8_t __align[2 ]; +}; + +struct opal_user_lr_setup { +size_t range_start; +size_t range_length; +int RLE;/* Read Lock enabled */ +int WLE;/* Write Lock Enabled */ +struct opal_session_info session; +uint8_t __align[4 ]; +}; + +struct opal_lock_unlock { +enum opal_lock_state l_state; +struct opal_session_info session; +}; + +struct opal_new_pw { +struct opal_session_info session; + +/* When we're not operating in sum, and we first set +* passwords we need to set them via ADMIN authority. +* After passwords are changed, we can set them via, +* User authorities. +* Because of this restriction we need to know about +* Two different users. One in 'session' which we will use +* to start the session and new_userr_pw as the user we're +* chaning the pw for. +*/ +struct opal_session_info new_user_pw; +}; + +struct opal_mbr_data { +u8 enable_disable; +struct opal_key key; +uint8_t __align[5 ]; +}; + +#define IOC_OPAL_SAVE _IOW('p', 220, struct opal_lock_unlock) +#define IOC_OPAL_LOCK_UNLOCK _IOW('p', 221, struct opal_lock_unlock) +#define IOC_OPAL_TAKE_OWNERSHIP _IOW('p', 222, struct opal_key) +#define IOC_OPAL_ACTIVATE_LSP _IOW('p', 223, struct opal_key) +#define IOC_OPAL_SET_PW _IOW('p', 224, struct opal_new_pw) +#define IOC_OPAL_ACTIVATE_USR _IOW('p', 225, struct opal_session_info) +#define IOC_OPAL_REVERT_TPR _IOW('p', 226, struct opal_key) +#define IOC_OPAL_LR_SETUP _IOW('p', 227, struct opal_user_lr_setup) +#define IOC_OPAL_ADD_USR_TO_LR _IOW('p', 228, struct opal_lock_unlock) +#define IOC_OPAL_ENABLE_DISABLE_MBR _IOW('p', 229, struct opal_mbr_data) +#define IOC_OPAL_ERASE_LR _IOW('p', 230, struct opal_session_info) +#define IOC_OPAL_SECURE_ERASE_LR _IOW('p', 231, struct opal_session_info) + +#endif /* _UAPI_SED_OPAL_H */
Signature · 1 line
2.7.4
PATCH v6 2/3 block: Add Sed-opal library
In reply to Scott BauerThis patch implements the necessary logic to bring an Opal enabled drive out of a factory-enabled into a working Opal state.
This patch set also enables logic to save a password to be replayed during a resume from suspend.
--- MAINTAINERS | 11 + block/Kconfig | 7 + block/Makefile | 1 + block/opal_proto.h | 429 ++++++++ block/sed-opal.c | 2448 ++++++++++++++++++++++++++++++++++++++++++++++ include/linux/sed-opal.h | 178 ++++ 6 files changed, 3074 insertions(+) create mode 100644 block/opal_proto.h create mode 100644 block/sed-opal.c create mode 100644 include/linux/sed-opal.h
MAINTAINERS +11 -0
@@ -11090,6 +11090,17 @@ L: linux-mmc at vger.kernel.org S: Maintained F: drivers/mmc/host/sdhci-spear.c +SECURE ENCRYPTING DEVICE (SED) OPAL DRIVER +M: Scott Bauer <scott.bauer at intel.com> +M: Jonathan Derrick <jonathan.derrick at intel.com> +M: Rafael Antognolli <rafael.antognolli at intel.com> +L: linux-nvme at lists.infradead.org +S: Supported +F: block/sed* +F: block/opal_proto.h +F: include/linux/sed* +F: include/uapi/linux/sed* + SECURITY SUBSYSTEM M: James Morris <james.l.morris at oracle.com> M: "Serge E. Hallyn" <serge at hallyn.com>
block/Kconfig +7 -0
@@ -164,6 +164,13 @@ config BLK_DEBUG_FS Unless you are building a kernel for a tiny system, you should say Y here. +config BLK_SED_OPAL + bool "Logic for interfacing with Opal enabled SEDs" + ---help--- + Builds Logic for interfacing with Opal enabled controllers. + Enabling this option enables users to setup/unlock/lock + Locking ranges for SED devices using the Opal protocol. + menu "Partition Types" source "block/partitions/Kconfig"
block/Makefile +1 -0
@@ -28,3 +28,4 @@ obj-$(CONFIG_BLK_MQ_PCI) += blk-mq-pci.o obj-$(CONFIG_BLK_DEV_ZONED) += blk-zoned.o obj-$(CONFIG_BLK_WBT) += blk-wbt.o obj-$(CONFIG_BLK_DEBUG_FS) += blk-mq-debugfs.o +obj-$(CONFIG_BLK_SED_OPAL) += sed-opal.o
block/opal_proto.h new file +429 -0
429 lines not on this page · raw message
block/sed-opal.c new file +2448 -0
2,448 lines not on this page · raw message
include/linux/sed-opal.h new file +178 -0
89 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.7.4
Part of the diff is not shown here. View the raw message.
PATCH v6 3/3 nvme: Add Support for Opal: Unlock from S3 & Opal Allocation/Ioctls
In reply to Scott BauerThis patch implements the necessary logic to unlock an Opal enabled device coming back from an S3.
The patch also implements the SED/Opal allocation necessary to support the opal ioctls.
--- drivers/nvme/host/core.c | 25 +++++++++++++++++++++++++ drivers/nvme/host/nvme.h | 14 ++++++++++++++ drivers/nvme/host/pci.c | 7 +++++++ 3 files changed, 46 insertions(+)
drivers/nvme/host/core.c +25 -0
@@ -798,6 +798,8 @@ static int nvme_ioctl(struct block_device *bdev, fmode_t mode,if (ns->ndev)return nvme_nvm_ioctl (ns, cmd, arg);#endif +if (is_sed_ioctl (cmd)) +return sed_ioctl (&ns->ctrl->opal_dev, cmd, arg);return -ENOTTY ; } }
@@ -1065,6 +1067,29 @@ static const struct pr_ops nvme_pr_ops = { .pr_clear = nvme_pr_clear, }; +#ifdef CONFIG_BLK_SED_OPAL +int nvme_sec_submit (struct opal_dev *dev,u16 spsp,u8 secp, +void *buffer,size_t len,bool send) +{ +struct nvme_command cmd; +struct nvme_ctrl *ctrl =NULL ; + +memset (&cmd,0 ,sizeof (cmd)); +if (send) + cmd.common.opcode = nvme_admin_security_send; +else + cmd.common.opcode = nvme_admin_security_recv; + ctrl = container_of(dev, struct nvme_ctrl, opal_dev); + cmd.common.nsid =0 ; + cmd.common.cdw10[0 ] =cpu_to_le32 (((u32 )secp) <<24 | ((u32 )spsp) <<8 ); + cmd.common.cdw10[1 ] =cpu_to_le32 (len); + +return __nvme_submit_sync_cmd (ctrl->admin_q, &cmd,NULL , buffer, len, +ADMIN_TIMEOUT ,NVME_QID_ANY ,1 ,0 ); +} +EXPORT_SYMBOL_GPL (nvme_sec_submit); +#endif /* CONFIG_BLK_SED_OPAL */ +static const struct block_device_operations nvme_fops = { .owner =THIS_MODULE , .ioctl = nvme_ioctl,
drivers/nvme/host/nvme.h +14 -0
@@ -19,6 +19,7 @@#include <linux/kref.h> #include <linux/blk-mq.h> #include <linux/lightnvm.h> +#include <linux/sed-opal.h> enum {/*
@@ -125,6 +126,8 @@ struct nvme_ctrl {struct list_head node;struct ida ns_ida; +struct opal_dev opal_dev; +char name[12 ];char serial[20 ];char model[40 ];
@@ -267,6 +270,17 @@ int nvme_init_identify(struct nvme_ctrl *ctrl);void nvme_queue_scan (struct nvme_ctrl *ctrl);void nvme_remove_namespaces (struct nvme_ctrl *ctrl); +#ifdef CONFIG_BLK_SED_OPAL +int nvme_sec_submit (struct opal_dev *dev,u16 spsp,u8 secp, +void *buffer,size_t len,bool send); +#else +static inline int nvme_sec_submit (struct opal_dev *dev,u16 spsp,u8 secp, +void *buffer,size_t len,bool send) +{ +return 0 ; +} +#endif /* CONFIG_BLK_DEV_SED_OPAL */ +#define NVME_NR_AERS 1void nvme_complete_async_event (struct nvme_ctrl *ctrl,__le16 status,union nvme_result *res);
drivers/nvme/host/pci.c +7 -0
@@ -43,6 +43,7 @@#include <linux/types.h> #include <linux/io-64-nonatomic-lo-hi.h> #include <asm/unaligned.h> +#include <linux/sed-opal.h> #include "nvme.h"
@@ -1754,6 +1755,7 @@ static void nvme_remove_dead_ctrl(struct nvme_dev *dev, int status)static void nvme_reset_work (struct work_struct *work) { struct nvme_dev *dev = container_of(work, struct nvme_dev, reset_work); +bool was_suspend = !!(dev->ctrl.ctrl_config &NVME_CC_SHN_NORMAL );int result = -ENODEV ;if (WARN_ON (dev->ctrl.state ==NVME_CTRL_RESETTING ))
@@ -1786,6 +1788,11 @@ static void nvme_reset_work(struct work_struct *work)if (result) goto out; +init_opal_dev (&dev->ctrl.opal_dev, &nvme_sec_submit); + +if (was_suspend) +opal_unlock_from_suspend (&dev->ctrl.opal_dev); + result =nvme_setup_io_queues (dev);if (result) goto out;
Signature · 1 line
2.7.4
v6 cover SED OPAL Library
In reply to Scott BauerLooks fine:
v6 cover SED OPAL Library
In reply to Scott BauerQuoted 18 lines · Scott Bauer
Changes from
v5->v6:1) Fixed comments from last review From Christoph
2) Rebased code on top of Jens' for-next
3) Explicitly aligned the structs in the uapi===============================================================================
This Patch series implements a large portion of the Opal protocol for self encrypting devices. The driver has the capability of storing a locking range's password. The password can then be replayed during a resume from previous suspend-to-RAM.The driver also supports logic to bring the device out of a factory default-inactive state into a functional Opal state.
The following logic is supported in order to bring the tper into a working state:
Quoted 11 lines
1) Taking Ownership of the drive (Setting the Admin CPIN).
2) Activating the Locking SP (In Single User Mode or Normal Mode).
3) Setting up Locking Ranges (Single User or Normal Mode).
4) Adding users to Locking Ranges (Normal Mode Only).
5) Locking or Unlocking Locking Ranges (Single User Mode or Normal Mode).
6) Reverting the TPer (Restore to factory default).
7) Setting LR/User passwords (Single User Mode or Normal Mode).
8) Enabling/disabling Shadow MBR.
9) Enabling Users in the LockingSP (Normal Mode Only).
10) Saving Password for resume from suspend.
11) Erase and Secure erasing locking ranges.
Applied for 4.11, thanks.
Signature · 1 line
Jens Axboe