Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4848489iob; Mon, 9 May 2022 03:07:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyyL994hothQQ1qCY7d5sU1mcoypywiTWyeOdvxI8Ba0/NGbgabB2fgr4AoolY19r5sCZ0w X-Received: by 2002:a17:90b:4f92:b0:1cd:3a73:3a46 with SMTP id qe18-20020a17090b4f9200b001cd3a733a46mr17609786pjb.66.1652090836148; Mon, 09 May 2022 03:07:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652090836; cv=none; d=google.com; s=arc-20160816; b=RG8zdpvTeC5GPRQyHXsOH/aXzN0a6u9gBGfVAiKST6uPk8q0wR5t79fKJfW+W2w/Ub z77g3NGJKVHULR/LeHAXXfGFuxYtQFxO3/HjlVVWtr40aBSgR9GVgzlk9aasLbHefWbu 5r3o/+uzASED0VxP/xsqVlKObIV48nlTZmCehCqMmC5dIlt88g+YWce0Ex3Rf2HrwUJY KT68nptogBsiwzhpfmH3j10uUAnmpPq0aJXBUZZSpBhNstPAw1tRT+2IM7KFRbV2HhO+ 2CVh8jEBmjQXaQg9Af9kOdTV1p4kJ2n0JaN/If625pHvlBLwRwALP+0wj50BDI1LDSRb NClw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=7Ql2K8wjSf4eSR22uE7Flc4Ghh3WCh6Zkh++Kk33ag4=; b=VuaAxHQpPFpd42NofG4fDgZGnxpZ9ZoqFQlLHOhdkpwM9fyUB1DTdFmU3I258lhpg/ wE1TVETYIpOV8KEPzk0RrD+hDYxfDXl6iab6bHE2vA8bXyjmzYBwUgBDuoVygVRYi3kz YDf3wS1HcdCvO5mSorrDyNGbLETrGPsy19EpariPPhU52ZtqhqXIXr8lofdGtRcfJVVO 5DtW5+KKzFIixGQPFB/3X3Twj/AWw9UU/MJBFwZJEbLsS9PhZmln8jAztZR/UWwbCW4G WpNY9vtamCov1Qj62S5qDu5k07/Pl9uBGEqrGdUq5uqtloc2RKbelYQelC0HdCFN124+ mg4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Ra5fBxl1; 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 w8-20020a170902e88800b0015ce3e0aa5fsi12433162plg.248.2022.05.09.03.07.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 03:07:16 -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=Ra5fBxl1; 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 out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 851B615E610; Mon, 9 May 2022 02:46:31 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234028AbiEIBsa (ORCPT + 99 others); Sun, 8 May 2022 21:48:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232422AbiEIBlN (ORCPT ); Sun, 8 May 2022 21:41:13 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62690344E5 for ; Sun, 8 May 2022 18:37:16 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id n6-20020a05600c3b8600b0039492b44ce7so451657wms.5 for ; Sun, 08 May 2022 18:37:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=7Ql2K8wjSf4eSR22uE7Flc4Ghh3WCh6Zkh++Kk33ag4=; b=Ra5fBxl1HbkVvB5WFu32ZS3wUApM4Nh/avRNb5JsMij0zVMYAj/r5UD5SACg1+lUzc /CdemvsyD7QwAU3vt0qcqdu5cEcWfHM+POLTZ4Z5dDSoqive9DkMrZXTjtsOMdE0/yGO P2qO09GGsC8R3xagaeYe16hOIFZ88hQNVU5eqADaFCo0ZJkn7jlIJRrNEOuyksBGLKRP iGG/BE51embL80f3Z9wNI0FJdfyIfiYVkmF4pD9pbsiH+uxfc8D5dZ+caQ+U+OYI1aNu iIYm6HzUVyFFHsyOSM7/n1YK+MMHIZe6sq7uluURvzm+1j1dkQeoMtAEbUF5beBun51y uL+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=7Ql2K8wjSf4eSR22uE7Flc4Ghh3WCh6Zkh++Kk33ag4=; b=mEi49q19N9eBTA/iQdlseIHrq0snEdoZTxqXEBVf+UeD8vHUOKU7LOWXF12SFDbqww h0s2G0FO1l4YAVYhcBj9/NZEUGfoAM0MKy6nxa9CrJu1JJBpk5qRFn6SqkCUV8+Zc3hp Cz3UIdrOTIQ9zhCF1b2Cn0P+pUaF35yGWwIahPai/bT788JzvcYD193PLruQKe0InyBO mUAnxbbjlEqtO2B2FwJVa6BZR2UhWARKWE0FeatIBLpyYFWIOIYIDUWXrTzBJGw570eG 1q9GlixPUEPfS9WmFY+uoRIDZadVeFuHQihwvIE9mLSwDQKKJXgzlbRKG48K8J8kI+W9 hrxA== X-Gm-Message-State: AOAM532xeuSOuW+eSeEYtbyTCJB0x5fPO+yHeJ4rCz33YGn5nsTyiJKi 2zei0Js/Uc81+37n0J4neF5vkdN8ncg4WCXkvYs= X-Received: by 2002:a05:600c:ad1:b0:38c:8bf6:7d6b with SMTP id c17-20020a05600c0ad100b0038c8bf67d6bmr13755649wmr.84.1652060036236; Sun, 08 May 2022 18:33:56 -0700 (PDT) MIME-Version: 1.0 References: <20220508161827.1014186-1-xiehuan09@gmail.com> In-Reply-To: <20220508161827.1014186-1-xiehuan09@gmail.com> From: Jeff Xie Date: Mon, 9 May 2022 09:33:44 +0800 Message-ID: Subject: Re: [PATCH] tracing: Fix possible crash in ftrace_free_ftrace_ops() To: Steven Rostedt Cc: mingo@redhat.com, Masami Hiramatsu , Tom Zanussi , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" 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 I am so sorry to bother you, this may be an invalid patch, kfree can return directly from null. ;-) On Mon, May 9, 2022 at 12:18 AM Jeff Xie wrote: > > 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 > Thanks, JeffXie