From 2223c96f0eecce28fe221eb19de4333156492337 Mon Sep 17 00:00:00 2001 From: David Goulet Date: Tue, 22 Jan 2013 12:13:13 -0500 Subject: [PATCH] Fix: add missing rcu lock for UST lookup Trace UST channel and event were not protected by RCU lock when calling their find function. Furthermore, the event lookup was not protected at all during and after the lookup. Signed-off-by: David Goulet --- src/bin/lttng-sessiond/cmd.c | 18 ++++++++++++++++++ src/bin/lttng-sessiond/context.c | 3 +++ src/bin/lttng-sessiond/trace-ust.c | 9 ++++----- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index 5ec65b786..456ddeb77 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -766,6 +766,8 @@ int cmd_disable_channel(struct ltt_session *session, int domain, usess = session->ust_session; + rcu_read_lock(); + switch (domain) { case LTTNG_DOMAIN_KERNEL: { @@ -810,6 +812,7 @@ int cmd_disable_channel(struct ltt_session *session, int domain, ret = LTTNG_OK; error: + rcu_read_unlock(); return ret; } @@ -830,6 +833,8 @@ int cmd_enable_channel(struct ltt_session *session, DBG("Enabling channel %s for session %s", attr->name, session->name); + rcu_read_lock(); + switch (domain) { case LTTNG_DOMAIN_KERNEL: { @@ -898,6 +903,7 @@ int cmd_enable_channel(struct ltt_session *session, } error: + rcu_read_unlock(); return ret; } @@ -910,6 +916,8 @@ int cmd_disable_event(struct ltt_session *session, int domain, { int ret; + rcu_read_lock(); + switch (domain) { case LTTNG_DOMAIN_KERNEL: { @@ -968,6 +976,7 @@ int cmd_disable_event(struct ltt_session *session, int domain, ret = LTTNG_OK; error: + rcu_read_unlock(); return ret; } @@ -979,6 +988,8 @@ int cmd_disable_event_all(struct ltt_session *session, int domain, { int ret; + rcu_read_lock(); + switch (domain) { case LTTNG_DOMAIN_KERNEL: { @@ -1037,6 +1048,7 @@ int cmd_disable_event_all(struct ltt_session *session, int domain, ret = LTTNG_OK; error: + rcu_read_unlock(); return ret; } @@ -1126,6 +1138,8 @@ int cmd_enable_event(struct ltt_session *session, int domain, assert(event); assert(channel_name); + rcu_read_lock(); + switch (domain) { case LTTNG_DOMAIN_KERNEL: { @@ -1224,6 +1238,7 @@ int cmd_enable_event(struct ltt_session *session, int domain, ret = LTTNG_OK; error: + rcu_read_unlock(); return ret; } @@ -1240,6 +1255,8 @@ int cmd_enable_event_all(struct ltt_session *session, int domain, assert(session); assert(channel_name); + rcu_read_lock(); + switch (domain) { case LTTNG_DOMAIN_KERNEL: { @@ -1371,6 +1388,7 @@ int cmd_enable_event_all(struct ltt_session *session, int domain, ret = LTTNG_OK; error: + rcu_read_unlock(); return ret; } diff --git a/src/bin/lttng-sessiond/context.c b/src/bin/lttng-sessiond/context.c index c1b7410da..46e1b3446 100644 --- a/src/bin/lttng-sessiond/context.c +++ b/src/bin/lttng-sessiond/context.c @@ -241,6 +241,8 @@ int context_ust_add(struct ltt_ust_session *usess, int domain, assert(ctx); assert(channel_name); + rcu_read_lock(); + /* * Define which channel's hashtable to use from the domain or quit if * unknown domain. @@ -303,5 +305,6 @@ int context_ust_add(struct ltt_ust_session *usess, int domain, } error: + rcu_read_unlock(); return ret; } diff --git a/src/bin/lttng-sessiond/trace-ust.c b/src/bin/lttng-sessiond/trace-ust.c index 81cb4db63..e07d27e67 100644 --- a/src/bin/lttng-sessiond/trace-ust.c +++ b/src/bin/lttng-sessiond/trace-ust.c @@ -116,7 +116,8 @@ no_match: } /* - * Find the channel in the hashtable. + * Find the channel in the hashtable and return channel pointer. RCU read side + * lock MUST be acquired before calling this. */ struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht, char *name) @@ -124,14 +125,11 @@ struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht, struct lttng_ht_node_str *node; struct lttng_ht_iter iter; - rcu_read_lock(); lttng_ht_lookup(ht, (void *)name, &iter); node = lttng_ht_iter_get_node_str(&iter); if (node == NULL) { - rcu_read_unlock(); goto error; } - rcu_read_unlock(); DBG2("Trace UST channel %s found by name", name); @@ -143,7 +141,8 @@ error: } /* - * Find the event in the hashtable. + * Find the event in the hashtable and return event pointer. RCU read side lock + * MUST be acquired before calling this. */ struct ltt_ust_event *trace_ust_find_event(struct lttng_ht *ht, char *name, struct lttng_filter_bytecode *filter, int loglevel) -- 2.34.1