From patchwork Fri Nov 18 02:42:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 22078 Return-Path: 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 + 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 ); 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 To: LKML , Linux Trace Kernel Cc: Masami Hiramatsu , Rafael Mendonca , Tzvetomir Stoyanov , Tom Zanussi 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 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: 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?= From: "Steven Rostedt (Google)" 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 Signed-off-by: Steven Rostedt (Google) Acked-by: Masami Hiramatsu (Google) --- 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); }