| Message ID | 20260808085337.2715506-1-lgs201920130244@gmail.com (mailing list archive) |
|---|---|
| State | New |
| Headers |
Return-Path: <linux-sunxi+bounces-25070-sunxi=pue.re@lists.linux.dev>
X-Original-To: noreply@patchwork.local
Delivered-To: noreply@patchwork.local
Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
by mxe881.netcup.net (Postfix) with ESMTPS id 4268F1C1486
for <noreply@patchwork.local>; Sat, 8 Aug 2026 10:59:45 +0200 (CEST)
Authentication-Results: mxe881;
dkim=pass header.d=gmail.com;
spf=pass (sender IP is 104.64.211.4)
smtp.mailfrom=linux-sunxi+bounces-25070-noreply=patchwork.local@lists.linux.dev
smtp.helo=sin.lore.kernel.org
Received-SPF: pass (mxe881: domain of lists.linux.dev designates 104.64.211.4
as permitted sender) client-ip=104.64.211.4;
envelope-from=linux-sunxi+bounces-25070-noreply=patchwork.local@lists.linux.dev;
helo=sin.lore.kernel.org;
Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org
[100.90.174.1])
by sin.lore.kernel.org (Postfix) with ESMTP id 2446A3001184
for <noreply@patchwork.local>; Sat, 8 Aug 2026 08:59:40 +0000 (UTC)
Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 8E5A337AA9C;
Sat, 8 Aug 2026 08:59:36 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com
header.b="TVZg8/P2"
X-Original-To: linux-sunxi@lists.linux.dev
Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com
[209.85.214.175])
(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4233130C14C
for <linux-sunxi@lists.linux.dev>; Sat, 8 Aug 2026 08:59:34 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org;
arc=none smtp.client-ip=209.85.214.175
ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
t=1786179576; cv=none;
b=RdBwyHy85nGtXVcUQwTmUsy5RGf4SjKEmWqJvIt4gilt8REa/EzJdNPa4dpHYSzMo6OarXc7L0+D/MkoUsS998QQskfTzuXmXqEoY7ncDvuJYlN0CfebdLOlSrPuSaslo3gqNJOdBuFT4k9A8UWl2R073+yVf7dRcOl48xQqu+k=
ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org;
s=arc-20240116; t=1786179576; c=relaxed/simple;
bh=k1jte4S6kmlNkWiF/TPSrh2PJp0JqoJa7csBL3XZxhw=;
h=From:To:Cc:Subject:Date:Message-ID:MIME-Version;
b=FYs87s8uvKd8/Oz0qHQ4BDBFVcwoCbAlgXMFfcssuF828ewhaFXQnYmuJQBgEGPQ6UxoCEFkgwN2IrdoLotmu8CBLvnwTUZgyeDLgfrnv6rbCpGaQjD51xHWB2gl+zYFiqVfo1WvUtE/miWZ7V5LiEtW9KE2yWCAEvMJT3aeyf0=
ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass (p=none dis=none) header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com
header.b=TVZg8/P2; arc=none smtp.client-ip=209.85.214.175
Authentication-Results: smtp.subspace.kernel.org;
dmarc=pass (p=none dis=none) header.from=gmail.com
Authentication-Results: smtp.subspace.kernel.org;
spf=pass smtp.mailfrom=gmail.com
Received: by mail-pl1-f175.google.com with SMTP id
d9443c01a7336-2cacf197759so6219005ad.2
for <linux-sunxi@lists.linux.dev>;
Sat, 08 Aug 2026 01:59:34 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20251104; t=1786179574; x=1786784374;
darn=lists.linux.dev;
h=content-transfer-encoding:mime-version:message-id:date:subject:cc
:to:from:from:to:cc:subject:date:message-id:reply-to:content-type;
bh=n/y7c/4lG8eevhNAw7vtPbWQQOLv7HTFTCbAr3jVwm4=;
b=TVZg8/P2cVuH+6qHFjSl2qTSGGuh5uLnv+5eB/OM5hdkb5Yea7ktO5sQa2KIyI0Wlv
dewqyz1lhAK3D6VpjAHwN2MM18oqeGCXa2j8Wl79J1GgBqJH69wOHmjp9sLlSyXcoIN4
gNqyo3dXIB24IA6yFbBn4mmqLE3yeXb3n77xXKZxmsKkcWHL2s+hKagwHUb/1ogBrurk
OLL2e2/u9xcoCkBSR53cIQpHZC5CNTXeyUPQIwoOGkMQTRFaNZrJZVCvTD50Trp5JEZK
bg0eh/MDJXRqLfAabHI/LCtPlnY8WZ5LiEhh7ihUkLzEfNqPl4gAaslCypb0IX+5TZnt
V5qA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20251104; t=1786179574; x=1786784374;
h=content-transfer-encoding:mime-version:message-id:date:subject:cc
:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date
:message-id:reply-to:content-type;
bh=n/y7c/4lG8eevhNAw7vtPbWQQOLv7HTFTCbAr3jVwm4=;
b=Yzfo492XOZFQ89jgF4EDvFvajZUkRAh3ql0s/RqJgzKuiEIE7oOkOhQ5RHcIg4sAhA
aAPGgcTuplwmGclINkHCG3Ede/Xb9RsPnRmlBxcLvaKrXNvXSJM5Jlx39/BwSpCybQ0N
ow4R5e2X8CAT7q7YoMF0c/i5R/560ki5+WdXJirmjqMcEeZmw4IkLei8mZiRAAdWBHA3
/u5wsNvOpsoi3k/CJqmV6dkFk6RV+DQAhJVaOAP8QPE7B55bDUYxljt1gq6FEQOCj1M+
eX2FQi/IgkqdX98glc0SP9P0ardrDQsHWKxeYJ7C4+DC009Uves+cFO0gHurN6GoAJQ/
vjSw==
X-Forwarded-Encrypted: i=1;
AHgh+RpY+ADI75JqM99ZZKarSNNXc/BMIE/y5rElL+M2Qz7MNbqoGu6Js4YPBQYfeHlxTemwlUcUiM3nnxgEQg==@lists.linux.dev
X-Gm-Message-State: AOJu0Yx/Hxnnm4I4Hgu7gulMJeBgWzYU5r14kShffJnijbfY7cSas6Yo
V4wbi6LLJ1wEmV+z4TcqAq3HocdESnz5+7U5G5DCPDvrG70fhRqOyjzT
X-Gm-Gg: AR+sD12A/U5QDY+gb2kS4vbAPkI5RvxRSNbkV7IdUO/ZNWOGlkMMhvKPWWb42lql6sT
JAXvvYs6zvrEIMBnQZ97gzMEVfFXdeoQ1XtDj1K9amQo4WDu8Um26+pKwpcXTP7NlUDdOuUN2TP
mBlmjy0jR2z27JThBqc8UpTPPBdHKhSANnobuW00lKCMfONPw6MRXUMWQt93fvy2mJWRrUW5RwW
U0II7yvNuhflkdFxhdgsyz+XTlEaJCEcChRN+/6tJDt+RiZf6YheycStTyGal0/XJZTnea9jsF6
NgH4cUProyj+lMfszC6iH5zp7k9GVZlWkm5DumeTzOXC8r9I7p/BM8gUHaPPimyzUkWkalKI3Dl
L+5a5Xl+KQeMwNMwdZH8zc4R5GYSRGcB8fgGbBb6V2t4o2I/dXWbUsNcGmTXSZMS7Sw/CgyEX2G
kOEgSOtVNqN1EAmvYqfflsds+QIqgfIpFHrIdiFCA9F1k=
X-Received: by 2002:a17:903:37cd:b0:2ca:d9b3:715e with SMTP id
d9443c01a7336-2d294b4b5b1mr126407935ad.9.1786179574331;
Sat, 08 Aug 2026 01:59:34 -0700 (PDT)
Received: from lgs.. ([2001:250:5800:1000::f280])
by smtp.gmail.com with ESMTPSA id
d9443c01a7336-2d16c4a6db2sm17431155ad.64.2026.08.08.01.59.29
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Sat, 08 Aug 2026 01:59:33 -0700 (PDT)
From: Guangshuo Li <lgs201920130244@gmail.com>
To: Corentin Labbe <clabbe.montjoie@gmail.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>,
Chen-Yu Tsai <wens@kernel.org>,
Jernej Skrabec <jernej.skrabec@gmail.com>,
Samuel Holland <samuel@sholland.org>,
Eric Biggers <ebiggers@kernel.org>,
Guangshuo Li <lgs201920130244@gmail.com>,
Arnd Bergmann <arnd@arndb.de>,
Maxime Ripard <mripard@kernel.org>,
linux-crypto@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-sunxi@lists.linux.dev,
linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Subject: [PATCH] crypto: sun4i-ss: fix autosuspend cleanup during teardown
Date: Sat, 8 Aug 2026 16:53:37 +0800
Message-ID: <20260808085337.2715506-1-lgs201920130244@gmail.com>
X-Mailer: git-send-email 2.43.0
Precedence: bulk
X-Mailing-List: linux-sunxi@lists.linux.dev
List-Id: <linux-sunxi.lists.linux.dev>
List-Subscribe: <mailto:linux-sunxi+subscribe@lists.linux.dev>
List-Unsubscribe: <mailto:linux-sunxi+unsubscribe@lists.linux.dev>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Rspamd-Server: rspamd-worker-8404
X-Spamd-Result: default: False [0.34 / 15.00];
BAYES_HAM(-5.50)[100.00%];
RBL_SENDERSCORE(2.00)[104.64.211.4:from];
SUSPICIOUS_RECIPS(1.50)[];
MID_CONTAINS_FROM(1.00)[];
DMARC_POLICY_SOFTFAIL(1.00)[gmail.com : SPF not aligned (relaxed),
No valid DKIM,none];
R_MISSING_CHARSET(0.50)[];
MAILLIST(-0.15)[generic];
BAD_REP_POLICIES(0.10)[];
MIME_GOOD(-0.10)[text/plain];
HAS_LIST_UNSUB(-0.01)[];
FROM_HAS_DN(0.00)[];
FORGED_SENDER_MAILLIST(0.00)[];
PRECEDENCE_BULK(0.00)[];
DBL_BLOCKED_OPENRESOLVER(0.00)[sin.lore.kernel.org:rdns,sin.lore.kernel.org:helo];
TAGGED_RCPT(0.00)[];
RCPT_COUNT_TWELVE(0.00)[15];
RCVD_COUNT_FIVE(0.00)[6];
TAGGED_FROM(0.00)[bounces-25070-noreply=patchwork.local];
R_SPF_ALLOW(0.00)[+ip4:104.64.211.4];
FREEMAIL_TO(0.00)[gmail.com,gondor.apana.org.au,davemloft.net,kernel.org,sholland.org,arndb.de,vger.kernel.org,lists.infradead.org,lists.linux.dev];
FREEMAIL_FROM(0.00)[gmail.com];
TO_DN_SOME(0.00)[];
FROM_NEQ_ENVFROM(0.00)[lgs201920130244@gmail.com,linux-sunxi@lists.linux.dev];
FORGED_RECIPIENTS_MAILLIST(0.00)[];
RCVD_TLS_LAST(0.00)[];
MIME_TRACE(0.00)[0:+];
ASN(0.00)[asn:63949, ipnet:104.64.192.0/19, country:SG];
ARC_ALLOW(0.00)[subspace.kernel.org:s=arc-20240116:i=1];
RCVD_VIA_SMTP_AUTH(0.00)[]
X-Rspamd-Queue-Id: 4268F1C1486
X-MORS-Enabled: yes
X-MORS-DOMAIN: patchwork.local
X-MORS-HOSTING: hosting172546
X-MORS-USER: hosting172546
X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?=
|
| Series |
crypto: sun4i-ss: fix autosuspend cleanup during teardown
|
|
Commit Message
Guangshuo Li
Aug. 8, 2026, 8:53 a.m. UTC
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.
This issue was found by manual code inspection.
Fixes: 554c42b4efd4 ("crypto: sun4i-ss - enable pm_runtime")
Cc: stable@vger.kernel.org
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
---
drivers/crypto/allwinner/sun4i-ss/sun4i-ss-core.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
Comments
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
diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-core.c b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-core.c index 35ef0930e77f..10c0f05994ed 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); }