From patchwork Tue Nov 22 17:23:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 24474 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2346374wrr; Tue, 22 Nov 2022 09:31:58 -0800 (PST) X-Google-Smtp-Source: AA0mqf5a6DB+cQOCWg39Ln8Ru045P+LVD0sahjYTrQZ+TNRR/psO/W6JkpD0VpJOh/fCYj/aaSCC X-Received: by 2002:a17:907:1750:b0:7ad:8608:a0a1 with SMTP id lf16-20020a170907175000b007ad8608a0a1mr20601449ejc.110.1669138318730; Tue, 22 Nov 2022 09:31:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669138318; cv=none; d=google.com; s=arc-20160816; b=nzBgHtEMH1KA9D/nyGQsRjIOSNc4eAL2fRo4RQuUEcmSGXsN20K7FrfRyEX1Aej4Kh JLrKeBzc0D40qQI3uVnMSviSXE+XPtxLYeIlR1A10B6Kq9F/6647sGuTj4BGxZs1x+IH T7D5EceUsuUH27oF920xDA7ed7SrPTf6j4xE+dlNtqvjGJ2UQrDFmAK9+hGqZYSyuDL4 6EsUJbMjBM1kgOt3QgWOwdZwRyIr3wAJqRaDLMiCHiK083m5ynD+uuPWnFs1w8v+lQ6l 2wYkRKdvMU4eWr3WvIb9mnYoU9WDBkX3Z1eqUNqvqz4+cYJ22Q1KYzJdTu8R3G9Pi8dj k5sQ== 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=3bEWGSd1Eo1MdDw28Jt9B3ojGlm7NU3jyaFdcH3TO4E=; b=drqcf6cY8dHaXviQFaLLyEVrRg+UwN9Qh0fkwhc3E9E9g3A7w1ztPVkshqwLd42x4R 7DTJVXlHghStxVkadkZu2/lCqN7hIhzSk3IOeZnufTbhM/3xEpTr79xDYpPDk2f7Rmy5 Qit3JxIp167WFXsIbxf7YxUaozbCA0rz2YXFqnnjS6p45KRasW8hS0KVRuG9o1lh6o5B p4EvwQM6unjk9ML9hBxexa09ht5SOuXIYr696iXjz4JzkO4RKL0d5UYi9cw8OkMof8PR EU4y62mbuBy14z/s4Gc+JOsMQ5GEWWA0oWKMApxi4556Xiw7C50/h9/Gb8d2AFy/cz5T 7tdQ== 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 s11-20020a170906a18b00b00783e7d72fc0si11171439ejy.272.2022.11.22.09.31.34; Tue, 22 Nov 2022 09:31:58 -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 S233941AbiKVRYD (ORCPT + 99 others); Tue, 22 Nov 2022 12:24:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234504AbiKVRXy (ORCPT ); Tue, 22 Nov 2022 12:23:54 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6674B77208; Tue, 22 Nov 2022 09:23:48 -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 01FEF61765; Tue, 22 Nov 2022 17:23:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EDEEBC433C1; Tue, 22 Nov 2022 17:23:46 +0000 (UTC) Date: Tue, 22 Nov 2022 12:23:45 -0500 From: Steven Rostedt To: LKML , Linux Trace Kernel Cc: Masami Hiramatsu , Rafael Mendonca Subject: [PATCH] tracing/probes: Handle system names with hyphens Message-ID: <20221122122345.160f5077@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?1750218381318499467?= X-GMAIL-MSGID: =?utf-8?q?1750218381318499467?= From: "Steven Rostedt (Google)" When creating probe names, a check is done to make sure it matches basic C standard variable naming standards. Basically, starts with alphabetic or underline, and then the rest of the characters have alpha-numeric or underline in them. But system names do not have any true naming conventions, as they are created by the TRACE_SYSTEM macro and nothing tests to see what they are. The "xhci-hcd" trace events has a '-' in the system name. When trying to attach a eprobe to one of these trace points, it fails because the system name does not follow the variable naming convention because of the hyphen, and the eprobe checks fail on this. Allow hyphens in the system name so that eprobes can attach to the "xhci-hcd" trace events. Link: https://lore.kernel.org/all/Y3eJ8GiGnEvVd8%2FN@macondo/ Cc: stable@vger.kernel.org Fixes: 5b7a96220900e ("tracing/probe: Check event/group naming rule at parsing") Reported-by: Rafael Mendonca Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace.h | 19 ++++++++++++++++--- kernel/trace/trace_probe.c | 2 +- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index 54ee5711c729..a16fb4c9642e 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -1955,17 +1955,30 @@ static __always_inline void trace_iterator_reset(struct trace_iterator *iter) } /* Check the name is good for event/group/fields */ -static inline bool is_good_name(const char *name) +static inline bool __is_good_name(const char *name, bool hash_ok) { - if (!isalpha(*name) && *name != '_') + if (!isalpha(*name) && *name != '_' && (!hash_ok || *name != '-')) return false; while (*++name != '\0') { - if (!isalpha(*name) && !isdigit(*name) && *name != '_') + if (!isalpha(*name) && !isdigit(*name) && *name != '_' && + (!hash_ok || *name != '-')) return false; } return true; } +/* Check the name is good for event/group/fields */ +static inline bool is_good_name(const char *name) +{ + return __is_good_name(name, false); +} + +/* Check the name is good for system */ +static inline bool is_good_system_name(const char *name) +{ + return __is_good_name(name, true); +} + /* Convert certain expected symbols into '_' when generating event names */ static inline void sanitize_event_name(char *name) { diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c index 36dff277de46..bb2f95d7175c 100644 --- a/kernel/trace/trace_probe.c +++ b/kernel/trace/trace_probe.c @@ -246,7 +246,7 @@ int traceprobe_parse_event_name(const char **pevent, const char **pgroup, return -EINVAL; } strlcpy(buf, event, slash - event + 1); - if (!is_good_name(buf)) { + if (!is_good_system_name(buf)) { trace_probe_log_err(offset, BAD_GROUP_NAME); return -EINVAL; }