From: Mathieu Desnoyers Date: Mon, 22 Mar 2021 14:01:55 +0000 (-0400) Subject: Validate match of all session channel's UUID X-Git-Tag: v2.13.0-rc1~236 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=9daacd1a32798bcef31f13cf45a3aab25bdc67af;p=lttng-ust.git Validate match of all session channel's UUID Add a validation at channel creation to ensure that the uuid of all channels created within a session match. Note that we still need to keep a copy of the uuid field in the channel private data at this stage, because the consumer daemon creates channels with a NULL session pointer. Signed-off-by: Mathieu Desnoyers Change-Id: I3490bab8879ffa66bc1e19559b0a1a60d33d605b --- diff --git a/liblttng-ust/lttng-events.c b/liblttng-ust/lttng-events.c index 9c65dc45..70e2f3a9 100644 --- a/liblttng-ust/lttng-events.c +++ b/liblttng-ust/lttng-events.c @@ -2019,3 +2019,21 @@ void lttng_ust_context_set_event_notifier_group_provider(const char *name, abort(); } } + +int lttng_ust_session_uuid_validate(struct lttng_ust_session *session, + unsigned char *uuid) +{ + if (!session) + return 0; + /* Compare UUID with session. */ + if (session->priv->uuid_set) { + if (memcmp(session->priv->uuid, uuid, LTTNG_UST_UUID_LEN)) { + return -1; + } + } else { + memcpy(session->priv->uuid, uuid, LTTNG_UST_UUID_LEN); + session->priv->uuid_set = true; + } + return 0; + +} diff --git a/liblttng-ust/lttng-ust-abi.c b/liblttng-ust/lttng-ust-abi.c index 53ca5dbe..af2a47dc 100644 --- a/liblttng-ust/lttng-ust-abi.c +++ b/liblttng-ust/lttng-ust-abi.c @@ -502,6 +502,11 @@ int lttng_abi_map_channel(int session_objd, goto alloc_error; } + if (lttng_ust_session_uuid_validate(session, lttng_chan_config->uuid)) { + ret = -EINVAL; + goto uuid_error; + } + /* Lookup transport name */ switch (type) { case LTTNG_UST_ABI_CHAN_PER_CPU: @@ -578,6 +583,7 @@ int lttng_abi_map_channel(int session_objd, /* error path after channel was created */ objd_error: notransport: +uuid_error: alloc_error: channel_destroy(chan, channel_handle, 0); lttng_ust_free_channel_common(lttng_chan_buf->parent); diff --git a/liblttng-ust/ust-events-internal.h b/liblttng-ust/ust-events-internal.h index 6ade956e..f6ab27a2 100644 --- a/liblttng-ust/ust-events-internal.h +++ b/liblttng-ust/ust-events-internal.h @@ -332,6 +332,9 @@ struct lttng_ust_session_private { struct lttng_ust_enum_ht enums_ht; /* ht of enumerations */ struct cds_list_head enums_head; struct lttng_ust_ctx *ctx; /* contexts for filters. */ + + unsigned char uuid[LTTNG_UST_UUID_LEN]; /* Trace session unique ID */ + bool uuid_set; /* Is uuid set ? */ }; struct lttng_enum { @@ -893,4 +896,8 @@ int lttng_ust_interpret_event_filter(struct lttng_ust_event_common *event, const char *interpreter_stack_data, void *filter_ctx); +__attribute__((visibility("hidden"))) +int lttng_ust_session_uuid_validate(struct lttng_ust_session *session, + unsigned char *uuid); + #endif /* _LTTNG_UST_EVENTS_INTERNAL_H */