Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp4119115pxb; Mon, 21 Feb 2022 12:36:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJz/maRBv4SWubtUEVuqxot6kb/2XjPb5PQXAeYOSFzwWMli+tL48w0hrjZFaNAWNSWpONjo X-Received: by 2002:a17:906:af68:b0:6cd:7896:15e with SMTP id os8-20020a170906af6800b006cd7896015emr17180230ejb.420.1645475773321; Mon, 21 Feb 2022 12:36:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645475773; cv=none; d=google.com; s=arc-20160816; b=Vg5bKexpnn0rAkEr7sfbEzyZXMvs1TnGEBooum1xo8z92+DXaAxDvNLpqgjcYhmGvP EwRGLoDIJHonfKGqXXnp7LxDTFLDl5PWebBIVThumIRIAQK8zx+R+X3i1SJQpTH+FRDL PQsCIz+xmkc499lfaJdo8oU+uYnSWBdjopP+tLfwPjMAYMshMEGyEWmamVVBlaCwR+YI tgtJcPC3lN47IgzGIVsPD1n6vv90uu/QC3QtjQ2t6fYo0ZxC2Mwc9C+IirQrin7BDgcu DSKVCi0wLH6E+nbiJ1K531QpInZN/BFZC8JogeazT16RRb2eODUcFGIdAhPjTltIsx0v MtZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=zCMXqF/GaqI6MmFOTYxh6DeeizAt18ebru402L24WHE=; b=zOWUc6EQfpOrATS3j9k/SeHxUWUQ5Nr8ghN/x2iHZWEJyXYF6usLPAojvzv+FbBZfc Lo3L6W1pyhw+GTgM9WkjbPdwhLAbfmrUGkykNCjOQ7nX7QwNrmXWW/PAW2GjVVB6c9bD 2M5qeV7WrkLBSY6M6CRH5m8g1OT2LFs+2JqwvaSqXh45oDvYF/SocDba29+svTDHelGs qeT41fpoyYGPQYyrvAMelujTu9fgX6BzuNkNdvR1/jjOeQ9NilKLIRs2G5Wq3AIGxb8H j+/BM4Ay5nsYltVfYZDaQF6h4k0nS9s2qWI3NN/t49YjxFUcEgC57e2116BxinP1ikq8 2k5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lLall1nH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u4si4403843eja.510.2022.02.21.12.35.49; Mon, 21 Feb 2022 12:36:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lLall1nH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353731AbiBUKCR (ORCPT + 99 others); Mon, 21 Feb 2022 05:02:17 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:57108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352013AbiBUJxA (ORCPT ); Mon, 21 Feb 2022 04:53:00 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 669981D317; Mon, 21 Feb 2022 01:23:20 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 19146B80EAF; Mon, 21 Feb 2022 09:23:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3CFACC340E9; Mon, 21 Feb 2022 09:23:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1645435397; bh=SH5kv4+d2g9ytmY1kPDcn0mQvYvUQiU/BXUGy5MogX8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lLall1nHhA8Xk+mWFHTLsBqhGTflRMRNa8/6or2CFMOVJJuOkE0V58KoRac46C71u vDKgfQSCjrfZ+vudBgPaAS3B+9PdzzKP/LaD0tUl0g4bw+7ytqU9WoUXHBK3ZSmqMb D9ym82nU50ETN/iWmSFg2dD7ZuayU6d1fN925RsE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tom Rix , "David S. Miller" Subject: [PATCH 5.16 117/227] mctp: fix use after free Date: Mon, 21 Feb 2022 09:48:56 +0100 Message-Id: <20220221084938.753002243@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220221084934.836145070@linuxfoundation.org> References: <20220221084934.836145070@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tom Rix commit 7e5b6a5c8c44310784c88c1c198dde79f6402f7b 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: 4f9e1ba6de45 ("mctp: Add tracepoints for tag/key handling") Signed-off-by: Tom Rix Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/mctp/route.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) --- a/net/mctp/route.c +++ b/net/mctp/route.c @@ -414,13 +414,14 @@ static int mctp_route_input(struct mctp_ * 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 {