From 9642d9bf3d80d6a45ecdd107ff12c676b5ef0870 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Thu, 2 Apr 2020 15:47:30 -0400 Subject: [PATCH 1/1] Fix: relayd: assertion fails on creation of session by peer < 2.11 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Observed issue ============== An assertion that a chunk has no active directory handle fails when creating an anonymous chunk. More specifically, this occurs when associating an fd tracker to the newly created anonymous trace chunk. This occurs when a session is created by a peer that is older than 2.11. Cause ===== Trace chunks that should monitor their file descriptors with a file descriptor tracker must be associated with the tracker before any other operation occurs on the chunk. This is to ensure that "raw" file descriptors are not created when they were meant to be tracked. Here, the credentials and session output directory are set before the file descriptor tracker was provided to the anonymous chunk which is a breach of the API contract (enforced by the assert()). Solution ======== Associate the fd tracker immediately to the anonymous chunk before providing it with a reference to the file descriptor tracker. Moreover, a leak of the output_directory is prevented by not setting it to NULL. The trace chunk will acquire a reference to the trace chunk; it is not transferred to the trace chunk. Note ==== The problem was introduced during the 2.12 release cycle (clear feature); this doesn't need to be backported. Signed-off-by: Jérémie Galarneau Change-Id: I92ca2f156f500dfe02e09f8b4783447e46710246 --- src/bin/lttng-relayd/session.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/bin/lttng-relayd/session.c b/src/bin/lttng-relayd/session.c index f40f70965..9f690d3af 100644 --- a/src/bin/lttng-relayd/session.c +++ b/src/bin/lttng-relayd/session.c @@ -220,6 +220,7 @@ static int session_set_anonymous_chunk(struct relay_session *session) goto end; } + lttng_trace_chunk_set_fd_tracker(chunk, the_fd_tracker); status = lttng_trace_chunk_set_credentials_current_user(chunk); if (status != LTTNG_TRACE_CHUNK_STATUS_OK) { ret = -1; @@ -232,8 +233,6 @@ static int session_set_anonymous_chunk(struct relay_session *session) goto end; } - lttng_trace_chunk_set_fd_tracker(chunk, the_fd_tracker); - output_directory = NULL; session->current_trace_chunk = chunk; chunk = NULL; end: -- 2.34.1