Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2352366pxb; Mon, 20 Sep 2021 19:49:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZOTNWMHkT1QHurTuR4ou4UPf41S8Wr12BI+KXew8/7NzTrm2GPH0JpY3MZOHwUwfuBmsp X-Received: by 2002:a5e:c741:: with SMTP id g1mr3982172iop.67.1632192568906; Mon, 20 Sep 2021 19:49:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632192568; cv=none; d=google.com; s=arc-20160816; b=yAhjLacu/pXggX044I1hwSxh/Q8iQR3QPaGFPSCUko0LJFSmn8nry773oU3A+cmK47 BTgEOEPJwfyfjhXSzKahnnvHXKsFc3ubLFd3jpWXTl19j4PK5tjgf3wZELxn4QFjtDoj Vqn3wXDjAQJGH4V1dYF6OV6afQFcHRhRN+ruWjL+s9w6V6sDOihXA1PO04m+xSFKzbTY cwHDP9mETGztD69WsJRejcob1oF1qvtQtzPU7+6ofa6mCWZDi5cHGPM2iZZuNJbLlW+L 2sZ9u4rfFTfE0PnCvKN9eORBKaHaREChtdr4robFFLMOYIPt1kY9evvfii2xZxfU/SkM dLtA== 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=fobzzg4KzgwdZPzYssAROjakpBh4VPJvhzTvRKCZH9EYZnws+biYbMxCjDEoGO5MUX 5yl0BS+ozWkGRaS+Spp8KbFEzjIkq9IMxaJ6b/dyoHMM2rAwxeOYJizP9l3i0/M0TYSE Z4DR+K0r/sv2YujUCQjjJdPeOAQY6Mgy1mJjJXVD5KdHJzw+aLi6DcnJRpPW6ZzUtMTi mhf0GuoAJcZANIb1FCK+rzWldAmfzuXSlASWjXv1S8kL9EY/oqWZs+ZMK+1a7Bp+M3Vw Pj2a5i9AqsLDa8jgdzjA4XtOOpV5kCqyIjG2P3s0S8BNgmrfRlV4kVoDG9oDr3W3WXJf vijQ== 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 linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 205si5227601ioc.95.2021.09.20.19.49.17; Mon, 20 Sep 2021 19:49:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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 linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1353333AbhITSim (ORCPT + 99 others); Mon, 20 Sep 2021 14:38:42 -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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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(-) 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; } -- 2.30.2