Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3857270iob; Tue, 17 May 2022 08:34:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxoihyMnxKCaT6odT0pakQtjD4+TEvrc8RfUxXyHMQ09w20g2ByaOEQaJxzyFlpQwf84XKX X-Received: by 2002:a17:903:2443:b0:161:bc26:825 with SMTP id l3-20020a170903244300b00161bc260825mr298525pls.32.1652801666118; Tue, 17 May 2022 08:34:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652801666; cv=none; d=google.com; s=arc-20160816; b=HK/8jgD4gPJsIAwyoo1aESBnBEJ7kglQgAiaXuJYJOiAdkTm910eKlsahCrXO3I2fY aXAXdH2pEuC0BJcT13CudHGsApFEnapF/2Mx6Nuo2SGfaRNf99n75kol0Wa0/sRtb1JJ SrBb8qQ+Ekq2aSAq1nPyK8C0QB5uDnl8YYzTvOiQP4A4y8nff5x29N2+1k/U28MVd1bO 3DmzjVtFG9affhqwSeZt/qT/TyDO2e6ivi1XNy+9ucDZBrpzdVQ+Wvjfuglr9hul/9Us qUPeNIPR6ocJG/TzzkPaV9IR7wKjn7GwT0SSKvD7QddnNXidiEPAW9BZT4kKd9aglSPp U4sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=zqxKM6eotU228yrHwTeanJ4JHp6muv7frj9QCzZ1g10=; b=CxmVoo+zMOfd12e42n8myKwGt/hdhQh4hAqHcNuFm5qz1Tm/OkutEJMZUbWHmXKcWr 4Gd2vi+44pzoW8tOQm7JbbyT3PY1jhNQ37hCk5tbbd6HVZvFnh7MJ7gH73oBPpT0QL+O DbzjXGHPIZL1WNOusiNP9bfUy+GTV4Jn5PiuinDOBPd7hcShNfkCAL2ABd4S1t7cHKKb jMXNm0ich05WgMirxO2EFLzzQViFMb8kYYzcGYvwEjbM7+wE2hDttLEcfqhQ/7iWJyzJ fPWwhkORqRZf/omzmm6kUIt3H/t8Siucb6aNXKyJr1QMpJJ1lrAKYhH8qH+vXAtOke4d GYZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=CrdwYFeI; 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=163.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b15-20020a170903228f00b0015d0953a427si19906289plh.142.2022.05.17.08.34.13; Tue, 17 May 2022 08:34:26 -0700 (PDT) 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=@163.com header.s=s110527 header.b=CrdwYFeI; 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=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245420AbiEQJ6L (ORCPT + 99 others); Tue, 17 May 2022 05:58:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245316AbiEQJ5z (ORCPT ); Tue, 17 May 2022 05:57:55 -0400 Received: from m12-13.163.com (m12-13.163.com [220.181.12.13]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C2D3E37AB0; Tue, 17 May 2022 02:57:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=zqxKM6eotU228yrHwT eanJ4JHp6muv7frj9QCzZ1g10=; b=CrdwYFeIsB3anMwUtaE7nAn+QSxi/XWise X59wLAiS1OzNgtTnIj7/OkDUjkVzakmkAfMRvyIZ2ybKz1J3+PSvaYMVqYCEJk80 5MEHmRJPrNcCbJ3uXLUzx4dRPheWtKQItKCN3KEq6BmHN2AU+q1rxpJVKt9VmcTa wzLSzbmtU= Received: from localhost.localdomain (unknown [202.112.113.212]) by smtp9 (Coremail) with SMTP id DcCowAA3PCWEcYNiDfluDQ--.937S4; Tue, 17 May 2022 17:57:42 +0800 (CST) From: Yuanjun Gong To: Yuanjun Gong , Steven Rostedt , Ingo Molnar , linux-kernel@vger.kernel.org Cc: stable@vger.kernel.org Subject: [PATCH 1/1] tracing: fix possible null pointer dereference Date: Tue, 17 May 2022 17:57:23 +0800 Message-Id: <20220517095723.7426-1-ruc_gongyuanjun@163.com> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: DcCowAA3PCWEcYNiDfluDQ--.937S4 X-Coremail-Antispam: 1Uf129KBjvJXoW7AryDJrWfAr13Xr4rtFWxXrb_yoW8GrW7pr W5Cr15Kr48tanFvF13uFn7Cry8J3s7Jry5CF4Uu3WfJry5Gr1vqr4q9ry8u3W0yFWDJwnx Xw1UZryF9FZrta7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0piQJ55UUUUU= X-Originating-IP: [202.112.113.212] X-CM-SenderInfo: 5uxfsw5rqj53pdqm30i6rwjhhfrp/1tbiNxcE5VWBn73nLgAAs+ X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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: 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) { 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++) - kfree(elt_data->field_var_str[i]); - - kfree(elt_data->field_var_str); - + 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); } -- 2.17.1