From patchwork Mon Sep 20 16:43:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 514366 Delivered-To: patch@linaro.org Received: by 2002:a02:c816:0:0:0:0:0 with SMTP id p22csp2328442jao; Mon, 20 Sep 2021 11:35:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzaPZMxMYAADQCcn64YclGatzmJCuPbJveFhtovQKECAVU8b3floFhCwYxAaS0m4EkjLb6V X-Received: by 2002:a05:6402:1241:: with SMTP id l1mr30123502edw.123.1632162957532; Mon, 20 Sep 2021 11:35:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632162957; cv=none; d=google.com; s=arc-20160816; b=IVFDRGateEo03qb+rbrKDIgzNAq7jFO3QKQfZx6wac4AR6ezv93L8YkE6TDkTLULie AyUCDP6vUOJuXyn+BdhY3NoCVb4Tbh77AipM91g1TQ64W9spnL/jmk41BnOG26fM6JPv 0RbBKqQdQi+iG7n7W+XXNpNYxBZ2PYh6BzB1fUDe5o7mQB6KjXJtrbQ4pNOY2wnPh32f JbeJd3k13UYQPjVE6a+c2x7/1CMwjv1rSS/uJCmDnoHr4lJW3GZmvutEZ8f4AODHsHsc TzsB+7oblPWh8gZZWtOb5Qu3aK80NoFP/ihEXrSsOr7xtQnjtov+u4ermXQIR5JO5DPL OY2Q== 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=awaGI3bddXuTeYVkWtQV7zAYElVWqNzaLTk3bnaW08Y=; b=hGgepGj1yjOh1uUQwr6GzwCKzWhWVvbrKEOiDNYT2GNwrmnG5rBBM5txRL8pvrzQsm BlfHACc4SYk2qYVi4h/VP/Q4tBVPCJy36twshSKNAflDOCwah6rurDDcr/tx4Yrl14Od cP2pd3xXSml6L0f8On7gHv9OFrjWdUrVTCeMzNrijmXpxQlyiX0wTQu9pJapnnmMBb40 17inThXOfYp9Jx4Ifa1+kJiBKs0YZufF4vQSft8cfRbjKK3JDZF9xTcbgA2+DZJkeDME QEG17z48DtLW+bZua38dtVS2/wCm3PkbtT3JCcW+JunAvJrGSdmvrQPxExKjQqd/hL/F I+SA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=keQ0D1LH; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b1si21572484ejb.600.2021.09.20.11.35.57; Mon, 20 Sep 2021 11:35:57 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=keQ0D1LH; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-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 S1379167AbhITSgQ (ORCPT + 11 others); Mon, 20 Sep 2021 14:36:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:49304 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380111AbhITSce (ORCPT ); Mon, 20 Sep 2021 14:32:34 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B0C6461AA7; Mon, 20 Sep 2021 17:27:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632158878; bh=LFNy3iIa87mVaeGgL4yMp5NJGuXQztt4Sr4cbRdUIVI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=keQ0D1LHzM/hjj4bZ0BiSktKF/0eX+olGaZzDeOKCLM6xPmpdePexwOB6XvDwyPeh y6mOrkN0kbO6prSoa5z53beuxpUhnW/UYk0XXPHsoUyubuaIbCqwDOgZdYSitdtClL VT/DQJ7mxCvuRkJ7GNsedFfGkyYz/HC8MUd71AdA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Masami Hiramatsu , "Steven Rostedt (VMware)" , Sasha Levin Subject: [PATCH 5.10 064/122] tracing/probes: Reject events which have the same name of existing one Date: Mon, 20 Sep 2021 18:43:56 +0200 Message-Id: <20210920163917.876178732@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163915.757887582@linuxfoundation.org> References: <20210920163915.757887582@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Masami Hiramatsu [ Upstream commit 8e242060c6a4947e8ae7d29794af6a581db08841 ] Since kprobe_events and uprobe_events only check whether the other same-type probe event has the same name or not, if the user gives the same name of the existing tracepoint event (or the other type of probe events), it silently fails to create the tracefs entry (but registered.) as below. /sys/kernel/tracing # ls events/task/task_rename enable filter format hist id trigger /sys/kernel/tracing # echo p:task/task_rename vfs_read >> kprobe_events [ 113.048508] Could not create tracefs 'task_rename' directory /sys/kernel/tracing # cat kprobe_events p:task/task_rename vfs_read To fix this issue, check whether the existing events have the same name or not in trace_probe_register_event_call(). If exists, it rejects to register the new event. Link: https://lkml.kernel.org/r/162936876189.187130.17558311387542061930.stgit@devnote2 Signed-off-by: Masami Hiramatsu Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Sasha Levin --- kernel/trace/trace_kprobe.c | 6 +++++- kernel/trace/trace_probe.c | 25 +++++++++++++++++++++++++ kernel/trace/trace_probe.h | 1 + kernel/trace/trace_uprobe.c | 6 +++++- 4 files changed, 36 insertions(+), 2 deletions(-) -- 2.30.2 diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c index 68150b9cbde9..552dbc9d5226 100644 --- a/kernel/trace/trace_kprobe.c +++ b/kernel/trace/trace_kprobe.c @@ -647,7 +647,11 @@ static int register_trace_kprobe(struct trace_kprobe *tk) /* Register new event */ ret = register_kprobe_event(tk); if (ret) { - pr_warn("Failed to register probe event(%d)\n", ret); + if (ret == -EEXIST) { + trace_probe_log_set_index(0); + trace_probe_log_err(0, EVENT_EXIST); + } else + pr_warn("Failed to register probe event(%d)\n", ret); goto end; } diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c index d2867ccc6aca..1d31bc4acf7a 100644 --- a/kernel/trace/trace_probe.c +++ b/kernel/trace/trace_probe.c @@ -1029,11 +1029,36 @@ error: return ret; } +static struct trace_event_call * +find_trace_event_call(const char *system, const char *event_name) +{ + struct trace_event_call *tp_event; + const char *name; + + list_for_each_entry(tp_event, &ftrace_events, list) { + if (!tp_event->class->system || + strcmp(system, tp_event->class->system)) + continue; + name = trace_event_name(tp_event); + if (!name || strcmp(event_name, name)) + continue; + return tp_event; + } + + return NULL; +} + int trace_probe_register_event_call(struct trace_probe *tp) { struct trace_event_call *call = trace_probe_event_call(tp); int ret; + lockdep_assert_held(&event_mutex); + + if (find_trace_event_call(trace_probe_group_name(tp), + trace_probe_name(tp))) + return -EEXIST; + ret = register_trace_event(&call->event); if (!ret) return -ENODEV; diff --git a/kernel/trace/trace_probe.h b/kernel/trace/trace_probe.h index 2f703a20c724..6d41e20c47ce 100644 --- a/kernel/trace/trace_probe.h +++ b/kernel/trace/trace_probe.h @@ -398,6 +398,7 @@ extern int traceprobe_define_arg_fields(struct trace_event_call *event_call, C(NO_EVENT_NAME, "Event name is not specified"), \ C(EVENT_TOO_LONG, "Event name is too long"), \ C(BAD_EVENT_NAME, "Event name must follow the same rules as C identifiers"), \ + C(EVENT_EXIST, "Given group/event name is already used by another event"), \ C(RETVAL_ON_PROBE, "$retval is not available on probe"), \ C(BAD_STACK_NUM, "Invalid stack number"), \ C(BAD_ARG_NUM, "Invalid argument number"), \ diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c index 3cf7128e1ad3..0dd6e286e519 100644 --- a/kernel/trace/trace_uprobe.c +++ b/kernel/trace/trace_uprobe.c @@ -514,7 +514,11 @@ static int register_trace_uprobe(struct trace_uprobe *tu) ret = register_uprobe_event(tu); if (ret) { - pr_warn("Failed to register probe event(%d)\n", ret); + if (ret == -EEXIST) { + trace_probe_log_set_index(0); + trace_probe_log_err(0, EVENT_EXIST); + } else + pr_warn("Failed to register probe event(%d)\n", ret); goto end; }