lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20251127070704.2935390-3-zheng.gong@samsung.com>
Date: Thu, 27 Nov 2025 15:06:59 +0800
From: "zheng.gong" <zheng.gong@...sung.com>
To: linux-scsi@...r.kernel.org
Cc: avri.altman@....com, bvanassche@....org, quic_cang@...cinc.com,
	alim.akhtar@...sung.com, martin.petersen@...cle.com, ebiggers@...nel.org,
	linux-kernel@...r.kernel.org, "zheng.gong" <zheng.gong@...sung.com>
Subject: [PATCH v2 2/2] scsi: ufs: Add crypto keyslot remapping test module

Add a test module (CONFIG_SCSI_UFS_CRYPTO_TEST) that demonstrates the use
of the new crypto_keyslot_remap variant operation. The module registers a
dummy variant ops that shifts the logical keyslot by a fixed offset (e.g., +8),
simulating a secondary domain in a multi-domain environment.

This is not a production driver, but serves to show that the hook is used.

Note: This patch is intended to illustrate usage. If maintainers prefer not
to include test modules in the core UFS driver, it can be dropped in a future
version.

Signed-off-by: zheng.gong <zheng.gong@...sung.com>
---
 drivers/ufs/core/Kconfig              | 17 +++++
 drivers/ufs/core/Makefile             |  1 +
 drivers/ufs/core/ufshcd-crypto-test.c | 90 +++++++++++++++++++++++++++
 3 files changed, 108 insertions(+)
 create mode 100644 drivers/ufs/core/ufshcd-crypto-test.c

diff --git a/drivers/ufs/core/Kconfig b/drivers/ufs/core/Kconfig
index 817208ee64ec..c5dfd3722365 100644
--- a/drivers/ufs/core/Kconfig
+++ b/drivers/ufs/core/Kconfig
@@ -50,3 +50,20 @@ config SCSI_UFS_HWMON
 	  a hardware monitoring device will be created for the UFS device.
 
 	  If unsure, say N.
+
+config SCSI_UFS_CRYPTO_TEST
+	bool "UFS crypto keyslot remapping test module"
+	depends on SCSI_UFS_CRYPTO
+	help
+	  This option enables a test implementation of the crypto_keyslot_remap
+	  variant operation to demonstrate how platform-specific keyslot remapping
+	  can be used for multi-domain inline encryption (e.g., VM or security
+	  domain isolation).
+
+	  The test module registers a dummy variant ops that shifts the keyslot
+	  by a fixed offset (e.g., +8), simulating a secondary domain.
+
+	  This is for testing and demonstration only. Say Y or M if you want to
+	  verify the remapping hook works end-to-end.
+
+	  If unsure, say N.
diff --git a/drivers/ufs/core/Makefile b/drivers/ufs/core/Makefile
index cf820fa09a04..cf85fee26afb 100644
--- a/drivers/ufs/core/Makefile
+++ b/drivers/ufs/core/Makefile
@@ -7,3 +7,4 @@ ufshcd-core-$(CONFIG_SCSI_UFS_BSG)	+= ufs_bsg.o
 ufshcd-core-$(CONFIG_SCSI_UFS_CRYPTO)	+= ufshcd-crypto.o
 ufshcd-core-$(CONFIG_SCSI_UFS_FAULT_INJECTION) += ufs-fault-injection.o
 ufshcd-core-$(CONFIG_SCSI_UFS_HWMON)	+= ufs-hwmon.o
+ufshcd-core-$(CONFIG_SCSI_UFS_CRYPTO_TEST) += ufshcd-crypto-test.o
diff --git a/drivers/ufs/core/ufshcd-crypto-test.c b/drivers/ufs/core/ufshcd-crypto-test.c
new file mode 100644
index 000000000000..96706a5b3b56
--- /dev/null
+++ b/drivers/ufs/core/ufshcd-crypto-test.c
@@ -0,0 +1,90 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2025 Samsung Electronics Co., Ltd.
+ */
+
+#include <ufs/ufshcd.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+
+#ifdef CONFIG_SCSI_UFS_CRYPTO_TEST
+
+static void ufs_crypto_test_keyslot_remap(struct ufs_hba *hba,
+										  struct ufshcd_lrb *lrbp)
+{
+	/*
+	 * Simulate a platform that uses non-zero keyslot base for certain domains.
+	 * For example:
+	 *   - Domain 0: keyslots [0–7]
+	 *   - Domain 1: keyslots [8–15]
+	 *
+	 * This is done by adding a fixed offset to the logical keyslot.
+	 *
+	 * In real platforms, this offset might depend on VM ID, security level,
+	 * or other runtime context.
+	 */
+	const int keyslot_offset = 8;
+
+	if (lrbp->crypto_key_slot >= 0) {
+		lrbp->crypto_key_slot += keyslot_offset;
+		pr_debug("remapped keyslot %d -> %d\n",
+				 lrbp->crypto_key_slot - keyslot_offset,
+				 lrbp->crypto_key_slot);
+	}
+}
+
+static struct ufs_hba_variant_ops ufs_crypto_test_variant_ops = {
+	.name = "ufs-crypto-test",
+	.crypto_keyslot_remap = ufs_crypto_test_keyslot_remap,
+};
+
+/* Only register if no platform ops are already set (for test purposes) */
+static int ufs_crypto_test_probe(struct platform_device *pdev)
+{
+	struct ufs_hba *hba = dev_get_drvdata(&pdev->dev);
+
+	if (!hba) {
+		dev_err(&pdev->dev, "no UFS HBA found\n");
+		return -ENODEV;
+	}
+
+	if (hba->vops) {
+		dev_info(&pdev->dev,
+			"HBA already has variant ops (%s), not registering test ops\n",
+			hba->vops->name);
+		return -EBUSY;
+	}
+
+	hba->vops = &ufs_crypto_test_variant_ops;
+	dev_info(&pdev->dev, "registered crypto_keyslot_remap test hook\n");
+
+	return 0;
+}
+
+static void ufs_crypto_test_remove(struct platform_device *pdev)
+{
+	struct ufs_hba *hba = dev_get_drvdata(&pdev->dev);
+
+	if (hba && hba->vops == &ufs_crypto_test_variant_ops) {
+		pr_info("unregistered crypto_keyslot_remap test hook\n");
+		hba->vops = NULL;
+	}
+}
+
+static struct platform_driver ufs_crypto_test_plat_drv = {
+	.probe = ufs_crypto_test_probe,
+	.remove = ufs_crypto_test_remove,
+	.driver = {
+		.name = "ufs-crypto-test",
+		.owner = THIS_MODULE,
+	},
+};
+
+module_platform_driver(ufs_crypto_test_plat_drv);
+
+MODULE_AUTHOR("Zheng Gong <zheng.gong@...sung.com>");
+MODULE_DESCRIPTION("UFS Crypto Keyslot Remapping Test Module");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:ufs-crypto-test");
+
+#endif /* CONFIG_SCSI_UFS_CRYPTO_TEST */
\ No newline at end of file
-- 
2.50.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ