[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220214175138.2902947-1-trix@redhat.com>
Date: Mon, 14 Feb 2022 09:51:38 -0800
From: trix@...hat.com
To: jk@...econstruct.com.au, matt@...econstruct.com.au,
davem@...emloft.net, kuba@...nel.org, nathan@...nel.org,
ndesaulniers@...gle.com
Cc: netdev@...r.kernel.org, linux-kernel@...r.kernel.org,
llvm@...ts.linux.dev, Tom Rix <trix@...hat.com>
Subject: [PATCH] mctp: fix use after free
From: Tom Rix <trix@...hat.com>
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: 4a992bbd3650 ("mctp: Implement message fragmentation & reassembly")
Signed-off-by: Tom Rix <trix@...hat.com>
---
net/mctp/route.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/net/mctp/route.c b/net/mctp/route.c
index 17e3482aa770..0c4c56e1bd6e 100644
--- a/net/mctp/route.c
+++ b/net/mctp/route.c
@@ -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 {
--
2.26.3
Powered by blists - more mailing lists