Skip to content

Commit

Permalink
tracing/probes: Handle system names with hyphens
Browse files Browse the repository at this point in the history
commit 575b76c upstream.

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/
Link: https://lore.kernel.org/linux-trace-kernel/20221122122345.160f5077@gandalf.local.home

Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: stable@vger.kernel.org
Fixes: 5b7a962 ("tracing/probe: Check event/group naming rule at parsing")
Reported-by: Rafael Mendonca <rafaelmendsr@gmail.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
rostedt authored and gregkh committed Jan 12, 2023
1 parent 2442e65 commit 17becbc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
19 changes: 16 additions & 3 deletions kernel/trace/trace.h
Expand Up @@ -1939,17 +1939,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)
{
Expand Down
2 changes: 1 addition & 1 deletion kernel/trace/trace_probe.c
Expand Up @@ -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;
}
Expand Down

0 comments on commit 17becbc

Please sign in to comment.