From 71e0a100af7369c2a56db35af7b864eeb5ca4f48 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Thu, 3 May 2018 14:35:24 -0400 Subject: [PATCH] Enforce locking assumptions during channel creation 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/session.c | 8 ++++++++ src/bin/lttng-sessiond/session.h | 1 + src/bin/lttng-sessiond/ust-app.c | 7 +++++++ 3 files changed, 16 insertions(+) diff --git a/src/bin/lttng-sessiond/session.c b/src/bin/lttng-sessiond/session.c index 01cdfdc00..16431ca15 100644 --- a/src/bin/lttng-sessiond/session.c +++ b/src/bin/lttng-sessiond/session.c @@ -134,6 +134,14 @@ void session_lock_list(void) pthread_mutex_lock(<t_session_list.lock); } +/* + * Try to acquire session list lock + */ +int session_trylock_list(void) +{ + return pthread_mutex_trylock(<t_session_list.lock); +} + /* * Release session list lock */ diff --git a/src/bin/lttng-sessiond/session.h b/src/bin/lttng-sessiond/session.h index 3ace323ba..92e7a11ad 100644 --- a/src/bin/lttng-sessiond/session.h +++ b/src/bin/lttng-sessiond/session.h @@ -212,6 +212,7 @@ int session_destroy(struct ltt_session *session); void session_lock(struct ltt_session *session); void session_lock_list(void); +int session_trylock_list(void); void session_unlock(struct ltt_session *session); void session_unlock_list(void); diff --git a/src/bin/lttng-sessiond/ust-app.c b/src/bin/lttng-sessiond/ust-app.c index 8120b6df2..62971067c 100644 --- a/src/bin/lttng-sessiond/ust-app.c +++ b/src/bin/lttng-sessiond/ust-app.c @@ -2847,6 +2847,7 @@ error: * Create and send to the application the created buffers with per UID buffers. * * This MUST be called with a RCU read side lock acquired. + * The session list lock and the session's lock must be acquired. * * Return 0 on success else a negative value. */ @@ -2939,6 +2940,8 @@ static int create_channel_per_uid(struct ust_app *app, session = session_find_by_id(ua_sess->tracing_id); assert(session); + assert(pthread_mutex_trylock(&session->lock)); + assert(session_trylock_list()); cmd_ret = notification_thread_command_add_channel( notification_thread_handle, session->name, ua_sess->euid, ua_sess->egid, @@ -2970,6 +2973,7 @@ error: * Create and send to the application the created buffers with per PID buffers. * * Called with UST app session lock held. + * The session list lock and the session's lock must be acquired. * * Return 0 on success else a negative value. */ @@ -3032,6 +3036,9 @@ static int create_channel_per_pid(struct ust_app *app, chan_reg->consumer_key = ua_chan->key; pthread_mutex_unlock(®istry->lock); + assert(pthread_mutex_trylock(&session->lock)); + assert(session_trylock_list()); + cmd_ret = notification_thread_command_add_channel( notification_thread_handle, session->name, ua_sess->euid, ua_sess->egid, -- 2.34.1