From: Hannes Reinecke <hare@kernel.org>
To: Christoph Hellwig <hch@lst.de>
Cc: Sagi Grimberg <sagi@grimberg.me>, Keith Busch <kbusch@kernel.org>,
linux-nvme@lists.infradead.org, Hannes Reinecke <hare@kernel.org>,
Hannes Reinecke <hare@suse.de>
Subject: [PATCH] nvme: add sysfs attribute 'tls_keyring'
Date: Fri, 8 Mar 2024 13:10:06 +0100 [thread overview]
Message-ID: <20240308121006.69442-1-hare@kernel.org> (raw)
Add a sysfs attribute 'tls_keyring' to hold the contents for the
'keyring' fabrics option. This option is only meaningful if the
'tls' option has been specified; if the 'tls_key' option is specified
the key is looked up directly and the keyring setting is ignored.
So blank out the keyring value when 'tls_key' is specified.
Signed-off-by: Hannes Reinecke <hare@suse.de>
---
drivers/nvme/host/sysfs.c | 55 +++++++++++++++++++++++++++++++++++++--
1 file changed, 53 insertions(+), 2 deletions(-)
diff --git a/drivers/nvme/host/sysfs.c b/drivers/nvme/host/sysfs.c
index 6c7f1d5c056f..7b65ff7426c9 100644
--- a/drivers/nvme/host/sysfs.c
+++ b/drivers/nvme/host/sysfs.c
@@ -5,11 +5,12 @@
* Copyright (c) 2011-2014, Intel Corporation.
*/
-#include <linux/nvme-auth.h>
-
#include "nvme.h"
#include "fabrics.h"
+#include <linux/nvme-auth.h>
+#include <linux/nvme-keyring.h>
+
static ssize_t nvme_sysfs_reset(struct device *dev,
struct device_attribute *attr, const char *buf,
size_t count)
@@ -677,6 +678,52 @@ static ssize_t tls_key_show(struct device *dev,
return sysfs_emit(buf, "%08x", key_serial(ctrl->tls_key));
}
static DEVICE_ATTR_RO(tls_key);
+
+static ssize_t tls_keyring_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
+ struct key *keyring;
+
+ if (!ctrl->tls_key)
+ return 0;
+ /* Do not display the keyring for user-selected keys */
+ if (ctrl->opts->tls_key)
+ return 0;
+ keyring = ctrl->opts->keyring;
+ if (!keyring) {
+ keyring = key_lookup(nvme_keyring_id());
+ if (!keyring)
+ return -EINVAL;
+ }
+ return sysfs_emit(buf, "%s", keyring->description);
+}
+
+static ssize_t tls_keyring_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t count)
+{
+ struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
+ int err;
+ u32 key_id;
+ struct key *keyring;
+
+ if (!strlen(buf))
+ return -EINVAL;
+ err = kstrtou32(buf, 0, &key_id);
+ if (err)
+ return err;
+ keyring = key_lookup(key_id);
+ if (IS_ERR(keyring)) {
+ pr_err("key %08x not found\n", key_id);
+ return -EINVAL;
+ }
+ if (ctrl->opts->keyring)
+ key_put(ctrl->opts->keyring);
+ ctrl->opts->keyring = keyring;
+ return 0;
+}
+static DEVICE_ATTR(tls_keyring, S_IRUGO | S_IWUSR,
+ tls_keyring_show, tls_keyring_store);
#endif
static struct attribute *nvme_dev_attrs[] = {
@@ -708,6 +755,7 @@ static struct attribute *nvme_dev_attrs[] = {
#endif
#ifdef CONFIG_NVME_TCP_TLS
&dev_attr_tls_key.attr,
+ &dev_attr_tls_keyring.attr,
#endif
&dev_attr_adm_passthru_err_log_enabled.attr,
NULL
@@ -743,6 +791,9 @@ static umode_t nvme_dev_attrs_are_visible(struct kobject *kobj,
if (a == &dev_attr_tls_key.attr &&
(!ctrl->opts || strcmp(ctrl->opts->transport, "tcp")))
return 0;
+ if (a == &dev_attr_tls_keyring.attr &&
+ (!ctrl->opts || strcmp(ctrl->opts->transport, "tcp")))
+ return 0;
#endif
return a->mode;
--
2.35.3
next reply other threads:[~2024-03-08 12:10 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-08 12:10 Hannes Reinecke [this message]
2024-03-08 14:01 ` [PATCH] nvme: add sysfs attribute 'tls_keyring' Sagi Grimberg
2024-03-08 14:06 ` Hannes Reinecke
2024-03-08 14:18 ` Sagi Grimberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240308121006.69442-1-hare@kernel.org \
--to=hare@kernel.org \
--cc=hare@suse.de \
--cc=hch@lst.de \
--cc=kbusch@kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=sagi@grimberg.me \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox