From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B60F5C433EF for ; Tue, 15 Feb 2022 00:54:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232447AbiBOAya (ORCPT ); Mon, 14 Feb 2022 19:54:30 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:53776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230096AbiBOAyX (ORCPT ); Mon, 14 Feb 2022 19:54:23 -0500 X-Greylist: delayed 531 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 14 Feb 2022 16:53:56 PST Received: from codeconstruct.com.au (pi.codeconstruct.com.au [203.29.241.158]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B29614147F for ; Mon, 14 Feb 2022 16:53:56 -0800 (PST) Received: from pecola.lan (unknown [159.196.93.152]) by mail.codeconstruct.com.au (Postfix) with ESMTPSA id ED1BC2015A; Tue, 15 Feb 2022 08:44:57 +0800 (AWST) Message-ID: Subject: Re: [PATCH] mctp: fix use after free From: Jeremy Kerr To: trix@redhat.com, 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 Date: Tue, 15 Feb 2022 08:44:57 +0800 In-Reply-To: <20220214175138.2902947-1-trix@redhat.com> References: <20220214175138.2902947-1-trix@redhat.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.42.3-1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Tom, > 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. Looks good to me, thanks for the fix. However, the Fixes tag will need an update; at the point of 4a992bbd3650 ("mctp: Implement message fragmentation"), there was no use of 'key' after the kfree() there. Instead, this is the hunk that introduced the trace event: @@ -365,12 +368,16 @@ if (rc) kfree(key); + trace_mctp_key_acquire(key); + /* we don't need to release key->lock on exit */ key = NULL; - which is from 4f9e1ba6de45. The unref() comes in later, but the initial uaf is caused by this change. So, I'd suggest this instead: Fixes: 4f9e1ba6de45 ("mctp: Add tracepoints for tag/key handling") (this just means we need the fix for 5.16+, rather than 5.15+). Also, can you share how you're doing the clang static analysis there? I'll get that included in my checks too. Cheers, Jeremy