All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Guangshuo Li" <lgs201920130244@gmail.com>
Cc: linux-sunxi@lists.linux.dev
Subject: Re: [PATCH] crypto: sun4i-ss: fix autosuspend cleanup during teardown
Date: Sat, 08 Aug 2026 09:11:46 +0000	[thread overview]
Message-ID: <20260808091146.C52F81F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260808085337.2715506-1-lgs201920130244@gmail.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

Pre-existing issues:
- [High] Unbalanced clock cleanup in the runtime PM resume error path
- [High] Memory leak and Use-After-Free of debugfs entries during device removal
- [High] Use-After-Free of device context when unbinding the device via sysfs with active TFMs
--

--- Patch [1]: [PATCH] crypto: sun4i-ss: fix autosuspend cleanup during teardown ---
commit 498a2e7e81cded38e9654e9d63d7f5c6261e2d92
Author: Guangshuo Li <lgs201920130244@gmail.com>

crypto: sun4i-ss: fix autosuspend cleanup during teardown

sun4i_ss_pm_init() calls pm_runtime_use_autosuspend(), but the
autosuspend setting is not undone if pm_runtime_set_suspended() fails
or when runtime PM is later torn down by sun4i_ss_pm_exit().

If the autosuspend delay is set to a negative value while autosuspend
is enabled, the runtime PM core increments usage_count to prevent
runtime suspend. Without calling pm_runtime_dont_use_autosuspend()
during cleanup, this reference is not dropped and usage_count remains
unbalanced.

Undo the autosuspend setting when pm_runtime_set_suspended() fails and
in sun4i_ss_pm_exit() before disabling runtime PM.

Fixes: 554c42b4efd4 ("crypto: sun4i-ss - enable pm_runtime")
Cc: stable@vger.kernel.org

> diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-core.c b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-core.c
> index 35ef0930e77f1..10c0f05994ed8 100644
> --- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-core.c
> +++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-core.c
> @@ -304,14 +304,17 @@ static int sun4i_ss_pm_init(struct sun4i_ss_ctx *ss)
>  	pm_runtime_set_autosuspend_delay(ss->dev, 2000);
>  
>  	err = pm_runtime_set_suspended(ss->dev);
> -	if (err)
> +	if (err) {
> +		pm_runtime_dont_use_autosuspend(ss->dev);
>  		return err;
> +	}
>  	pm_runtime_enable(ss->dev);
>  	return err;
>  }
>  
>  static void sun4i_ss_pm_exit(struct sun4i_ss_ctx *ss)
>  {
> +	pm_runtime_dont_use_autosuspend(ss->dev);
>  	pm_runtime_disable(ss->dev);
>  }

[Severity: High]
This is a pre-existing issue, but does the error path in sun4i_ss_pm_resume()
corrupt the clock framework's reference counting?

If clk_prepare_enable(ss->busclk) fails, the code jumps to err_enable:

err_enable:
    sun4i_ss_pm_suspend(dev);
    return err;

sun4i_ss_pm_suspend() then unconditionally disables both clocks:

    clk_disable_unprepare(ss->ssclk);
    clk_disable_unprepare(ss->busclk);

Since busclk failed to enable and ssclk wasn't attempted yet, does calling
clk_disable_unprepare() on them drop the prepare_count and enable_count below
zero?

[Severity: High]
This isn't a bug introduced by this patch, but does the driver leak debugfs
entries during device removal?

In sun4i_ss_probe(), the debugfs entries are created:

    ss->dbgfs_dir = debugfs_create_dir("sun4i-ss", NULL);
    ss->dbgfs_stats = debugfs_create_file("stats", 0444, ss->dbgfs_dir, ss,
                                          &sun4i_ss_debugfs_fops);

The device removal path in sun4i_ss_remove() lacks a corresponding
debugfs_remove_recursive() call.

Could this leak the debugfs dentries, and potentially lead to a use-after-free
if a user reads the leaked stats file after devres has freed the ss context?

[Severity: High]
This is a pre-existing issue, but is there a use-after-free risk when unbinding
the device with active TFMs?

In sun4i_ss_remove(), algorithms are unregistered:

    crypto_unregister_skcipher(&ss_algs[i].alg.crypto);

This merely removes the algorithms from the active list without waiting for
active TFMs to close. Since the context is managed by devm_kzalloc, devres
will free it immediately after remove completes.

If an unprivileged user keeps a TFM open, could callbacks like
sun4i_ss_cipher_poll() access freed memory when dereferencing op->ss?

sun4i_ss_cipher_poll()
    struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq);
    struct sun4i_tfm_ctx *op = crypto_skcipher_ctx(tfm);
    // op->ss is accessed here

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260808085337.2715506-1-lgs201920130244@gmail.com?part=1

      reply	other threads:[~2026-08-08  9:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-08  8:53 [PATCH] crypto: sun4i-ss: fix autosuspend cleanup during teardown Guangshuo Li
2026-08-08  9:11 ` sashiko-bot [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=20260808091146.C52F81F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=lgs201920130244@gmail.com \
    --cc=linux-sunxi@lists.linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.