Skip to content

Commit

Permalink
mctp: fix use after free
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Tom Rix authored and davem330 committed Feb 15, 2022
1 parent ef57640 commit 7e5b6a5
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions net/mctp/route.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,13 +412,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 7e5b6a5

Please sign in to comment.