Message ID | 20221117214249.2addbe10@gandalf.local.home |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp743488wrr; Thu, 17 Nov 2022 18:48:07 -0800 (PST) X-Google-Smtp-Source: AA0mqf4gifsVIUbxjJP4mon82uimh+t1PUSLiMpnkpUYWkaFCM8gy2Bjx7Tdf/yv3vhV6vGZ+1J6 X-Received: by 2002:a63:ed4f:0:b0:438:a751:f8fa with SMTP id m15-20020a63ed4f000000b00438a751f8famr4673847pgk.601.1668739686810; Thu, 17 Nov 2022 18:48:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668739686; cv=none; d=google.com; s=arc-20160816; b=kVJwxWjKC5WxDvvObSdjpTBfXd5ydc3BJr+1lWHDxohQ8Cuv1gJg12wfXkRMaxlOkw G7bOQNPobFrLeLOgu1kzlq9U63irMDngo7iDh9X3jSRntu0p7s1G5DjVxeH6pybjgbmq riP7B3Uo1CK65SluSIaEzYAGt7GCRxb2rq/ZQJX2o9Umn3o5ljh0j93CZQqyZbkXopno QdXp6A2TNv0BzUmHb2XvD1BAa9AxBbPehoUs5PYheyHG/DetfZXeQuwYfEuFDehkQNjY 9ujOdwIRVjVo/bO37lOy40qa+Xjyktz4EFBrkArJpIWjA0v3LDY50PSoy0p5bKWKFlDo CgUA== 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:subject:cc:to:from:date; bh=h+3/CVhCMc4KANedgb+INnksrVgawNAscAgOHQo6TFY=; b=AhVguaUDCBqXyy4ofTNRWaz08xEuXrPIWWdrWhpD/A7v2ibxGL1RRMfpMuMAOWRn40 Wk0UuzWSjqCm+hEYKR/NrTrfW5K5Axt/PDZdxgStxx+XnDQ8QtWCnrWF3Ar7b92V+T0Z Po8MrRhjUmsHLXZRdIIARsBUPcGvMu9UnQD20B2lnH+mqu47S8iZUIAljTMbU2LFYTAK nm49yCp50iFsEPgFZCO/64zqMi2pCi4TZ/kfNUGA0YsDbSonR7ZcLN5mpmpIPNTjB0mY v9A6Kez7V9Va9yIODn/FiFomatrnwiIxzGa43YCcur2DaVtWUfb9gY8bYahaoXooOjXA Z6RQ== 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:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t17-20020a170902e85100b00186a3bc939esi2940817plg.211.2022.11.17.18.47.53; Thu, 17 Nov 2022 18:48:06 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234758AbiKRCm4 (ORCPT <rfc822;a1648639935@gmail.com> + 99 others); Thu, 17 Nov 2022 21:42:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232050AbiKRCmz (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 17 Nov 2022 21:42:55 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC69E8DA4C; Thu, 17 Nov 2022 18:42:54 -0800 (PST) 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 dfw.source.kernel.org (Postfix) with ESMTPS id 67DAB6229D; Fri, 18 Nov 2022 02:42:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 51B23C433D6; Fri, 18 Nov 2022 02:42:52 +0000 (UTC) Date: Thu, 17 Nov 2022 21:42:49 -0500 From: Steven Rostedt <rostedt@goodmis.org> To: LKML <linux-kernel@vger.kernel.org>, Linux Trace Kernel <linux-trace-kernel@vger.kernel.org> Cc: Masami Hiramatsu <mhiramat@kernel.org>, Rafael Mendonca <rafaelmendsr@gmail.com>, Tzvetomir Stoyanov <tz.stoyanov@gmail.com>, Tom Zanussi <zanussi@kernel.org> Subject: [PATCH] tracing: Fix race where eprobes can be called before the event Message-ID: <20221117214249.2addbe10@gandalf.local.home> 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=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749800385563322547?= X-GMAIL-MSGID: =?utf-8?q?1749800385563322547?= |
Series |
tracing: Fix race where eprobes can be called before the event
|
|
Commit Message
Steven Rostedt
Nov. 18, 2022, 2:42 a.m. UTC
From: "Steven Rostedt (Google)" <rostedt@goodmis.org> The flag that tells the event to call its triggers after reading the event is set for eprobes after the eprobe is enabled. This leads to a race where the eprobe may be triggered at the beginning of the event where the record information is NULL. The eprobe then dereferences the NULL record causing a NULL kernel pointer bug. Test for a NULL record to keep this from happening. Link: https://lore.kernel.org/linux-trace-kernel/20221116192552.1066630-1-rafaelmendsr@gmail.com/ Cc: stable@vger.kernel.org Fixes: 7491e2c442781 ("tracing: Add a probe that attaches to trace events") Reported-by: Rafael Mendonca <rafaelmendsr@gmail.com> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org> --- kernel/trace/trace_eprobe.c | 3 +++ 1 file changed, 3 insertions(+)
Comments
On Thu, 17 Nov 2022 21:42:49 -0500 Steven Rostedt <rostedt@goodmis.org> wrote: > From: "Steven Rostedt (Google)" <rostedt@goodmis.org> > > The flag that tells the event to call its triggers after reading the event > is set for eprobes after the eprobe is enabled. This leads to a race where > the eprobe may be triggered at the beginning of the event where the record > information is NULL. The eprobe then dereferences the NULL record causing > a NULL kernel pointer bug. > > Test for a NULL record to keep this from happening. > > Link: https://lore.kernel.org/linux-trace-kernel/20221116192552.1066630-1-rafaelmendsr@gmail.com/ This looks good to me. Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> BTW, would other trigger callbacks also need to add similar checks? Thank you, > > Cc: stable@vger.kernel.org > Fixes: 7491e2c442781 ("tracing: Add a probe that attaches to trace events") > Reported-by: Rafael Mendonca <rafaelmendsr@gmail.com> > Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org> > --- > kernel/trace/trace_eprobe.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/kernel/trace/trace_eprobe.c b/kernel/trace/trace_eprobe.c > index 5dd0617e5df6..6b31b74954d9 100644 > --- a/kernel/trace/trace_eprobe.c > +++ b/kernel/trace/trace_eprobe.c > @@ -563,6 +563,9 @@ static void eprobe_trigger_func(struct event_trigger_data *data, > { > struct eprobe_data *edata = data->private_data; > > + if (unlikely(!rec)) > + return; > + > __eprobe_trace_func(edata, rec); > } > > -- > 2.35.1 >
On Fri, 18 Nov 2022 21:18:09 +0900 Masami Hiramatsu (Google) <mhiramat@kernel.org> wrote: > This looks good to me. > > Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> > > BTW, would other trigger callbacks also need to add similar checks? I just checked, and yes, I think that histograms (the only other trigger that has EVENT_CMD_FL_NEEDS_REC set) has the same issue, and requires: diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c index 087c19548049..1c82478e8dff 100644 --- a/kernel/trace/trace_events_hist.c +++ b/kernel/trace/trace_events_hist.c @@ -5143,6 +5143,9 @@ static void event_hist_trigger(struct event_trigger_data *data, void *key = NULL; unsigned int i; + if (unlikely(!rbe)) + return; + memset(compound_key, 0, hist_data->key_size); for_each_hist_key_field(i, hist_data) { I'll add that next. -- Steve
diff --git a/kernel/trace/trace_eprobe.c b/kernel/trace/trace_eprobe.c index 5dd0617e5df6..6b31b74954d9 100644 --- a/kernel/trace/trace_eprobe.c +++ b/kernel/trace/trace_eprobe.c @@ -563,6 +563,9 @@ static void eprobe_trigger_func(struct event_trigger_data *data, { struct eprobe_data *edata = data->private_data; + if (unlikely(!rec)) + return; + __eprobe_trace_func(edata, rec); }