Skip to contentSkip to conversation

Fix: lttng-consumerd crash due to double free metadata stream

PATCH Jonathan Rajotte-Julien 1 participant 2 messages Sep 28, 2017 – Oct 11, 2017 2 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

Hi Liguang,

Thanks for submitting the patch.

Quoted 2 lines · Liguang Li

When setup metadata failed, the exception handling function will free the metadata stream twice.

This is lacking context and a good explanation of the problem at hand. Providing a good reproducer is a good first step to allow easier review of patches. This also remove uncertainty on the origin of the issue at the first place.

In this case, I'll assume that the issue happen when the call to lttng_pipe_write inside send_stream_to_thread fails. I would be even more interested on the conditions(scenario) required for this call to fail in the first place. It would be nice if you could provide more information regarding that.

Still, faking a failure on lttng_pipe_write when a metadata stream is to be sent allows me to reproduce an issue similar to the one you are describing.

Quoted 38 lines
---
 src/common/ust-consumer/ust-consumer.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
src/common/ust-consumer/ust-consumer.c +3 -3
index 366f855..3836ef9 100644
@@ -234,6 +234,8 @@ static int send_stream_to_thread(struct lttng_consumer_stream *stream,
 		ERR("Consumer write %s stream to pipe %d",
 				stream->metadata_flag ? "metadata" : "data",
 				lttng_pipe_get_writefd(stream_pipe));
+		/* Remove node from the channel stream list. */
+		cds_list_del(&stream->send_node);
 		if (stream->metadata_flag) {
 			consumer_del_stream_for_metadata(stream);
 		} else {
@@ -721,8 +723,6 @@ static int send_streams_to_thread(struct lttng_consumer_channel *channel,
 			 * If we are unable to send the stream to the thread, there is
 			 * a big problem so just stop everything.
 			 */
-			/* Remove node from the channel stream list. */
-			cds_list_del(&stream->send_node);
 			goto error;
 		}
 
@@ -925,7 +925,7 @@ static int setup_metadata(struct lttng_consumer_local_data *ctx, uint64_t key)
 		 * a big problem so just stop everything.
 		 */
 		ret = LTTCOMM_CONSUMERD_FATAL;
-		goto error;
+		goto end;
 	}
 	/* List MUST be empty after or else it could be reused. */
 	assert(cds_list_empty(&metadata->streams.head));

src/common/ust-consumer/ust-consumer.c error: · line 948

Quoted 10 lines
src/common/ust-consumer/ust-consumer.c +5 -1
@@ -940,8 +940,14 @@ error:
 	 * the stream is still in the local stream list of the channel. This call
 	 * will make sure to clean that list.
 	 */
-	consumer_stream_destroy(metadata->metadata_stream, NULL);
 	cds_list_del(&metadata->metadata_stream->send_node);
+
+	/* Destroy tracer buffers of the stream. */
+	consumer_stream_destroy_buffers(metadata->metadata_stream);
+	/* Close down everything including the relayd if one. */
+	consumer_stream_close(metadata->metadata_stream);

Those two calls are already performed inside destroy_close_stream() which is always called inside consumer_stream_destroy(). No need to perform them.

You can find a reworked version of this fix here [1]. Could you validate that it does indeed fixes the issue?

[1] https://lists.lttng.org/pipermail/lttng-dev/2017-September/027488.html

Quoted 12 lines
src/common/ust-consumer/ust-consumer.c +2 -0
+
+	consumer_stream_destroy(metadata->metadata_stream, NULL);
 	metadata->metadata_stream = NULL;
 error_no_stream:
 end:
Signature · 6 lines
2.7.4

_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
Signature · 6 lines
Jonathan Rajotte-Julien
EfficiOS
_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

A message that is not in the archive (sent off-list or not yet received): 20170928205742.rm66aato6q3vsilq@psrcode-TP-X230

#3 lore raw

Hi,

Quoted 22 lines · Jonathan Rajotte-Julien

Hi Liguang,

Thanks for submitting the patch.

Quoted 2 lines · Liguang Li

When setup metadata failed, the exception handling function will free the metadata stream twice.

This is lacking context and a good explanation of the problem at hand. Providing a good reproducer is a good first step to allow easier review of patches. This also remove uncertainty on the origin of the issue at the first place.

In this case, I'll assume that the issue happen when the call to lttng_pipe_write inside send_stream_to_thread fails. I would be even more interested on the conditions(scenario) required for this call to fail in the first place. It would be nice if you could provide more information regarding that.

Still, faking a failure on lttng_pipe_write when a metadata stream is to be sent allows me to reproduce an issue similar to the one you are describing.

Quoted 8 lines

Those two calls are already performed inside destroy_close_stream() which is always called inside consumer_stream_destroy(). No need to perform them.

You can find a reworked version of this fix here [1]. Could you validate that it does indeed fixes the issue?

[1] https://lists.lttng.org/pipermail/lttng-dev/2017-September/027488.html

Any feedback regarding the provided patch?

Cheers

Signature · 6 lines
Jonathan Rajotte-Julien
EfficiOS
_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev