]> git.dujemihanovic.xyz Git - linux.git/commitdiff
net: mctp: put sock on tag allocation failure
authorJeremy Kerr <jk@codeconstruct.com.au>
Thu, 15 Feb 2024 07:53:08 +0000 (15:53 +0800)
committerJakub Kicinski <kuba@kernel.org>
Thu, 22 Feb 2024 01:01:54 +0000 (17:01 -0800)
We may hold an extra reference on a socket if a tag allocation fails: we
optimistically allocate the sk_key, and take a ref there, but do not
drop if we end up not using the allocated key.

Ensure we're dropping the sock on this failure by doing a proper unref
rather than directly kfree()ing.

Fixes: de8a6b15d965 ("net: mctp: add an explicit reference from a mctp_sk_key to sock")
Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://lore.kernel.org/r/ce9b61e44d1cdae7797be0c5e3141baf582d23a0.1707983487.git.jk@codeconstruct.com.au
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/mctp/route.c

index 7a47a58aa54b446acf7451ba6bdc1b834adda327..6218dcd07e184e5ed2741d556399a95830cd2d14 100644 (file)
@@ -663,7 +663,7 @@ struct mctp_sk_key *mctp_alloc_local_tag(struct mctp_sock *msk,
        spin_unlock_irqrestore(&mns->keys_lock, flags);
 
        if (!tagbits) {
-               kfree(key);
+               mctp_key_unref(key);
                return ERR_PTR(-EBUSY);
        }