From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AA52D28EB for ; Mon, 30 Jan 2023 14:04:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F3A9C433EF; Mon, 30 Jan 2023 14:04:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1675087451; bh=NjPBDYI5jCL8et9GGDol9+rAhvQkZtIlZplexE6EXmM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G0fs6mts0uahenePtgD2ILrjDHz2QlNteXrUc1LGJrDD8dGO6s7/IiKWw+W3s3REc CEQhfPm3OCtB1uHI4QNCTUa7P7Tzhk5jSmc7QV1Hj6Dorby1nYTp3OTCcj0q+Rmotv rN+bHCWNy184dgOzmrFyHWTlq4zxY8ylEuX7RK4Y= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Natalia Petrova , "Steven Rostedt (Google)" Subject: [PATCH 6.1 213/313] trace_events_hist: add check for return value of create_hist_field Date: Mon, 30 Jan 2023 14:50:48 +0100 Message-Id: <20230130134346.626089538@linuxfoundation.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230130134336.532886729@linuxfoundation.org> References: <20230130134336.532886729@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Natalia Petrova commit 8b152e9150d07a885f95e1fd401fc81af202d9a4 upstream. Function 'create_hist_field' is called recursively at trace_events_hist.c:1954 and can return NULL-value that's why we have to check it to avoid null pointer dereference. Found by Linux Verification Center (linuxtesting.org) with SVACE. Link: https://lkml.kernel.org/r/20230111120409.4111-1-n.petrova@fintech.ru Cc: stable@vger.kernel.org Fixes: 30350d65ac56 ("tracing: Add variable support to hist triggers") Signed-off-by: Natalia Petrova Signed-off-by: Steven Rostedt (Google) Signed-off-by: Greg Kroah-Hartman --- kernel/trace/trace_events_hist.c | 2 ++ 1 file changed, 2 insertions(+) --- a/kernel/trace/trace_events_hist.c +++ b/kernel/trace/trace_events_hist.c @@ -1975,6 +1975,8 @@ static struct hist_field *create_hist_fi hist_field->fn_num = flags & HIST_FIELD_FL_LOG2 ? HIST_FIELD_FN_LOG2 : HIST_FIELD_FN_BUCKET; hist_field->operands[0] = create_hist_field(hist_data, field, fl, NULL); + if (!hist_field->operands[0]) + goto free; hist_field->size = hist_field->operands[0]->size; hist_field->type = kstrdup_const(hist_field->operands[0]->type, GFP_KERNEL); if (!hist_field->type)