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.