From: Mathieu Desnoyers Date: Wed, 12 May 2021 20:05:29 +0000 (-0400) Subject: Fix: validate whether event notifiers are supported by UST application X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=commitdiff_plain;h=27a3be486f8cc9364d4861b7d163ad3e1426e9b3 Fix: validate whether event notifiers are supported by UST application Considering that lttng-sessiond interacts with older (2.12) applications as well as 2.13+, it needs not to send event notifiers related commands to an older UST, because the unknown command will cause the protocol to become out of sync on the communication socket, because the older lttng-ust does not know how many bytes must be read when receiving the unknown command. So even though it can return that the command is unknown, the communication socket becomes out of sync. Depends-on: lttng-ust: If048c739dd37147ffb2a54715c2101177d2df4f7 Signed-off-by: Mathieu Desnoyers Signed-off-by: Jérémie Galarneau Change-Id: If9cbc7a7cd6cb957134bf3a2e284ab99ef20e93b --- diff --git a/src/bin/lttng-sessiond/event-notifier-error-accounting.c b/src/bin/lttng-sessiond/event-notifier-error-accounting.c index 47366e9e9..74b15bf98 100644 --- a/src/bin/lttng-sessiond/event-notifier-error-accounting.c +++ b/src/bin/lttng-sessiond/event-notifier-error-accounting.c @@ -381,6 +381,12 @@ struct ust_error_accounting_entry *ust_error_accounting_entry_create( .has_overflow = false, }; + if (!ust_app_supports_counters(app)) { + DBG("Refusing to create accounting entry for application (unsupported feature): app name = '%s', app ppid = %d", + app->name, (int) app->ppid); + goto error; + } + entry = zmalloc(sizeof(struct ust_error_accounting_entry)); if (!entry) { PERROR("Failed to allocate event notifier error acounting entry") @@ -586,6 +592,11 @@ event_notifier_error_accounting_register_app(struct ust_app *app) enum event_notifier_error_accounting_status status; struct lttng_ust_abi_object_data **cpu_counters; + if (!ust_app_supports_counters(app)) { + status = EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_UNSUPPORTED; + goto end; + } + /* * Check if we already have a error counter for the user id of this * app. If not, create one. @@ -688,7 +699,7 @@ event_notifier_error_accounting_register_app(struct ust_app *app) app->event_notifier_group.nr_counter_cpu = entry->nr_counter_cpu_fds; app->event_notifier_group.counter_cpu = cpu_counters; cpu_counters = NULL; - goto end; + goto end_unlock; error_send_cpu_counter_data: error_duplicate_cpu_counter: @@ -716,8 +727,9 @@ error_duplicate_counter: ust_error_accounting_entry_put(entry); error_creating_entry: app->event_notifier_group.counter = NULL; -end: +end_unlock: rcu_read_unlock(); +end: return status; } diff --git a/src/bin/lttng-sessiond/event-notifier-error-accounting.h b/src/bin/lttng-sessiond/event-notifier-error-accounting.h index d42fff650..319a488ae 100644 --- a/src/bin/lttng-sessiond/event-notifier-error-accounting.h +++ b/src/bin/lttng-sessiond/event-notifier-error-accounting.h @@ -21,6 +21,7 @@ enum event_notifier_error_accounting_status { EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_NOMEM, EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_NO_INDEX_AVAILABLE, EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_APP_DEAD, + EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_UNSUPPORTED, }; /* diff --git a/src/bin/lttng-sessiond/ust-app.c b/src/bin/lttng-sessiond/ust-app.c index f8668d88c..c00dd2877 100644 --- a/src/bin/lttng-sessiond/ust-app.c +++ b/src/bin/lttng-sessiond/ust-app.c @@ -4006,6 +4006,16 @@ int ust_app_version(struct ust_app *app) return ret; } +bool ust_app_supports_notifiers(const struct ust_app *app) +{ + return app->v_major >= 9; +} + +bool ust_app_supports_counters(const struct ust_app *app) +{ + return app->v_major >= 9; +} + /* * Setup the base event notifier group. * @@ -4022,6 +4032,11 @@ int ust_app_setup_event_notifier_group(struct ust_app *app) assert(app); + if (!ust_app_supports_notifiers(app)) { + ret = -ENOSYS; + goto error; + } + /* Get the write side of the pipe. */ event_pipe_write_fd = lttng_pipe_get_writefd( app->event_notifier_group.event_pipe); @@ -4071,14 +4086,20 @@ int ust_app_setup_event_notifier_group(struct ust_app *app) event_notifier_error_accounting_status = event_notifier_error_accounting_register_app(app); - if (event_notifier_error_accounting_status != EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_OK) { - if (event_notifier_error_accounting_status == EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_APP_DEAD) { - DBG3("Failed to setup event notifier error accounting (application is dead): app socket fd = %d", - app->sock); - ret = 0; - goto error_accounting; - } - + switch (event_notifier_error_accounting_status) { + case EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_OK: + break; + case EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_UNSUPPORTED: + DBG3("Failed to setup event notifier error accounting (application does not support notifier error accounting): app socket fd = %d, app name = '%s', app ppid = %d", + app->sock, app->name, (int) app->ppid); + ret = 0; + goto error_accounting; + case EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_APP_DEAD: + DBG3("Failed to setup event notifier error accounting (application is dead): app socket fd = %d, app name = '%s', app ppid = %d", + app->sock, app->name, (int) app->ppid); + ret = 0; + goto error_accounting; + default: ERR("Failed to setup event notifier error accounting for app"); ret = -1; goto error_accounting; @@ -5655,6 +5676,10 @@ void ust_app_synchronize_event_notifier_rules(struct ust_app *app) struct ust_app_event_notifier_rule *event_notifier_rule; unsigned int count, i; + if (!ust_app_supports_notifiers(app)) { + goto end; + } + /* * Currrently, registering or unregistering a trigger with an * event rule condition causes a full synchronization of the event @@ -5974,7 +5999,7 @@ void ust_app_global_update_event_notifier_rules(struct ust_app *app) DBG2("UST application global event notifier rules update: app = '%s' (ppid: %d)", app->name, app->ppid); - if (!app->compatible) { + if (!app->compatible || !ust_app_supports_notifiers(app)) { return; } diff --git a/src/bin/lttng-sessiond/ust-app.h b/src/bin/lttng-sessiond/ust-app.h index e0321cdc4..2b82aeec0 100644 --- a/src/bin/lttng-sessiond/ust-app.h +++ b/src/bin/lttng-sessiond/ust-app.h @@ -404,6 +404,9 @@ int ust_app_supported(void) return 1; } +bool ust_app_supports_notifiers(const struct ust_app *app); +bool ust_app_supports_counters(const struct ust_app *app); + #else /* HAVE_LIBLTTNG_UST_CTL */ static inline @@ -596,6 +599,16 @@ int ust_app_supported(void) return 0; } static inline +bool ust_app_supports_notifiers(const struct ust_app *app) +{ + return false; +} +static inline +bool ust_app_supports_counters(const struct ust_app *app) +{ + return false; +} +static inline struct ust_app *ust_app_find_by_sock(int sock) { return NULL;