Skip to contentSkip to conversation

firmware: imx: secure-enclave: fix list UAF in init_device_context()

PATCH Applied Pankaj Gupta 2 participants 2 messages May 8 Arm i.MX and Layerscape

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 firmware: imx: secure-enclave: fix list UAF in init_device_context()

init_device_context() added a new device context to priv->dev_ctx_list before calling init_se_shared_mem(). If initialization failed, the device context was freed without being removed from the list, leaving behind a dangling list entry.

Move the list insertion until after all fallible initialization has completed successfully.

Fixes 4de71839142b ("firmware: drivers: imx: adds miscdev")
---
 drivers/firmware/imx/se_ctrl.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/firmware/imx/se_ctrl.c +3 -3
index 3a1e0c6a942b..814a1946d1c2 100644
@@ -481,9 +481,6 @@ static int init_device_context(struct se_if_priv *priv, int ch_id,
 	dev_ctx->priv = priv;
 	*new_dev_ctx = dev_ctx;
 
-	list_add_tail(&dev_ctx->link, &priv->dev_ctx_list);
-	priv->active_devctx_count++;
-
 	ret = init_se_shared_mem(dev_ctx);
 	if (ret < 0) {
 		kfree(dev_ctx->devname);
@@ -491,6 +488,9 @@ static int init_device_context(struct se_if_priv *priv, int ch_id,
 		*new_dev_ctx = NULL;
 	}
 
+	list_add_tail(&dev_ctx->link, &priv->dev_ctx_list);
+	priv->active_devctx_count++;
+
 	return ret;
 }
 
Signature · 1 line
2.43.0
maintainer Applied
#1 lore raw
Quoted 9 lines · Pankaj Gupta

init_device_context() added a new device context to priv->dev_ctx_list before calling init_se_shared_mem(). If initialization failed, the device context was freed without being removed from the list, leaving behind a dangling list entry.

Move the list insertion until after all fallible initialization has completed successfully.

[...]

Applied, thanks!

[1/1] firmware: imx: secure-enclave: fix list UAF in init_device_context()

      commit: 66f3c3f91c48238dd13543cd428879b9184c80f4

Best regards,

Signature · 1 line
Frank Li <[email protected]>