crypto: rockchip - fix hash timeouts and debugfs leak
Subsystems (4)
cover crypto: rockchip - fix hash timeouts and debugfs leak
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(-)
Signature · 1 line
2.47.3
PATCH 1/2 crypto: rockchip - fix inverted hash completion poll
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.
--- drivers/crypto/rockchip/rk3288_crypto_ahash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/rockchip/rk3288_crypto_ahash.c +1 -1
@@ -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;
Signature · 1 line
2.47.3
PATCH 2/2 crypto: rockchip - fix debugfs leak when stats are disabled
In reply to Timur KussainovSince 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).
--- drivers/crypto/rockchip/rk3288_crypto.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-)
drivers/crypto/rockchip/rk3288_crypto.c +7 -12
@@ -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);
Signature · 1 line
2.47.3