Message ID | 20220215020541.2944949-1-trix@redhat.com (mailing list archive) |
---|---|
State | Accepted |
Commit | 7e5b6a5c8c44310784c88c1c198dde79f6402f7b |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | [v2] mctp: fix use after free | expand |
Hi Tom, > 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") > Signed-off-by: Tom Rix <trix@redhat.com> > --- > v2: change the Fixes: line Super, thanks! Acked-off-by: Jeremy Kerr <jk@codeconstruct.com.au> Cheers, Jeremy
Hello: This patch was applied to netdev/net.git (master) by David S. Miller <davem@davemloft.net>: On Mon, 14 Feb 2022 18:05:41 -0800 you wrote: > From: Tom Rix <trix@redhat.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. > > [...] 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!
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 {