Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp767164iob; Wed, 18 May 2022 12:29:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy9B7kc99N+C9qyIUyuwXcsq0EtvY3UVFitfYY2/3Xy8YI53z51GssB9GiBHh0P6w8IhR95 X-Received: by 2002:a63:34a:0:b0:3f5:ef54:ec6c with SMTP id 71-20020a63034a000000b003f5ef54ec6cmr803681pgd.41.1652902178455; Wed, 18 May 2022 12:29:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652902178; cv=none; d=google.com; s=arc-20160816; b=qYgX/BiH4+LGXYo7bzoAtak9qh9W+lBZC64OsqQm1FwyaNhHCBT8KidZjw0d6JEnSu Rt7V8pdNuaVnISE8tkYSDJUZLmdJoV8w0ENYidEkpwutL21fakgk6O3i+y0ejvIbLn6R TSprqvvYU8u6tYNB0PNGb9dufTjVAIXj3+XEsvhrhw4t/Y3KI/hVgd9O9RiOytrQCyVk 94XnCRsi4QAtV1FmwqSKjNywkEEPDlc9NbS/j/Xj/yu85oOQjmzSm21/qdJxcFSn3GES 7mSnseu3zxHAbw4Eo7CTEW80YRH585Dimdx25UTsxIYn2c9FP1i2X/K38JyO2hQr+zmg S5gA== 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 :references:in-reply-to:message-id:subject:cc:to:from:date; bh=tU8fe7tj8jSb5kuzCvDXHi097/m402OBbWi7krcsD80=; b=UBwvcdc7PRnmVcYEsVuRrw09v7OrOwiAyjaRqviI+NFuKE99/4tbDgi9ENZz6LwLkY lYR2rc7aee+fk2WQvGvm/ayC5YuM9r1E2E1HPtHvaVV30s01qGRMzv68lhYQKnfae9RR +KnBXL1SEh5aXcIYs7uaxI2FKmjAROmPfJlNpMj094+kq2Nc2FoXfTqt+jHX4D3tB6hP TIwg0RkbxQaMHUF0QJxP3PL1EyFDpTD0WwOHkayEjZdgQE7wF56JoKnQ3XhrP18tZq/k RXrojfGnhxIQmbSz40To1ioPfzi7GVfonCCn9Qt6z9WAfVxHqp+E0IfBijALLVR7McSK xF0Q== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id c8-20020a056a00248800b0050fac0168c6si4092201pfv.49.2022.05.18.12.29.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 12:29:38 -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; 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CD6D81BDD95; Wed, 18 May 2022 12:29:00 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241845AbiERT2r (ORCPT + 99 others); Wed, 18 May 2022 15:28:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232246AbiERT2q (ORCPT ); Wed, 18 May 2022 15:28:46 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 988A71BA8E6; Wed, 18 May 2022 12:28:44 -0700 (PDT) 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 4AA72B821AB; Wed, 18 May 2022 19:28:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 72D9FC385A5; Wed, 18 May 2022 19:28:41 +0000 (UTC) Date: Wed, 18 May 2022 15:28:39 -0400 From: Steven Rostedt To: Yuanjun Gong Cc: Ingo Molnar , linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH 1/1] tracing: fix possible null pointer dereference Message-ID: <20220518152839.0f51830b@gandalf.local.home> In-Reply-To: <20220517095723.7426-1-ruc_gongyuanjun@163.com> References: <20220517095723.7426-1-ruc_gongyuanjun@163.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, 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 On Tue, 17 May 2022 17:57:23 +0800 Yuanjun Gong wrote: > From: Gong Yuanjun > > In hist_trigger_elt_data_alloc(), elt_data is freed by > hist_elt_data_free() if kcalloc fails. > > static int hist_trigger_elt_data_alloc(struct tracing_map_elt *elt) > { > ... > elt_data->field_var_str = kcalloc(n_str, sizeof(char *), GFP_KERNEL); > if (!elt_data->field_var_str) { But at this position elt_data->n_field_var_str is zero. > hist_elt_data_free(elt_data); > return -EINVAL; > } > ...} > > In hist_elt_data_free() the elt_data->field_var_str field should be > checked before dereference. > > Signed-off-by: Gong Yuanjun > --- > kernel/trace/trace_events_hist.c | 10 +++++----- > 1 file changed, 5 insertions(+), 5 deletions(-) > > diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c > index 44db5ba9cabb..73177c9f94b2 100644 > --- a/kernel/trace/trace_events_hist.c > +++ b/kernel/trace/trace_events_hist.c > @@ -1576,11 +1576,11 @@ static void hist_elt_data_free(struct hist_elt_data *elt_data) > { > unsigned int i; > > - for (i = 0; i < elt_data->n_field_var_str; i++) This loop will not execute because n_field_var_str is zero, and 0 < 0 is false. > - kfree(elt_data->field_var_str[i]); > - > - kfree(elt_data->field_var_str); freeing a NULL pointer is OK to do. There is nothing wrong with the current code. NACK. -- Steve > - > + if (elt_data->field_var_str) { > + for (i = 0; i < elt_data->n_field_var_str; i++) > + kfree(elt_data->field_var_str[i]); > + kfree(elt_data->field_var_str); > + } > kfree(elt_data->comm); > kfree(elt_data); > }