Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3328345rwa; Tue, 23 Aug 2022 02:57:45 -0700 (PDT) X-Google-Smtp-Source: AA6agR529tnsGcU8bYtICM6VTHsTtj/PleyhnPZhiXk0njfLW8nPxTbbc4zSLjZMUYc4mvoyF6P/ X-Received: by 2002:a17:906:ef90:b0:730:9cd8:56d7 with SMTP id ze16-20020a170906ef9000b007309cd856d7mr14894350ejb.94.1661248664813; Tue, 23 Aug 2022 02:57:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661248664; cv=none; d=google.com; s=arc-20160816; b=Y2Dhqy6xG9beUB+flOJZ7r3TFonOjvQuawmykEy2NU2R8Va5JMtbpWoNOroHiNObRz XcOfi0GECscOlfn8PiJf2Z1lhbdnvAplgXWmoFBvzd59d2T+/DlUHrFL6gNMRvAle1nb qBBvcqKXL+mEhKCJ6JLf5xTFFkT9Sl+llZOu3BdKhd4FdCPifvifRG5b95NVxDc928K/ KsYYpDnptrM2aSD1b9A21Nq2m6SI5KG+Y34/+E0xYGKNK65CAR4eJFLkx8ZQIEwq7pqH RivzsRNdHceJdxf+/sM/n4KikQemWmrOHFOKRJbzlOv4CA9s5R3J/swPwhIrhg16Cb2T dlkg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=tJB8nHsrNEu0v/+eSQzAwD6l5AGY6KIpvEvgq1mNxc4=; b=dfKfMt1PklWWWnel1nQ+lnNfDOsV31T5VGS24cNaHbv6l9jScXjPg5ix3t+m4LMORU NWqPxVhA/0tWXHMhD3+GjOYXiKrsKtzEaxfoDGdNDyge3NQfgcWsv34kRiOnDYweK6ZY UtNIhc8+segQrEUB/z9XGz6qC5YYrYH45K7ffeP5K2B1EgawFW2DuuzeLpA3Y+iLNVEl Sdl/YH1QH6LCLTslyk+dU3fiWUm2OxUDjEh4U4sITzs2za8bsr+Z5fEutBQ5LM09e1CG 6PGkpytl6c0+NuG5zm2ty/QNAfJTl+My1nOJ9Mx6fOGn7gPo/g5kGcRG4i1PvROR2Jjq PlIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Rn+MPGCv; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hu8-20020a170907a08800b0073832e13344si11341638ejc.86.2022.08.23.02.57.18; Tue, 23 Aug 2022 02:57:44 -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=@linuxfoundation.org header.s=korg header.b=Rn+MPGCv; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351464AbiHWJik (ORCPT + 99 others); Tue, 23 Aug 2022 05:38:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351460AbiHWJhl (ORCPT ); Tue, 23 Aug 2022 05:37:41 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DEEE129C8C; Tue, 23 Aug 2022 01:40:47 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 160F761377; Tue, 23 Aug 2022 08:40:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CA985C433C1; Tue, 23 Aug 2022 08:40:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661244002; bh=X8v8KkcwcX5ObVqicD2o6pK97cQKiy5IBBKsBJQ6ZT4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Rn+MPGCvBu9fqAQxuZw0gk302p+8WEAdy+T+kRoxiU1kVx7qGVlm8lxOMy1j3xIu1 xy0HTCJ+FoOZA+/yk2y8/iI6GmwBibOWt3wBXPAOPXEvpudEjIMg2SUMm/gEM0Vyh1 6erusAvD2Uuth0DRlbgfq3FzRayYlKiwUZ0vyAbk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ingo Molnar , Andrew Morton , Masami Hiramatsu , Tzvetomir Stoyanov , Tom Zanussi , "Steven Rostedt (Google)" Subject: [PATCH 5.15 022/244] tracing/eprobes: Have event probes be consistent with kprobes and uprobes Date: Tue, 23 Aug 2022 10:23:01 +0200 Message-Id: <20220823080059.805774797@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080059.091088642@linuxfoundation.org> References: <20220823080059.091088642@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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: Steven Rostedt (Google) commit 6a832ec3d680b3a4f4fad5752672827d71bae501 upstream. Currently, if a symbol "@" is attempted to be used with an event probe (eprobes), it will cause a NULL pointer dereference crash. Both kprobes and uprobes can reference data other than the main registers. Such as immediate address, symbols and the current task name. Have eprobes do the same thing. For "comm", if "comm" is used and the event being attached to does not have the "comm" field, then make it the "$comm" that kprobes has. This is consistent to the way histograms and filters work. Link: https://lkml.kernel.org/r/20220820134401.136924220@goodmis.org Cc: stable@vger.kernel.org Cc: Ingo Molnar Cc: Andrew Morton Cc: Masami Hiramatsu Cc: Tzvetomir Stoyanov Cc: Tom Zanussi Fixes: 7491e2c44278 ("tracing: Add a probe that attaches to trace events") Signed-off-by: Steven Rostedt (Google) Signed-off-by: Greg Kroah-Hartman --- kernel/trace/trace_eprobe.c | 70 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 64 insertions(+), 6 deletions(-) --- a/kernel/trace/trace_eprobe.c +++ b/kernel/trace/trace_eprobe.c @@ -226,6 +226,7 @@ static int trace_eprobe_tp_arg_update(st struct probe_arg *parg = &ep->tp.args[i]; struct ftrace_event_field *field; struct list_head *head; + int ret = -ENOENT; head = trace_get_fields(ep->event); list_for_each_entry(field, head, link) { @@ -235,9 +236,20 @@ static int trace_eprobe_tp_arg_update(st return 0; } } + + /* + * Argument not found on event. But allow for comm and COMM + * to be used to get the current->comm. + */ + if (strcmp(parg->code->data, "COMM") == 0 || + strcmp(parg->code->data, "comm") == 0) { + parg->code->op = FETCH_OP_COMM; + ret = 0; + } + kfree(parg->code->data); parg->code->data = NULL; - return -ENOENT; + return ret; } static int eprobe_event_define_fields(struct trace_event_call *event_call) @@ -339,16 +351,38 @@ static unsigned long get_event_field(str static int get_eprobe_size(struct trace_probe *tp, void *rec) { + struct fetch_insn *code; struct probe_arg *arg; int i, len, ret = 0; for (i = 0; i < tp->nr_args; i++) { arg = tp->args + i; - if (unlikely(arg->dynamic)) { + if (arg->dynamic) { unsigned long val; - val = get_event_field(arg->code, rec); - len = process_fetch_insn_bottom(arg->code + 1, val, NULL, NULL); + code = arg->code; + retry: + switch (code->op) { + case FETCH_OP_TP_ARG: + val = get_event_field(code, rec); + break; + case FETCH_OP_IMM: + val = code->immediate; + break; + case FETCH_OP_COMM: + val = (unsigned long)current->comm; + break; + case FETCH_OP_DATA: + val = (unsigned long)code->data; + break; + case FETCH_NOP_SYMBOL: /* Ignore a place holder */ + code++; + goto retry; + default: + continue; + } + code++; + len = process_fetch_insn_bottom(code, val, NULL, NULL); if (len > 0) ret += len; } @@ -366,8 +400,28 @@ process_fetch_insn(struct fetch_insn *co { unsigned long val; - val = get_event_field(code, rec); - return process_fetch_insn_bottom(code + 1, val, dest, base); + retry: + switch (code->op) { + case FETCH_OP_TP_ARG: + val = get_event_field(code, rec); + break; + case FETCH_OP_IMM: + val = code->immediate; + break; + case FETCH_OP_COMM: + val = (unsigned long)current->comm; + break; + case FETCH_OP_DATA: + val = (unsigned long)code->data; + break; + case FETCH_NOP_SYMBOL: /* Ignore a place holder */ + code++; + goto retry; + default: + return -EILSEQ; + } + code++; + return process_fetch_insn_bottom(code, val, dest, base); } NOKPROBE_SYMBOL(process_fetch_insn) @@ -849,6 +903,10 @@ static int trace_eprobe_tp_update_arg(st if (ep->tp.args[i].code->op == FETCH_OP_TP_ARG) ret = trace_eprobe_tp_arg_update(ep, i); + /* Handle symbols "@" */ + if (!ret) + ret = traceprobe_update_arg(&ep->tp.args[i]); + return ret; }