Skip to content

Commit

Permalink
mctp: fix use after free
Browse files Browse the repository at this point in the history
commit 7e5b6a5 upstream.

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: 4f9e1ba ("mctp: Add tracepoints for tag/key handling")
Signed-off-by: Tom Rix <trix@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
trixirt authored and gregkh committed Feb 23, 2022
1 parent ea1f85f commit 1dd3ecb
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions net/mctp/route.c
Expand Up @@ -414,13 +414,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 {
Expand Down

0 comments on commit 1dd3ecb

Please sign in to comment.