From c810029902dacbb0aca6106c4c161acbf6382816 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Sun, 23 Aug 2015 00:27:34 -0400 Subject: [PATCH] Prevent the use of reserved UST event names MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- src/bin/lttng-sessiond/cmd.c | 45 ++++++++++++++++++++++++++++++++++++ src/common/defaults.h | 7 +++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index c26e5163c..5aff25d2a 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -1409,6 +1409,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, @@ -1624,6 +1654,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, diff --git a/src/common/defaults.h b/src/common/defaults.h index a0a582a01..d1cec3458 100644 --- a/src/common/defaults.h +++ b/src/common/defaults.h @@ -168,17 +168,22 @@ /* Default JUL tracepoint name. This is a wildcard for the JUL domain. */ #define DEFAULT_SYS_JUL_EVENT_NAME "lttng_jul:sys*" #define DEFAULT_USER_JUL_EVENT_NAME "lttng_jul:user*" +#define DEFAULT_JUL_EVENT_COMPONENT "lttng_jul" +#define DEFAULT_JUL_EVENT_NAME DEFAULT_JUL_EVENT_COMPONENT ":*" /* Default log4j domain channel name. */ #define DEFAULT_LOG4J_CHANNEL_NAME "lttng_log4j_channel" /* Default log4j tracepoint name. This is a wildcard for the log4j domain. */ #define DEFAULT_SYS_LOG4J_EVENT_NAME "lttng_log4j:sys*" #define DEFAULT_USER_LOG4J_EVENT_NAME "lttng_log4j:user*" +#define DEFAULT_LOG4J_EVENT_COMPONENT "lttng_log4j" +#define DEFAULT_LOG4J_EVENT_NAME DEFAULT_LOG4J_EVENT_COMPONENT ":*" /* Default Python domain channel name. */ #define DEFAULT_PYTHON_CHANNEL_NAME "lttng_python_channel" /* Default Python tracepoint name. This is a wildcard for the python domain. */ -#define DEFAULT_PYTHON_EVENT_NAME "lttng_python:*" +#define DEFAULT_PYTHON_EVENT_COMPONENT "lttng_python" +#define DEFAULT_PYTHON_EVENT_NAME DEFAULT_PYTHON_EVENT_COMPONENT ":*" #define DEFAULT_CHANNEL_OVERWRITE 0 #define DEFAULT_CHANNEL_TRACEFILE_SIZE 0 -- 2.34.1