Skip to contentSkip to conversation

s390/uv: Provide Host-key-hashes in sysfs

PATCH Superseded Steffen Eiden 2 participants 5 messages Sep 30, 2024 – Oct 1, 2024

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover s390/uv: Provide Host-key-hashes in sysfs

List the installed host keys in the sysfs if the machine supports the Query Ultravisor Keys UVC.

As of now, two types of host keys are available:
The used/primary host key, and the backup hostkey both hastes are available in a sysfs file.
For forwards compatibility an all file is also available that displays the whole payload (15*32 bytes) and therefore future key hashes.

Steffen Eiden (2):
s390/uv: Refactor uv-sysfs creation
s390/uv: Provide host-key hashes in sysfs

 arch/s390/include/asm/uv.h |  16 ++++++
 arch/s390/kernel/uv.c      | 108 +++++++++++++++++++++++++++++++++----
 2 files changed, 114 insertions(+), 10 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/2 s390/uv: Refactor uv-sysfs creation

Streamline the sysfs generation to make it more extensible. Add a function to create a sysfs entry in the uv-sysfs dir. Use this function for the query directory.

---
 arch/s390/kernel/uv.c | 35 ++++++++++++++++++++++++-----------
 1 file changed, 24 insertions(+), 11 deletions(-)
arch/s390/kernel/uv.c +24 -11
index 36db065c7cf7..d703ecc9aea5 100644
@@ -752,7 +752,26 @@ static const struct attribute *uv_prot_virt_attrs[] = {
 static struct kset *uv_query_kset;
 static struct kobject *uv_kobj;
 
-static int __init uv_info_init(void)
+static int __init uv_sysfs_dir_init(const struct attribute_group *grp,
+				    struct kset **uv_dir_kset, const char *name)
+{
+	struct kset *kset;
+	int rc = -ENOMEM;
+
+	kset = kset_create_and_add(name, NULL, uv_kobj);
+	if (!kset)
+		return -ENOMEM;
+	*uv_dir_kset = kset;
+
+	rc = sysfs_create_group(&kset->kobj, grp);
+	if (!rc)
+		return 0;
+
+	kset_unregister(kset);
+	return rc;
+}
+
+static int __init uv_sysfs_init(void)
 {
 	int rc = -ENOMEM;
 
@@ -767,17 +786,11 @@ static int __init uv_info_init(void)
 	if (rc)
 		goto out_kobj;
 
-	uv_query_kset = kset_create_and_add("query", NULL, uv_kobj);
-	if (!uv_query_kset) {
-		rc = -ENOMEM;
+	rc = uv_sysfs_dir_init(&uv_query_attr_group, &uv_query_kset, "query");
+	if (rc)
 		goto out_ind_files;
-	}
-
-	rc = sysfs_create_group(&uv_query_kset->kobj, &uv_query_attr_group);
-	if (!rc)
-		return 0;
+	return 0;
 
-	kset_unregister(uv_query_kset);
 out_ind_files:
 	sysfs_remove_files(uv_kobj, uv_prot_virt_attrs);
 out_kobj:
@@ -785,4 +798,4 @@ static int __init uv_info_init(void)
 	kobject_put(uv_kobj);
 	return rc;
 }
-device_initcall(uv_info_init);
+device_initcall(uv_sysfs_init);
Signature · 1 line
2.43.0
#3 lore raw

PATCH 2/2 s390/uv: Provide host-key hashes in sysfs

In reply to Steffen Eiden

Utilize the new Query Ultravisor Keys to give user space the information which host-keys are installed on the system.

Create a new sysfs directory 'firmware/uv/keys' that contains the hash of the host-key and the backup host-key of that system. Additionally, the file 'all' contains the response from the UVC possibly containing more key-hashes than currently known.

---
 arch/s390/include/asm/uv.h | 16 ++++++++
 arch/s390/kernel/uv.c      | 75 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 91 insertions(+)
arch/s390/include/asm/uv.h +16 -0
index 153d93468b77..7eda73073cdd 100644
@@ -31,6 +31,7 @@
 #define UVC_RC_NEED_DESTROY	0x8000
 
 #define UVC_CMD_QUI			0x0001
+#define UVC_CMD_QUK			0x0002
 #define UVC_CMD_INIT_UV			0x000f
 #define UVC_CMD_CREATE_SEC_CONF		0x0100
 #define UVC_CMD_DESTROY_SEC_CONF	0x0101
@@ -94,6 +95,7 @@ enum uv_cmds_inst {
 	BIT_UVC_CMD_ADD_SECRET = 29,
 	BIT_UVC_CMD_LIST_SECRETS = 30,
 	BIT_UVC_CMD_LOCK_SECRETS = 31,
+	BIT_UVC_CMD_QUERY_KEYS = 34,
 };
 
 enum uv_feat_ind {
@@ -145,6 +147,20 @@ struct uv_cb_qui {
 	u8 reserved112[0x120 - 0x112];		/* 0x0112 */
 } __packed __aligned(8);
 
+struct uv_key_hash {
+	u64 dword[4];
+} __packed __aligned(8);
+
+#define UVC_QUERY_KEYS_IDX_HK		0
+#define UVC_QUERY_KEYS_IDX_BACK_HK		1
+
+/* Query Ultravisor Keys */
+struct uv_cb_query_keys {
+	struct uv_cb_header header;	/* 0x0000 */
+	u64 reserved08[3];		/* 0x0008 */
+	struct uv_key_hash keys[15];	/* 0x0020 */
+} __packed __aligned(8);
+
 /* Initialize Ultravisor */
 struct uv_cb_init {
 	struct uv_cb_header header;
arch/s390/kernel/uv.c +75 -0

97 lines not on this page · raw message

Signature · 1 line
2.43.0
maintainer
#4 lore raw

Re: [PATCH v1 2/2] s390/uv: Provide host-key hashes in sysfs

Quoted 20 lines · Steffen Eiden

Utilize the new Query Ultravisor Keys to give user space the information which host-keys are installed on the system.

Create a new sysfs directory 'firmware/uv/keys' that contains the hash of the host-key and the backup host-key of that system. Additionally, the file 'all' contains the response from the UVC possibly containing more key-hashes than currently known.

---
  arch/s390/include/asm/uv.h | 16 ++++++++
  arch/s390/kernel/uv.c      | 75 ++++++++++++++++++++++++++++++++++++++
  2 files changed, 91 insertions(+)
arch/s390/include/asm/uv.h +0 -0
index 153d93468b77..7eda73073cdd 100644

arch/s390/include/asm/uv.h line 34

Quoted 4 lines
arch/s390/include/asm/uv.h +1 -0
@@ -31,6 +31,7 @@
  #define UVC_RC_NEED_DESTROY	0x8000
 
  #define UVC_CMD_QUI			0x0001
+#define UVC_CMD_QUK			0x0002

Should've used the long form here as well.

Quoted 10 lines
arch/s390/include/asm/uv.h +1 -0
  #define UVC_CMD_INIT_UV			0x000f
  #define UVC_CMD_CREATE_SEC_CONF		0x0100
  #define UVC_CMD_DESTROY_SEC_CONF	0x0101
@@ -94,6 +95,7 @@ enum uv_cmds_inst {
  	BIT_UVC_CMD_ADD_SECRET = 29,
  	BIT_UVC_CMD_LIST_SECRETS = 30,
  	BIT_UVC_CMD_LOCK_SECRETS = 31,
+	BIT_UVC_CMD_QUERY_KEYS = 34,
  };
 

[...]

arch/s390/include/asm/uv.h static int __init uv_sysfs_init(void) · line 863

Quoted 7 lines

static int __init uv_sysfs_dir_init(const struct attribute_group *grp,

arch/s390/include/asm/uv.h +2 -0
@@ -789,6 +859,11 @@ static int __init uv_sysfs_init(void)
  	rc = uv_sysfs_dir_init(&uv_query_attr_group, &uv_query_kset, "query");
  	if (rc)
  		goto out_ind_files;
+
+	// Get installed key hashes if available, ignore any errors

Please use:
/* */

Quoted 6 lines
arch/s390/include/asm/uv.h +3 -0
+	if (test_bit_inv(BIT_UVC_CMD_QUERY_KEYS, uv_info.inst_calls_list))
+		uv_sysfs_dir_init(&uv_keys_attr_group, &uv_keys_kset, "keys");
+
  	return 0;
 
  out_ind_files:
maintainer Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH v1 1/2] s390/uv: Refactor uv-sysfs creation

In reply to Steffen Eiden
Quoted 6 lines · Steffen Eiden

Streamline the sysfs generation to make it more extensible. Add a function to create a sysfs entry in the uv-sysfs dir. Use this function for the query directory.

Quoted 6 lines
arch/s390/kernel/uv.c +0 -2
@@ -767,17 +786,11 @@ static int __init uv_info_init(void)
  	if (rc)
  		goto out_kobj;
 
-	uv_query_kset = kset_create_and_add("query", NULL, uv_kobj);
-	if (!uv_query_kset) {

arch/s390/kernel/uv.c static int __init uv_info_init(void) · line 792

Quoted 10 lines
arch/s390/kernel/uv.c +3 -6
-		rc = -ENOMEM;
+	rc = uv_sysfs_dir_init(&uv_query_attr_group, &uv_query_kset, "query");
+	if (rc)
  		goto out_ind_files;
-	}
-
-	rc = sysfs_create_group(&uv_query_kset->kobj, &uv_query_attr_group);
-	if (!rc)
-		return 0;
+	return 0;

Could've left a \n before the return so it doesn't look weird if only this patch is applied. But that's not important.

Quoted 11 lines
arch/s390/kernel/uv.c +1 -2
-	kset_unregister(uv_query_kset);
  out_ind_files:
  	sysfs_remove_files(uv_kobj, uv_prot_virt_attrs);
  out_kobj:
@@ -785,4 +798,4 @@ static int __init uv_info_init(void)
  	kobject_put(uv_kobj);
  	return rc;
  }
-device_initcall(uv_info_init);
+device_initcall(uv_sysfs_init);