Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4714146iob; Sun, 8 May 2022 23:00:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwMSd6H2Px9GvRIpXFlzBYx3gVAbsCM14n29Lfseo/ps6UqSaBOpxpGqbxhzJMeebCWMj/j X-Received: by 2002:a17:90b:4f81:b0:1dc:69a0:432b with SMTP id qe1-20020a17090b4f8100b001dc69a0432bmr24572623pjb.203.1652076023492; Sun, 08 May 2022 23:00:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652076023; cv=none; d=google.com; s=arc-20160816; b=bE6sr2jWZ2ilS+lXjOjQ6zq6liVOf1UD3bkH34ncepbnyPDOm/zxxm6M/T474NN4P3 41R2dQfA6DZHhMjqTgW5S9m7ylHB/DESineFlozMuhAkLvIUZ4ZZ+Nfr/09NeeBDYsXB +heq472eBCawUW9s/52b+wonLwsIp60vKBtZew/91+f9QrxZ2J5BxZvuoS/cjUEGzNqI eBaIShDUeAU+IZVWjLZwTB2FNaVonI2+KlDKOIGWgsTVvq3nE7kdnKgWLAVt8Em22l3S g6bn3V+7edm1tMcHWTjn8fbTL1jdKdaKzgx/KG2dOtN14CFOOmSUo9j751yG0+0jkgpl hUSw== 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=QWhBNZogHnlvklmcU4nt0RMjAacSV4GHQXRxhMD3Rlo=; b=w8EQhk+qbuvKTVUIIlKGNtfz6U8ulCzAVC2x24kJv8eBm0zWIQCt3o5flZLP4xETov j9SwgFxPCA330H1IleD2EJGQ9P7jghcwAXHekv+fyucEUu0nca9rRWyhEup1+posiWLQ MXtQzAbiyjguIXjHpy9Pe2kuRL1bfr0bQbYN3psIoNi5jcp7GVR50UDHMUTGecbF/6Ip KfvR3se78zWnOzTpYGj18rz28PH2UkglwMkCE1sy1/1T4iuf2PxL/ubvXL88+w4+8Gry 48bbqeFlnFeRv9RsERnDxS4XyUCFu0VX9JKBD2FakLnje+u4a54MmmcRiW/pcgRxhEuJ LkJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=pZqYl9oA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id i16-20020a170902c95000b00155d4e81304si13012711pla.143.2022.05.08.23.00.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 23:00:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=pZqYl9oA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2074C1654AE; Sun, 8 May 2022 23:00:14 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235485AbiEHQWu (ORCPT + 99 others); Sun, 8 May 2022 12:22:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235380AbiEHQWt (ORCPT ); Sun, 8 May 2022 12:22:49 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27DEBC3F for ; Sun, 8 May 2022 09:18:59 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id c9so11102466plh.2 for ; Sun, 08 May 2022 09:18:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=QWhBNZogHnlvklmcU4nt0RMjAacSV4GHQXRxhMD3Rlo=; b=pZqYl9oApiyD69ykUKFSXDUrectgXO2RIH+N2EDpEVnmkQRU9LlGQX//uCvUD7Kmhu 8CJDHcK4IvpPlBArsCKeTKkW+YPVJhlSjrZBLHJ3bIPcePRep2hyVsnjfpODBmGeexNw bJLU69fGwpVWJU1ynYkA6ibtP7WCO8ynyKfZXxHpEDq6znFA6P0/H8HoGLui2Im/uDn4 5IAF81xo7qWbK8aaJMizfybHv5B546fURyOzAXSEZ9UI+J3St2xC/r0YVUwPuK70fmOX JhIGf4n50Rrdh8tB+7UvbXSsqRk9zAGpKaICajsd//gY5mFJ79x+V6HYNrSSHLCG4rDw 2Cbg== 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=QWhBNZogHnlvklmcU4nt0RMjAacSV4GHQXRxhMD3Rlo=; b=B9t298alOoEutFD+1eC8+n/5iRlUC5V9F+zGRD5UJNBGkK4MgB52GpJAAfAxA2iIJM C7YrvQHYg+mgAbLa693onhn+3//4esn26G7QLo+IkAilE4XqBSxWdKxwvvhvJWuQr8Dh iZbV0BKmSSRYujX07riQFpMj3qudH48QYZdYVtoJYuvP4GJBQL2RS/oBTjRTLHeX7NbY a96yo0lg5wCX+G5Niet5XYkwQLarXwZzyqJZwxp7xjkk34c8SMG3K8qwbsk/mXISbXqp 1AwAY8NlU0mztpQ3+2+w+SX7hJCLTnjaFrkpNFmkT2ONk/GAYVEZ4sog/tlV3R/xGdyC Ur7A== X-Gm-Message-State: AOAM533mAhgFyQMMaMrBIcYhDznHuSqNHJrBrkIrXF33eaozYdnzvIRM HKEdw+9SMK1DQa1wnZIWHL8= X-Received: by 2002:a17:90b:2311:b0:1d9:277e:edad with SMTP id mt17-20020a17090b231100b001d9277eedadmr14136254pjb.190.1652026738706; Sun, 08 May 2022 09:18:58 -0700 (PDT) Received: from localhost.localdomain (li567-56.members.linode.com. [192.155.81.56]) by smtp.gmail.com with ESMTPSA id d15-20020a170902b70f00b0015ea0a679ddsm5320291pls.251.2022.05.08.09.18.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 09:18:58 -0700 (PDT) From: Jeff Xie To: rostedt@goodmis.org Cc: mingo@redhat.com, mhiramat@kernel.org, zanussi@kernel.org, linux-kernel@vger.kernel.org, Jeff Xie Subject: [PATCH] tracing: Fix possible crash in ftrace_free_ftrace_ops() Date: Mon, 9 May 2022 00:18:27 +0800 Message-Id: <20220508161827.1014186-1-xiehuan09@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 Currently if the ftrace_allocate_ftrace_ops() return -ENOMEM, the ftrace_free_ftrace_ops() will kfree(NULL). trace_array_create() { ... if (ftrace_allocate_ftrace_ops(tr) < 0) goto out_free_tr; ... out_free_tr: ftrace_free_ftrace_ops(tr); ... } ftrace_allocate_ftrace_ops() { ... ops = kzalloc(sizeof(*ops), GFP_KERNEL); if (!ops) return -ENOMEM; ... } ftrace_free_ftrace_ops() { kfree(tr->ops); tr->ops = NULL; } Signed-off-by: Jeff Xie --- kernel/trace/trace_functions.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/trace/trace_functions.c b/kernel/trace/trace_functions.c index 9f1bfbe105e8..d186d6101695 100644 --- a/kernel/trace/trace_functions.c +++ b/kernel/trace/trace_functions.c @@ -73,6 +73,9 @@ int ftrace_allocate_ftrace_ops(struct trace_array *tr) void ftrace_free_ftrace_ops(struct trace_array *tr) { + if (!tr->ops) + return; + kfree(tr->ops); tr->ops = NULL; } -- 2.25.1