Skip to contentSkip to conversation

remoteproc: core: Fix rproc->firmware free in rproc_set_firmware()

PATCH Applied Daniele Alessandrelli 3 participants 4 messages Jan 18, 2021 – Feb 9, 2021 Remote processor (remoteproc)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 remoteproc: core: Fix rproc->firmware free in rproc_set_firmware()

From: Daniele Alessandrelli <[email protected]>

rproc_alloc_firmware() (called by rproc_alloc()) can allocate rproc->firmware using kstrdup_const() and therefore should be freed using kfree_const(); however, rproc_set_firmware() frees it using the simple kfree(). This causes a kernel oops if a constant string is passed to rproc_alloc() and rproc_set_firmware() is subsequently called.

Fix the above issue by using kfree_const() to free rproc->firmware in rproc_set_firmware().

---
 drivers/remoteproc/remoteproc_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/remoteproc/remoteproc_core.c +1 -1
index 2394eef383e3..ab150765d124 100644
@@ -1988,7 +1988,7 @@ int rproc_set_firmware(struct rproc *rproc, const char *fw_name)
 		goto out;
 	}
 
-	kfree(rproc->firmware);
+	kfree_const(rproc->firmware);
 	rproc->firmware = p;
 
 out:

base-commit: 8cc8eeffd058f3e7e2d8710a514ffcbc2bd69d28

Signature · 1 line
2.26.2
maintainer
#1 lore raw

Good morning,

Quoted 21 lines · Daniele Alessandrelli

From: Daniele Alessandrelli <[email protected]>

rproc_alloc_firmware() (called by rproc_alloc()) can allocate rproc->firmware using kstrdup_const() and therefore should be freed using kfree_const(); however, rproc_set_firmware() frees it using the simple kfree(). This causes a kernel oops if a constant string is passed to rproc_alloc() and rproc_set_firmware() is subsequently called.

Fix the above issue by using kfree_const() to free rproc->firmware in rproc_set_firmware().

---
 drivers/remoteproc/remoteproc_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/remoteproc/remoteproc_core.c +0 -0
index 2394eef383e3..ab150765d124 100644

drivers/remoteproc/remoteproc_core.c int rproc_set_firmware(struct rproc *rproc, const char *fw_name) · line 1992

Quoted 6 lines
drivers/remoteproc/remoteproc_core.c +1 -1
@@ -1988,7 +1988,7 @@ int rproc_set_firmware(struct rproc *rproc, const char *fw_name)
 		goto out;
 	}
 
-	kfree(rproc->firmware);
+	kfree_const(rproc->firmware);
 	rproc->firmware = p;

Thanks for the fix, I will pick it up shortly.

Mathieu

Quoted 7 lines
drivers/remoteproc/remoteproc_core.c +0 -0
 out:
 

base-commit: 8cc8eeffd058f3e7e2d8710a514ffcbc2bd69d28

Signature · 1 line
2.26.2
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Daniele Alessandrelli
Quoted 21 lines · Daniele Alessandrelli

From: Daniele Alessandrelli <[email protected]>

rproc_alloc_firmware() (called by rproc_alloc()) can allocate rproc->firmware using kstrdup_const() and therefore should be freed using kfree_const(); however, rproc_set_firmware() frees it using the simple kfree(). This causes a kernel oops if a constant string is passed to rproc_alloc() and rproc_set_firmware() is subsequently called.

Fix the above issue by using kfree_const() to free rproc->firmware in rproc_set_firmware().

---
 drivers/remoteproc/remoteproc_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/remoteproc/remoteproc_core.c +0 -0
index 2394eef383e3..ab150765d124 100644

drivers/remoteproc/remoteproc_core.c int rproc_set_firmware(struct rproc *rproc, const char *fw_name) · line 1992

Quoted 6 lines
drivers/remoteproc/remoteproc_core.c +1 -1
@@ -1988,7 +1988,7 @@ int rproc_set_firmware(struct rproc *rproc, const char *fw_name)
 		goto out;
 	}
 
-	kfree(rproc->firmware);
+	kfree_const(rproc->firmware);
 	rproc->firmware = p;
Quoted 7 lines
drivers/remoteproc/remoteproc_core.c +0 -0
 out:
 

base-commit: 8cc8eeffd058f3e7e2d8710a514ffcbc2bd69d28

Signature · 1 line
2.26.2
#3 lore raw
In reply to Daniele Alessandrelli
This patch was applied to andersson/remoteproc.git (refs/heads/for-next):

Hello:

This patch was applied to andersson/remoteproc.git (refs/heads/for-next):

Quoted 9 lines · On Mon, 18 Jan 2021 16:59:04 +0000 you wrote:

From: Daniele Alessandrelli <[email protected]>

rproc_alloc_firmware() (called by rproc_alloc()) can allocate rproc->firmware using kstrdup_const() and therefore should be freed using kfree_const(); however, rproc_set_firmware() frees it using the simple kfree(). This causes a kernel oops if a constant string is passed to rproc_alloc() and rproc_set_firmware() is subsequently called.

[...]

Here is the summary with links:
- remoteproc: core: Fix rproc->firmware free in rproc_set_firmware()

    https://git.kernel.org/andersson/remoteproc/c/43d3f2c715ce

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html