Linux cryptographic layer development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Rodolfo Giometti" <giometti@enneenne.com>,
	"David Howells" <dhowells@redhat.com>,
	"Jarkko Sakkinen" <jarkko@kernel.org>,
	keyrings@vger.kernel.org
Cc: "Herbert Xu" <herbert@gondor.apana.org.au>,
	"David S. Miller" <davem@davemloft.net>,
	"Jens Wiklander" <jenswi@kernel.org>,
	"Sumit Garg" <sumit.garg@kernel.org>,
	op-tee@lists.trustedfirmware.org,
	"Horia Geantă" <horia.geanta@nxp.com>,
	"Pankaj Gupta" <pankaj.gupta@nxp.com>,
	"Sahil Malhotra" <sahil.malhotra@nxp.com>,
	"Ahmad Fatoum" <a.fatoum@pengutronix.de>,
	"Richard Weinberger" <richard@nod.at>,
	"Christophe Leroy (CS GROUP)" <chleroy@kernel.org>,
	"Eric Biggers" <ebiggers@kernel.org>,
	"Demi Marie Obenour" <demiobenour@gmail.com>,
	"Arnd Bergmann" <arnd@arndb.de>,
	"Paul Moore" <paul@paul-moore.com>,
	"James Morris" <jmorris@namei.org>,
	"Serge E. Hallyn" <serge@hallyn.com>,
	"Jonathan Corbet" <corbet@lwn.net>,
	"Shuah Khan" <skhan@linuxfoundation.org>,
	"Randy Dunlap" <rdunlap@infradead.org>,
	linux-crypto@vger.kernel.org,
	linux-security-module@vger.kernel.org
Subject: Re: [RFC PATCH 3/9] KEYS: keycrypt: Add the OP-TEE backend
Date: Wed, 18 Nov 2026 14:33:08 +0000	[thread overview]
Message-ID: <sashiko-outbox-221217@kernel.org> (raw)
In-Reply-To: <20261118140421.584086-4-giometti@enneenne.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] keys: keycrypt: NULL dereference in kc_optee_remove() after
  shutdown
--

commit 8da0e0d8cf01260109b52bb935a051203beb3758
Author: Rodolfo Giometti <giometti@enneenne.com>

KEYS: keycrypt: Add the OP-TEE backend

This commit adds the "optee" keycrypt backend driver for the tee tier,
using sessions to the keycrypt OP-TEE Trusted Application to seal, load,
and run operations on keys.

> diff --git a/security/keys/keycrypt/optee.c b/security/keys/keycrypt/optee.c
> new file mode 100644
> index 0000000000000..5a3ab6f825f17
> --- /dev/null
> +++ b/security/keys/keycrypt/optee.c

[ ... ]

> +static void kc_optee_remove(struct tee_client_device *tdev)
> +{
> +	keycrypt_unregister_backend(&keycrypt_optee);
> +	tee_client_close_session(kc_optee.tee, kc_optee.ctl);
> +	tee_shm_free(kc_optee.ctl_shm);
> +	tee_client_close_context(kc_optee.tee);
> +	kc_optee.tee = NULL;
> +}
> +
> +static const struct tee_client_device_id kc_optee_id_table[] = {
> +	{ UUID_INIT(0x65a0d9f0, 0xf057, 0x414c,
> +		    0x9d, 0x5a, 0x9a, 0xac, 0x7c, 0x8b, 0xa4, 0x61) },
> +	{}
> +};
> +MODULE_DEVICE_TABLE(tee, kc_optee_id_table);
> +
> +static struct tee_client_driver kc_optee_driver = {
> +	.probe		= kc_optee_probe,
> +	.remove		= kc_optee_remove,
> +	/* Sessions left open would outlive a kexec in the secure world */
> +	.shutdown	= kc_optee_remove,

[Severity: High]
Can kc_optee_remove() run a second time when .remove is called after
.shutdown?

device_shutdown() invokes .shutdown without unbinding the driver.  On
Arm FF-A OP-TEE platforms, device_shutdown() first calls
tee_client_device_shutdown() -> kc_optee_remove() on the TA child device,
setting kc_optee.tee to NULL, and then reaches the parent FF-A device
whose .shutdown callback (ffa_remove() -> ... ->
optee_unregister_devices()) unregisters the TA device and calls
tee_client_device_remove() -> kc_optee_remove() again.

The second call hits WARN_ON_ONCE(!h) in keycrypt_unregister_backend(),
dereferences NULL kc_optee.tee in tee_client_close_session() and
tee_client_close_context(), and double frees kc_optee.ctl_shm.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261118140421.584086-1-giometti@enneenne.com?part=3

  reply	other threads:[~2026-11-18 14:33 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 14:04 [RFC PATCH 0/9] KEYS: keycrypt: keys that user space can use but never read Rodolfo Giometti
2026-11-18 14:04 ` [RFC PATCH 1/9] KEYS: keycrypt: Add a key type for keys user space never reads Rodolfo Giometti
2026-11-18 14:04 ` [RFC PATCH 2/9] KEYS: keycrypt: Add the sw backend Rodolfo Giometti
2026-11-18 14:04 ` [RFC PATCH 3/9] KEYS: keycrypt: Add the OP-TEE backend Rodolfo Giometti
2026-11-18 14:33   ` sashiko-bot [this message]
2026-11-18 14:07 ` [RFC PATCH 4/9] docs: keycrypt: document keycrypt keys Rodolfo Giometti
2026-11-18 14:08 ` [RFC PATCH 5/9] MAINTAINERS: add KEYS-KEYCRYPT Rodolfo Giometti
2026-11-18 14:09 ` [RFC PATCH 6/9] KEYS: keycrypt: Add the engine tier Rodolfo Giometti
2026-11-18 14:10 ` [RFC PATCH 7/9] crypto: caam - add an internal cbc(paes) taking the blob's key modifier Rodolfo Giometti
2026-11-18 14:11 ` [RFC PATCH 8/9] KEYS: keycrypt: Add the CAAM backend Rodolfo Giometti
2026-11-18 14:12 ` [RFC PATCH 9/9] KEYS: keycrypt: Add the aes256-gcm-stream algorithm Rodolfo Giometti
2026-11-18 14:31 ` [RFC PATCH 0/9] KEYS: keycrypt: keys that user space can use but never read Jarkko Sakkinen
2026-11-18 14:39   ` Jarkko Sakkinen
2026-11-18 14:57 ` Marco Felsch

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=sashiko-outbox-221217@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=a.fatoum@pengutronix.de \
    --cc=arnd@arndb.de \
    --cc=chleroy@kernel.org \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=demiobenour@gmail.com \
    --cc=dhowells@redhat.com \
    --cc=ebiggers@kernel.org \
    --cc=giometti@enneenne.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=horia.geanta@nxp.com \
    --cc=jarkko@kernel.org \
    --cc=jenswi@kernel.org \
    --cc=jmorris@namei.org \
    --cc=keyrings@vger.kernel.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=op-tee@lists.trustedfirmware.org \
    --cc=pankaj.gupta@nxp.com \
    --cc=paul@paul-moore.com \
    --cc=rdunlap@infradead.org \
    --cc=richard@nod.at \
    --cc=sahil.malhotra@nxp.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=serge@hallyn.com \
    --cc=skhan@linuxfoundation.org \
    --cc=sumit.garg@kernel.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