From patchwork Mon Sep 20 16:44:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "gregkh@linuxfoundation.org" X-Patchwork-Id: 514380 Delivered-To: patch@linaro.org Received: by 2002:a02:c816:0:0:0:0:0 with SMTP id p22csp2344903jao; Mon, 20 Sep 2021 11:56:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwVwt7GKJqOk5bXrWzqrF1LhIb0ITvjrozLzeUkGTykpd0lmy3YOA16qAgKr6vQKKINoshr X-Received: by 2002:a17:906:6c87:: with SMTP id s7mr29934838ejr.186.1632164199270; Mon, 20 Sep 2021 11:56:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632164199; cv=none; d=google.com; s=arc-20160816; b=v210mgyKdQIYCF2yq5e1UuVgFNzG+5TV+e1MAywKVeLwt7l3O0VQcp6MHY5wJX8SF2 1KUTEJZ1heJyMsnnvF6N9LVR9ZGiUL0PtSqx3O/KgADsucePYTYVjVna6VEbKOiK1ciT 28M9yqq7fx1459PKDF1FT5s8WR2KHR7c7haL47s1mVuigsqkqEbG17+ZbOxgqxfXM/mG UFxrHvwdT4wqs4E3NhrwmAa/BI1TauwPun7cOUH8E86D+WI21opRXYA9RqNOr9DJMlnH QIhKngZqwlWvQWAxTaMlIjb2A999dQtzSnoQ7cQLD4KeDoJCHLEi5rq4iSrbqcJ7UAHX n9ww== 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=b+CB7V4x79rqHA08lLGi0JzStbEjBvg9W3WpuSj4BN0=; b=TqohK1E2KDLWDTcDKxMa+1USlEtwodQw/+ZGyiLY1oBE1PKpuWi69zIy9nCq0TBn0i GZGRk/8C7LIlG4f/nYk1b9qgZeePBXqmthQDMqz+mSYGz13XtEe7BXe10YSmCXs95+CL +zqXfArXj9qZ20u8T/c5PxmSjti6mEDuW4DFK92sffeKZBlopu/3nNZ3pYq5xW+TkLQu m/gUisOPjPiesWBni5qXfAX9eYgCyiJoc+cOPQNE3P/lgaAAXK4bPgQNTEZUgbMVOVF2 iSv+n0MRLvoZGFeI+k2gERBWixq5jdgAUF8nHtHXxPk2ztVSAe7uyqc9crqrkIXxJXtf LK8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=H28BmjKD; 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 y6si3332003edl.608.2021.09.20.11.56.39; Mon, 20 Sep 2021 11:56:39 -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=H28BmjKD; 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 S1387275AbhITS5A (ORCPT + 11 others); Mon, 20 Sep 2021 14:57:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:59830 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1384475AbhITSsQ (ORCPT ); Mon, 20 Sep 2021 14:48:16 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1DA9061361; Mon, 20 Sep 2021 17:33:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632159224; bh=P2LzhxgiADc6JDLSjbcXwytINfBo65K4kTBrzXO9+A8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H28BmjKDl+ShcowXix4QpvDyOjgY1/i6YvxfjAIoaDpWFx2itjrW9Z4m3yrVKY0Xs rIKQ87r0EWvFYVe2YvWRU7kbodSw2q92lQos5YryaYXzZ5BoUVeGUiMw7eR79SFXki WHnsKvjNvt26Rbg8zwU2Oh3OxuYgwsDczWgY/odk= 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.14 102/168] tracing/probes: Reject events which have the same name of existing one Date: Mon, 20 Sep 2021 18:44:00 +0200 Message-Id: <20210920163924.992956769@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163921.633181900@linuxfoundation.org> References: <20210920163921.633181900@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 ea6178cb5e33..032191977e34 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 15413ad7cef2..0e29bb14fc8b 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 227d518e5ba5..9f14186d132e 100644 --- a/kernel/trace/trace_probe.h +++ b/kernel/trace/trace_probe.h @@ -399,6 +399,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 9b50869a5ddb..957244ee07c8 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; }