From: Kim Phillips <kim.phillips@amd.com>
To: Tom Lendacky <thomas.lendacky@amd.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
"David S . Miller" <davem@davemloft.net>
Cc: Ashish Kalra <ashish.kalra@amd.com>,
Rijo Thomas <Rijo-john.Thomas@amd.com>,
Mario Limonciello <mario.limonciello@amd.com>,
<linux-crypto@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<stable@vger.kernel.org>, Kim Phillips <kim.phillips@amd.com>,
Sashiko <sashiko-bot@kernel.org>
Subject: [PATCH 1/2] crypto: ccp - fix leak and stale misc_dev on SFS misc_register() failure
Date: Tue, 17 Nov 2026 16:19:00 -0600 [thread overview]
Message-ID: <20261117221901.746427-2-kim.phillips@amd.com> (raw)
In-Reply-To: <20261117221901.746427-1-kim.phillips@amd.com>
sfs_misc_init() assigns the newly allocated structure to the global
misc_dev before registering the misc device, but returns early when
misc_register() fails, without freeing the allocation or clearing the
global pointer. The early return also skips kref_init(), so the
embedded refcount stays at the zero left by kzalloc_obj().
SFS support can be detected on multiple PSP devices, and the failure
only aborts the probe of the device that hit it. When a subsequent
device probes, sfs_misc_init() observes the stale non-NULL misc_dev and
takes the else branch, calling kref_get() on the zeroed refcount. That
triggers a "refcount_t: addition on 0; use-after-free" warning and
leaves the count at zero, so the matching kref_put() in
sfs_dev_destroy() warns too and never reaches sfs_exit(). The device
goes on to report that SFS support is available even though /dev/sfs was
never created, and the original allocation is leaked.
Free the allocation and reset misc_dev to NULL on the misc_register()
error path.
Fixes: 648dbccc03a0 ("crypto: ccp - Add AMD Seamless Firmware Servicing (SFS) driver")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/bug/linux-126662e0-70a1-4086-a5d1-2f1e15a14f20
Cc: Ashish Kalra <ashish.kalra@amd.com>
Cc: Rijo Thomas <Rijo-john.Thomas@amd.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Cc: Mario Limonciello <mario.limonciello@amd.com>
Cc: stable@vger.kernel.org
Signed-off-by: Kim Phillips <kim.phillips@amd.com>
---
drivers/crypto/ccp/sfs.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/crypto/ccp/sfs.c b/drivers/crypto/ccp/sfs.c
index 530141f8bc74..01b16e318fc7 100644
--- a/drivers/crypto/ccp/sfs.c
+++ b/drivers/crypto/ccp/sfs.c
@@ -237,8 +237,11 @@ static int sfs_misc_init(struct sfs_device *sfs)
misc->mode = 0600;
ret = misc_register(misc);
- if (ret)
+ if (ret) {
+ kfree(misc_dev);
+ misc_dev = NULL;
return ret;
+ }
kref_init(&misc_dev->refcount);
} else {
--
2.43.0
next prev parent reply other threads:[~2026-11-17 22:19 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 22:18 [PATCH 0/2] crypto: ccp - fix misc_register() failure paths in SEV and SFS Kim Phillips
2026-11-17 22:19 ` Kim Phillips [this message]
2026-11-17 22:19 ` [PATCH 2/2] crypto: ccp - fix leak and stale misc_dev on SEV misc_register() failure Kim Phillips
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=20261117221901.746427-2-kim.phillips@amd.com \
--to=kim.phillips@amd.com \
--cc=Rijo-john.Thomas@amd.com \
--cc=ashish.kalra@amd.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mario.limonciello@amd.com \
--cc=sashiko-bot@kernel.org \
--cc=stable@vger.kernel.org \
--cc=thomas.lendacky@amd.com \
/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