Fix: use of uninitialised bytes valgrind warning
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Wed, 16 Jun 2021 16:10:42 +0000 (12:10 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 16 Jun 2021 16:49:15 +0000 (12:49 -0400)
commite5d671a8da3f207a1e8031547ef4914cabe5ce4f
tree676d1e3769762d75ba5994c3d4decc345c7d03ee
parent71e2e361e570a4701e06694c6ffeceb3a81a01bd
Fix: use of uninitialised bytes valgrind warning

Issue
=====

Valgrind reports usage of uninitialised stack allocated memory:
  ==2961363== Thread 9 Client manageme:
  ==2961363== Syscall param sendmsg(msg.msg_iov[0]) points to uninitialised byte(s)
  ==2961363==    at 0x521418D: __libc_sendmsg (sendmsg.c:28)
  ==2961363==    by 0x521418D: sendmsg (sendmsg.c:25)
  ==2961363==    by 0x53411B: lttcomm_send_unix_sock (unix.c:294)
  ==2961363==    by 0x48AA8C: send_unix_sock (client.c:896)
  ==2961363==    by 0x484F45: thread_manage_clients (client.c:2865)
  ==2961363==    by 0x480FB4: launch_thread (thread.c:66)
  ==2961363==    by 0x5208608: start_thread (pthread_create.c:477)
  ==2961363==    by 0x5346292: clone (clone.S:95)
  ==2961363==  Address 0x7575389 is 25 bytes inside a block of size 16,384 alloc'd
  ==2961363==    at 0x483DFAF: realloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
  ==2961363==    by 0x4EB618: lttng_dynamic_buffer_set_capacity (dynamic-buffer.c:166)
  ==2961363==    by 0x4EB52C: lttng_dynamic_buffer_append (dynamic-buffer.c:55)
  ==2961363==    by 0x48CBA1: setup_lttng_msg (client.c:125)
  ==2961363==    by 0x48AD70: setup_lttng_msg_no_cmd_header (client.c:860)
  ==2961363==    by 0x489825: process_client_msg (client.c:2253)
  ==2961363==    by 0x484A97: thread_manage_clients (client.c:2807)
  ==2961363==    by 0x480FB4: launch_thread (thread.c:66)
  ==2961363==    by 0x5208608: start_thread (pthread_create.c:477)
  ==2961363==    by 0x5346292: clone (clone.S:95)
  ==2961363==  Uninitialised value was created by a stack allocation
  ==2961363==    at 0x485FE4: process_client_msg (client.c:928)

After some digging, I found that this warning was caused by the padding
of the `struct lttng_session_list_schedules_return` during the
`LTTNG_SESSION_LIST_ROTATION_SCHEDULES` command.

All the fields are of the stack allocated struct are initialised by the
designated initializer but the padding is not.

These padding bytes are reported by Valgrind as being used
uninitialised.

Fix
===

Remove the padding by adding the LTTNG_PACKED attribute to the nested
structs in `struct lttng_session_list_schedules_return`.

Notes
=====

In light of the actual root cause, this is stacktrace is not really
useful.

The realloc call to grow the buffer makes it hard to find what is the
actual uninitialised stack allocation because Valgrind reports the
realloc call as the problematic site.

I was able to track this issue by adding a "consuming" step in the
`lttng_dynamic_buffer_append()` function. This consuming step would sum
all the bytes of the `buf` parameter so as to force Valgrind to check
each byte and not wait until the `sendmsg()` call. This way, I was able
to get a more precise location of the root cause of the issue.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Ib4a729575e9117cf95716ad25e1417c833f4232b
include/lttng/rotate-internal.h
This page took 0.033015 seconds and 4 git commands to generate.