Linux cryptographic layer development
 help / color / mirror / Atom feed
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>
Subject: [PATCH 0/2] crypto: ccp - fix misc_register() failure paths in SEV and SFS
Date: Tue, 17 Nov 2026 16:18:59 -0600	[thread overview]
Message-ID: <20261117221901.746427-1-kim.phillips@amd.com> (raw)

sev_misc_init() and sfs_misc_init() both publish their newly allocated
sev_misc_dev/sfs_misc_dev to a file-global pointer before registering
the misc device, then return early if misc_register() fails.  Neither
frees the allocation nor clears the global, and the early return is
ahead of the kref_init(), so the embedded refcount is left at the zero
from kzalloc_obj().

Both features can be detected on more than one device, and a failure
here only aborts the probe of the device that hit it.  The next device
to probe therefore sees a stale non-NULL global, takes the else branch,
and calls kref_get() on a zeroed refcount:

  refcount_t: addition on 0; use-after-free.

The count stays at zero, so the matching kref_put() on teardown warns in
the same way and never reaches sev_exit()/sfs_exit().  What is left is a
leaked allocation plus a device whose ->misc points at a miscdevice that
was never registered, while the driver still reports the feature as
available and no /dev/sev or /dev/sfs node exists.

Both patches free the allocation and reset the global on the
misc_register() error path.

Note the differing Fixes: tags.  The SEV stale-pointer half goes back to
the original SEV support commit, but the allocation was devm_kzalloc()
then, so backporting the kfree() that far would turn the leak into a
double free; the tag points at the commit from which the fix is safe.

Found by review of the equivalent bug reports; no hardware failure was
observed, as misc_register() only fails here on minor exhaustion or an
OOM.  Compile-tested on x86_64 with CONFIG_CRYPTO_DEV_SP_PSP=y.

The two patches are independent of each other, and of the pending

  https://lore.kernel.org/linux-crypto/20261116203622.615371-1-kim.phillips@amd.com/

which touches psp-dev.c only.  This series applies on top of it, but
also applies cleanly to cryptodev master without it.

Kim Phillips (2):
  crypto: ccp - fix leak and stale misc_dev on SFS misc_register()
    failure
  crypto: ccp - fix leak and stale misc_dev on SEV misc_register()
    failure

 drivers/crypto/ccp/sev-dev.c | 5 ++++-
 drivers/crypto/ccp/sfs.c     | 5 ++++-
 2 files changed, 8 insertions(+), 2 deletions(-)


base-commit: 26ca5f34841f0a86d0883664a1c13be89a01d351
-- 
2.43.0


             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 Kim Phillips [this message]
2026-11-17 22:19 ` [PATCH 1/2] crypto: ccp - fix leak and stale misc_dev on SFS misc_register() failure Kim Phillips
2026-11-17 22:19 ` [PATCH 2/2] crypto: ccp - fix leak and stale misc_dev on SEV " 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-1-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=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