X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fcmd.c;h=0c34d163841dbc35db367173174a08ad2fc5117e;hb=87c6e3280d90742c27d20de37d64e8c075830b3a;hp=50ff1632fb1bc3439e3517cdd66cc5129ed85146;hpb=88f06f1562c6ecd3a5666baa93a57273fbe10437;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index 50ff1632f..0c34d1638 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -268,8 +268,7 @@ static int list_lttng_ust_global_events(char *channel_name, uchan = caa_container_of(&node->node, struct ltt_ust_channel, node.node); - nb_event += lttng_ht_get_count(uchan->events); - + nb_event = lttng_ht_get_count(uchan->events); if (nb_event == 0) { ret = nb_event; goto error; @@ -284,6 +283,11 @@ static int list_lttng_ust_global_events(char *channel_name, } cds_lfht_for_each_entry(uchan->events->ht, &iter.iter, uevent, node.node) { + if (uevent->internal) { + /* This event should remain hidden from clients */ + nb_event--; + continue; + } strncpy(tmp[i].name, uevent->attr.name, LTTNG_SYMBOL_NAME_LEN); tmp[i].name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0'; tmp[i].enabled = uevent->enabled; @@ -1415,6 +1419,36 @@ end: return ret; } +static inline bool name_starts_with(const char *name, const char *prefix) +{ + const size_t max_cmp_len = min(strlen(prefix), LTTNG_SYMBOL_NAME_LEN); + + return !strncmp(name, prefix, max_cmp_len); +} + +/* Perform userspace-specific event name validation */ +static int validate_ust_event_name(const char *name) +{ + int ret = 0; + + if (!name) { + ret = -1; + goto end; + } + + /* + * Check name against all internal UST event component namespaces used + * by the agents. + */ + if (name_starts_with(name, DEFAULT_JUL_EVENT_COMPONENT) || + name_starts_with(name, DEFAULT_LOG4J_EVENT_COMPONENT) || + name_starts_with(name, DEFAULT_PYTHON_EVENT_COMPONENT)) { + ret = -1; + } + +end: + return ret; +} static int cmd_enable_event_internal(struct ltt_session *session, struct lttng_domain *domain, @@ -1630,6 +1664,21 @@ static int _cmd_enable_event(struct ltt_session *session, assert(uchan); } + if (!internal_event) { + /* + * Ensure the event name is not reserved for internal + * use. + */ + ret = validate_ust_event_name(event->name); + if (ret) { + WARN("Userspace event name %s failed validation.", + event->name ? + event->name : "NULL"); + ret = LTTNG_ERR_INVALID_EVENT_NAME; + goto error; + } + } + /* At this point, the session and channel exist on the tracer */ ret = event_ust_enable_tracepoint(usess, uchan, event, filter_expression, filter, exclusion, @@ -1696,7 +1745,7 @@ static int _cmd_enable_event(struct ltt_session *session, default_chan_name = DEFAULT_PYTHON_CHANNEL_NAME; break; default: - /* The switch/case we are in should avoid this else big problem */ + /* The switch/case we are in makes this impossible */ assert(0); }