From patchwork Thu Oct 14 08:10:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Johnston X-Patchwork-Id: 12557973 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 07C78C433EF for ; Thu, 14 Oct 2021 08:11:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DF7C4610F9 for ; Thu, 14 Oct 2021 08:11:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230150AbhJNING (ORCPT ); Thu, 14 Oct 2021 04:13:06 -0400 Received: from pi.codeconstruct.com.au ([203.29.241.158]:38650 "EHLO codeconstruct.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230117AbhJNINF (ORCPT ); Thu, 14 Oct 2021 04:13:05 -0400 Received: by codeconstruct.com.au (Postfix, from userid 10001) id 98ACE20223; Thu, 14 Oct 2021 16:10:59 +0800 (AWST) From: Matt Johnston To: netdev@vger.kernel.org Cc: "David S. Miller" , Jakub Kicinski , Jeremy Kerr Subject: [PATCH net-next v2] mctp: Avoid leak of mctp_sk_key Date: Thu, 14 Oct 2021 16:10:50 +0800 Message-Id: <20211014081050.3041204-1-matt@codeconstruct.com.au> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org mctp_key_alloc() returns a key already referenced. The mctp_route_input() path receives a packet for a bind socket and allocates a key. It passes the key to mctp_key_add() which takes a refcount and adds the key to lists. mctp_route_input() should then release its own refcount when setting the key pointer to NULL. In the mctp_alloc_local_tag() path (for mctp_local_output()) we similarly need to unref the key before returning (mctp_reserve_tag() takes a refcount and adds the key to lists). Fixes: 73c618456dc5 ("mctp: locking, lifetime and validity changes for sk_keys") Signed-off-by: Matt Johnston Reviewed-by: Jeremy Kerr --- v2: - "Fixes:" revid was short - Send with correct [net-next] subject - No changes to patch. --- net/mctp/route.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/net/mctp/route.c b/net/mctp/route.c index 04781459b2be..82fb5ae524f6 100644 --- a/net/mctp/route.c +++ b/net/mctp/route.c @@ -372,6 +372,7 @@ static int mctp_route_input(struct mctp_route *route, struct sk_buff *skb) trace_mctp_key_acquire(key); /* we don't need to release key->lock on exit */ + mctp_key_unref(key); key = NULL; } else { @@ -584,6 +585,9 @@ static int mctp_alloc_local_tag(struct mctp_sock *msk, trace_mctp_key_acquire(key); *tagp = key->tag; + /* done with the key in this scope */ + mctp_key_unref(key); + key = NULL; rc = 0; }