Fix: validate whether event notifiers are supported by UST application
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 12 May 2021 20:05:29 +0000 (16:05 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 14 May 2021 18:10:22 +0000 (14:10 -0400)
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 <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: If9cbc7a7cd6cb957134bf3a2e284ab99ef20e93b

src/bin/lttng-sessiond/event-notifier-error-accounting.c
src/bin/lttng-sessiond/event-notifier-error-accounting.h
src/bin/lttng-sessiond/ust-app.c
src/bin/lttng-sessiond/ust-app.h

index 47366e9e9a95b75211281c3422489e51a2c586ab..74b15bf98a655c397436dbad532ca931d7493499 100644 (file)
@@ -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;
 }
 
index d42fff650d8cd5aeaeb7582b65e18910b6c4eaf0..319a488ae7e1412deb3d33b8ebc1c261dce8f033 100644 (file)
@@ -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,
 };
 
 /*
index f8668d88c4be34c043e6aaa2c87c4eda6aa6c0ee..c00dd2877fd08d1aed942ac1fce52ab4ff25d3c8 100644 (file)
@@ -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;
        }
 
index e0321cdc486a368b173860932e6ef539296be678..2b82aeec098c068b9ccc07e1e385eea511c42cf6 100644 (file)
@@ -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;
This page took 0.032505 seconds and 5 git commands to generate.