Skip to contentSkip to conversation

mctp: fix use after free

PATCH Applied [email protected] 3 participants 3 messages Feb 15, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 mctp: fix use after free

From: Tom Rix <[email protected]>

Clang static analysis reports this problem route.c:425:4: warning: Use of memory after it is freed
trace_mctp_key_acquire(key); ^~~~~~~~~~~~~~~~~~~~~~~~~~~
When mctp_key_add() fails, key is freed but then is later used in trace_mctp_key_acquire(). Add an else statement to use the key only when mctp_key_add() is successful.

Fixes 4f9e1ba6de45 ("mctp: Add tracepoints for tag/key handling")

---
v2: change the Fixes: line

 net/mctp/route.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
net/mctp/route.c +6 -5
index 17e3482aa770..0c4c56e1bd6e 100644
@@ -419,13 +419,14 @@ static int mctp_route_input(struct mctp_route *route, struct sk_buff *skb)
 			 * this function.
 			 */
 			rc = mctp_key_add(key, msk);
-			if (rc)
+			if (rc) {
 				kfree(key);
+			} else {
+				trace_mctp_key_acquire(key);
 
-			trace_mctp_key_acquire(key);
-
-			/* we don't need to release key->lock on exit */
-			mctp_key_unref(key);
+				/* we don't need to release key->lock on exit */
+				mctp_key_unref(key);
+			}
 			key = NULL;
 
 		} else {
Signature · 1 line
2.26.3
maintainer
#1 lore raw

Hi Tom,

Quoted 8 lines

Clang static analysis reports this problem route.c:425:4: warning: Use of memory after it is freed trace_mctp_key_acquire(key); ^~~~~~~~~~~~~~~~~~~~~~~~~~~
When mctp_key_add() fails, key is freed but then is later used in trace_mctp_key_acquire().  Add an else statement to use the key only when mctp_key_add() is successful.

Quoted 4 lines
Fixes 4f9e1ba6de45 ("mctp: Add tracepoints for tag/key handling")

---
v2: change the Fixes: line

Super, thanks!

Cheers,

Jeremy

#2 lore raw
In reply to [email protected]
This patch was applied to netdev/net.git (master) by David S. Miller <[email protected]>:

Hello:

This patch was applied to netdev/net.git (master)
by David S. Miller <[email protected]>:

Quoted 11 lines · On Mon, 14 Feb 2022 18:05:41 -0800 you wrote:

From: Tom Rix <[email protected]>

Clang static analysis reports this problem route.c:425:4: warning: Use of memory after it is freed
trace_mctp_key_acquire(key); ^~~~~~~~~~~~~~~~~~~~~~~~~~~
When mctp_key_add() fails, key is freed but then is later used in trace_mctp_key_acquire(). Add an else statement to use the key only when mctp_key_add() is successful.

[...]

Here is the summary with links:
- [v2] mctp: fix use after free

    https://git.kernel.org/netdev/net/c/7e5b6a5c8c44

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html