Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp6330520pxb; Mon, 14 Feb 2022 23:12:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJweqy1RzL0DvnesIuzGasYBSI/KxMD4sXA9x3gtB/s79DBFgTU2V7KC9CBSIfR/uq4CBzu6 X-Received: by 2002:a17:90b:310:b0:1b5:677a:3383 with SMTP id ay16-20020a17090b031000b001b5677a3383mr2867566pjb.187.1644909170894; Mon, 14 Feb 2022 23:12:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644909170; cv=none; d=google.com; s=arc-20160816; b=ZFnaLKe5t4a1ZatItiAfBYJbKyOLqal85i09emScpudgg/7vFzKtM/lrLSWzN3NWv5 OJLuEC5yKBD85q94/NjezoyO1Cbvi8WTkxdc332jUVQRL1oGC1B5XZjA51YYCg9i7NYj cXdrQamgX01uzciDJE96lK6N5ZwHwtu2X0YJJlUsv1y9poLOtpquXOq7jgGL2dgid/I2 /jLCWJQpOPvXC8l/fhb3e4kAO5X3ZiS4F+vGvPSxpjeqStNkoh0viDN1rcCTdhixarvp kDBwQjS/8os02hWTqOp58RQkxR6t5GMJl+QlJcs22TCk+7uOQ72O+IwzHsOVrqxzkfxy t5jQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=rcVCDBo5DVaghZVQQl2zbGTyQ7E+laKLLxGgEjqHxnk=; b=OdYemajxiN+vZkvJ+yPncS08y1xh6XCed2QcjGur0lTSnZaEY6GP52yiCkzs+qiLvs hWteJhwzZAZsKylg+rQiA6hdeg4NW4pjoB17kTPEWnVuZIKXGwC0xAj/jtFGaq+3lY7j 6te6CceOu5TOfN8LBjJnL84wKnQSXe7IgnsltdVqzJswMcSIpjgxlcBsRwsUPd4o1Pg7 GYb5LLHUCLjAXeg+PwdsabNor00cNW9X8rk5jKcXQ4C1eCLoURyYS5ePaNT6DhbcKnhs 225lR3JpNkNpJ3bP/VqFq4X2Tt1cn9w3OVwB9NLmV0xG9PqeO1l4WyXhoxraWPfeNqhM eVcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BsxIUDJ0; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s16si6105990pfk.133.2022.02.14.23.12.36; Mon, 14 Feb 2022 23:12:50 -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=@redhat.com header.s=mimecast20190719 header.b=BsxIUDJ0; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231868AbiBOCGI (ORCPT + 99 others); Mon, 14 Feb 2022 21:06:08 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:49480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230498AbiBOCF7 (ORCPT ); Mon, 14 Feb 2022 21:05:59 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E8652246 for ; Mon, 14 Feb 2022 18:05:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644890748; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=rcVCDBo5DVaghZVQQl2zbGTyQ7E+laKLLxGgEjqHxnk=; b=BsxIUDJ0NFwUiJ43PxEXU25y1vTuIzFDlJT36TVEeYsSeAjix370M3S14x+VeiVImZpYVh ybAaCpPtG7IAqjI2MIlyPAfEqj5tohTeDvfW1P383T/n32JInI3MLvmIx6m44mo3fpgB5S HGUF20Hn81Et1PA9gKO6PtJYyrlm8GU= Received: from mail-oo1-f69.google.com (mail-oo1-f69.google.com [209.85.161.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-20-FwxPgrQzM-2Owczkqe46SA-1; Mon, 14 Feb 2022 21:05:47 -0500 X-MC-Unique: FwxPgrQzM-2Owczkqe46SA-1 Received: by mail-oo1-f69.google.com with SMTP id v10-20020a4ade8a000000b003177422e81dso11707435oou.3 for ; Mon, 14 Feb 2022 18:05:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=rcVCDBo5DVaghZVQQl2zbGTyQ7E+laKLLxGgEjqHxnk=; b=ZUY+P9geHRG61LrfvO8WOHLoPuNyp+kUpqpF2GZSPpa8xnAdESLG5O3/JtK9lyMSgb KwinOFes0+9vkrsOfJhsAA7ctQ4/IDbZyZbisd+3z4MhpiXknklcCKzF3rWK8FH4PMKt 8YadA477VZ7NXCVGq+3cQC3ktVuJlXMJ7D2el2ZVqOcQvXzQxt3IbuD/JfXp7bOaOKU/ CliW8HWgoBatVfp/lzmaps02UMYb9pXgBMqu5Ynb2/GL5Cv5j5NZ3qyF8Ku+NccTtgr2 EFtabWQZb62gePaKTEkxRjwVuzv7CnKqANZUUKsxyWvbvdNrjz1x9r4D1Q06SoWutb3Q lBQQ== X-Gm-Message-State: AOAM533WWipJMStUKL3OUQ2WEUZ0G5pze7odcAdvdRDVw854vKc4nz3i 1a4j9o5tWV62CoIljJ76uunpo0NIB7l7UV67TzYbzUqKImXvNlRBhBNK5M4CjhM04cGWeinDrBv rVpiDym963r56tMoaEvLZpmaX X-Received: by 2002:a05:6830:4113:: with SMTP id w19mr688306ott.120.1644890746728; Mon, 14 Feb 2022 18:05:46 -0800 (PST) X-Received: by 2002:a05:6830:4113:: with SMTP id w19mr688302ott.120.1644890746552; Mon, 14 Feb 2022 18:05:46 -0800 (PST) Received: from localhost.localdomain.com (024-205-208-113.res.spectrum.com. [24.205.208.113]) by smtp.gmail.com with ESMTPSA id r41sm14527325oap.2.2022.02.14.18.05.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Feb 2022 18:05:46 -0800 (PST) From: trix@redhat.com To: jk@codeconstruct.com.au, matt@codeconstruct.com.au, davem@davemloft.net, kuba@kernel.org, nathan@kernel.org, ndesaulniers@google.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Tom Rix Subject: [PATCH v2] mctp: fix use after free Date: Mon, 14 Feb 2022 18:05:41 -0800 Message-Id: <20220215020541.2944949-1-trix@redhat.com> X-Mailer: git-send-email 2.26.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,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 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 --- v2: change the Fixes: line net/mctp/route.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/net/mctp/route.c b/net/mctp/route.c index 17e3482aa770..0c4c56e1bd6e 100644 --- a/net/mctp/route.c +++ b/net/mctp/route.c @@ -419,13 +419,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 { -- 2.26.3