Linux cryptographic layer development
 help / color / mirror / Atom feed
From: Timur Kussainov <kusainov.timur@gmail.com>
To: Herbert Xu <herbert@gondor.apana.org.au>,
	Corentin Labbe <clabbe@baylibre.com>
Cc: "David S . Miller" <davem@davemloft.net>,
	Heiko Stuebner <heiko@sntech.de>,
	linux-crypto@vger.kernel.org, linux-rockchip@lists.infradead.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org,
	Timur Kussainov <kusainov.timur@gmail.com>
Subject: [PATCH 2/2] crypto: rockchip - fix debugfs leak when stats are disabled
Date: Sat, 28 Nov 2026 15:47:45 -0500	[thread overview]
Message-ID: <20261128204745.1044083-3-kusainov.timur@gmail.com> (raw)
In-Reply-To: <20261128204745.1044083-1-kusainov.timur@gmail.com>

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


      parent reply	other threads:[~2026-11-28 20:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]

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=20261128204745.1044083-3-kusainov.timur@gmail.com \
    --to=kusainov.timur@gmail.com \
    --cc=clabbe@baylibre.com \
    --cc=davem@davemloft.net \
    --cc=heiko@sntech.de \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    /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