Linux cryptographic layer development
 help / color / mirror / Atom feed
* [PATCH 0/2] crypto: rockchip - fix hash timeouts and debugfs leak
@ 2026-11-28 20:47 Timur Kussainov
  2026-11-28 20:47 ` [PATCH 1/2] crypto: rockchip - fix inverted hash completion poll Timur Kussainov
  2026-11-28 20:47 ` [PATCH 2/2] crypto: rockchip - fix debugfs leak when stats are disabled Timur Kussainov
  0 siblings, 2 replies; 3+ messages in thread
From: Timur Kussainov @ 2026-11-28 20:47 UTC (permalink / raw)
  To: Herbert Xu, Corentin Labbe
  Cc: David S . Miller, Heiko Stuebner, linux-crypto, linux-rockchip,
	linux-arm-kernel, linux-kernel, Timur Kussainov

On RK3288 (tested on an ASUS Tinker Board) all hardware hashes of the
rockchip crypto driver currently fail with "HASH idle timeout" and the
rk-md5/rk-sha1/rk-sha256 self-tests fail. Patch 1 fixes the inverted
completion poll that causes this.

Patch 2 fixes a debugfs directory leak with
CONFIG_CRYPTO_DEV_ROCKCHIP_DEBUG=n, which leads to an oops when the
stale stats file is read after the module is removed (found while
testing patch 1 by reloading the module).

Timur Kussainov (2):
  crypto: rockchip - fix inverted hash completion poll
  crypto: rockchip - fix debugfs leak when stats are disabled

 drivers/crypto/rockchip/rk3288_crypto.c       | 19 +++++++------------
 drivers/crypto/rockchip/rk3288_crypto_ahash.c |  2 +-
 2 files changed, 8 insertions(+), 13 deletions(-)

-- 
2.47.3


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

* [PATCH 1/2] crypto: rockchip - fix inverted hash completion poll
  2026-11-28 20:47 [PATCH 0/2] crypto: rockchip - fix hash timeouts and debugfs leak Timur Kussainov
@ 2026-11-28 20:47 ` Timur Kussainov
  2026-11-28 20:47 ` [PATCH 2/2] crypto: rockchip - fix debugfs leak when stats are disabled Timur Kussainov
  1 sibling, 0 replies; 3+ messages in thread
From: Timur Kussainov @ 2026-11-28 20:47 UTC (permalink / raw)
  To: Herbert Xu, Corentin Labbe
  Cc: David S . Miller, Heiko Stuebner, linux-crypto, linux-rockchip,
	linux-arm-kernel, linux-kernel, Timur Kussainov, stable

Before commit 37bc22159c45 ("crypto: rockchip - use read_poll_timeout"),
rk_hash_run() waited for the hash engine with

	while (!CRYPTO_READ(tctx->dev, RK_CRYPTO_HASH_STS))
		udelay(10);

i.e. it spun until RK_CRYPTO_HASH_STS became non-zero (HASH_DONE set).
The conversion to readl_poll_timeout() inverted the condition to
"v == 0", so the poll now waits for the opposite state. The return value
was ignored at the time, so the bug went unnoticed: the digest was read
after the 1 ms timeout and happened to be correct.

Now that the timeout is reported as an error, every hash request fails
with "HASH idle timeout" and the rk-sha1/rk-sha256/rk-md5 self-tests
fail.

Poll for the HASH_DONE bit, as the original code did.

Tested on an ASUS Tinker Board (RK3288): the md5/sha1/sha256 self-tests
pass, and 300 digests of random buffers (4 bytes to 1 MiB) computed via
AF_ALG match the generic implementation.

Fixes: 37bc22159c45 ("crypto: rockchip - use read_poll_timeout")
Cc: stable@vger.kernel.org
Signed-off-by: Timur Kussainov <kusainov.timur@gmail.com>
---
 drivers/crypto/rockchip/rk3288_crypto_ahash.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/crypto/rockchip/rk3288_crypto_ahash.c b/drivers/crypto/rockchip/rk3288_crypto_ahash.c
index d3482619a..922980b66 100644
--- a/drivers/crypto/rockchip/rk3288_crypto_ahash.c
+++ b/drivers/crypto/rockchip/rk3288_crypto_ahash.c
@@ -325,7 +325,7 @@ static int rk_hash_run(struct crypto_engine *engine, void *breq)
 	 * complete.
 	 */
 	err = readl_poll_timeout(rkc->reg + RK_CRYPTO_HASH_STS, v,
-				 v == 0, 10, 1000);
+				 v & RK_CRYPTO_HASH_DONE, 10, 1000);
 	if (err) {
 		dev_err(rkc->dev, "HASH idle timeout\n");
 		goto theend;
-- 
2.47.3


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

* [PATCH 2/2] crypto: rockchip - fix debugfs leak when stats are disabled
  2026-11-28 20:47 [PATCH 0/2] crypto: rockchip - fix hash timeouts and debugfs leak Timur Kussainov
  2026-11-28 20:47 ` [PATCH 1/2] crypto: rockchip - fix inverted hash completion poll Timur Kussainov
@ 2026-11-28 20:47 ` Timur Kussainov
  1 sibling, 0 replies; 3+ messages in thread
From: Timur Kussainov @ 2026-11-28 20:47 UTC (permalink / raw)
  To: Herbert Xu, Corentin Labbe
  Cc: David S . Miller, Heiko Stuebner, linux-crypto, linux-rockchip,
	linux-arm-kernel, linux-kernel, Timur Kussainov

Since commit 1a15d26c3131 ("crypto: rk3288 - Use new crypto_engine_op
interface") register_debugfs() creates /sys/kernel/debug/rk3288_crypto
unconditionally, but the dentry is only stored in rocklist, and only
removed in rk_crypto_remove(), when CONFIG_CRYPTO_DEV_ROCKCHIP_DEBUG is
enabled.

With the option disabled the directory is leaked on module removal.
Reading the stale "stats" file afterwards dereferences the freed module
and oopses, and a re-probe fails to create the directory again.

Create the debugfs entries only when CONFIG_CRYPTO_DEV_ROCKCHIP_DEBUG is
enabled, as the Kconfig help text describes, and remove them
unconditionally (debugfs_remove_recursive() handles NULL).

Fixes: 1a15d26c3131 ("crypto: rk3288 - Use new crypto_engine_op interface")
Signed-off-by: Timur Kussainov <kusainov.timur@gmail.com>
---
 drivers/crypto/rockchip/rk3288_crypto.c | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/drivers/crypto/rockchip/rk3288_crypto.c b/drivers/crypto/rockchip/rk3288_crypto.c
index b2b629fff..b600ef8b0 100644
--- a/drivers/crypto/rockchip/rk3288_crypto.c
+++ b/drivers/crypto/rockchip/rk3288_crypto.c
@@ -235,18 +235,15 @@ DEFINE_SHOW_ATTRIBUTE(rk_crypto_debugfs);
 
 static void register_debugfs(struct rk_crypto_info *crypto_info)
 {
-	struct dentry *dbgfs_dir __maybe_unused;
-	struct dentry *dbgfs_stats __maybe_unused;
+	if (!IS_ENABLED(CONFIG_CRYPTO_DEV_ROCKCHIP_DEBUG))
+		return;
 
 	/* Ignore error of debugfs */
-	dbgfs_dir = debugfs_create_dir("rk3288_crypto", NULL);
-	dbgfs_stats = debugfs_create_file("stats", 0444, dbgfs_dir, &rocklist,
-					  &rk_crypto_debugfs_fops);
-
-#ifdef CONFIG_CRYPTO_DEV_ROCKCHIP_DEBUG
-	rocklist.dbgfs_dir = dbgfs_dir;
-	rocklist.dbgfs_stats = dbgfs_stats;
-#endif
+	rocklist.dbgfs_dir = debugfs_create_dir("rk3288_crypto", NULL);
+	rocklist.dbgfs_stats = debugfs_create_file("stats", 0444,
+						   rocklist.dbgfs_dir,
+						   &rocklist,
+						   &rk_crypto_debugfs_fops);
 }
 
 static int rk_crypto_register(struct rk_crypto_info *crypto_info)
@@ -420,9 +417,7 @@ static void rk_crypto_remove(struct platform_device *pdev)
 	spin_unlock_bh(&rocklist.lock);
 
 	if (!first) {
-#ifdef CONFIG_CRYPTO_DEV_ROCKCHIP_DEBUG
 		debugfs_remove_recursive(rocklist.dbgfs_dir);
-#endif
 		rk_crypto_unregister();
 	}
 	rk_crypto_pm_exit(crypto_tmp);
-- 
2.47.3


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

end of thread, other threads:[~2026-11-28 20:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-28 20:47 [PATCH 0/2] crypto: rockchip - fix hash timeouts and debugfs leak Timur Kussainov
2026-11-28 20:47 ` [PATCH 1/2] crypto: rockchip - fix inverted hash completion poll Timur Kussainov
2026-11-28 20:47 ` [PATCH 2/2] crypto: rockchip - fix debugfs leak when stats are disabled Timur Kussainov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox