[lttng-dev] [PATCH lttng-tools 2/2] Fix: handle syscall table resizing if nbmem is equal to zero

Mathieu Desnoyers mathieu.desnoyers at efficios.com
Tue Mar 14 01:25:40 UTC 2017



----- On Mar 13, 2017, at 6:13 PM, Jonathan Rajotte jonathan.rajotte-julien at efficios.com wrote:

> LTTng-modules returns indexes starting from zero. Hence, if nbmem is zero
> and index is zero the table will fail to grow to contain one
> element.
> 
> This situation should never happen since nbmem is assigned the value of
> SYSCALL_TABLE_INIT_SIZE which is 256 currently.

This changelog does not explain the issue at hand. The case of nbmem == 0
does not happen in this code, it's just an easy way to show the underlying
issue.

We could modify this patch subject to:

Fix: index off-by-one in syscall_init_table()

And describe as:

The index value returned by fscanf is an index starting at 0.
However, it is later used to count how many elements need to be
allocated, without any extra increment.

It does not cause issues in practice because SYSCALL_TABLE_INIT_SIZE
is nonzero, and because we don't require the table to expand by more
than the double of its size at once (which could happen if we could
have a hole in the syscall table for instance).

It's better to fix this off-by-one for clarity, and in case this code
gets re-used in other contexts that don't have the same memory growth
pattern.


Thanks,

Mathieu


> 
> Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien at efficios.com>
> ---
> src/bin/lttng-sessiond/syscall.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/bin/lttng-sessiond/syscall.c b/src/bin/lttng-sessiond/syscall.c
> index c21e4d8..51214bf 100644
> --- a/src/bin/lttng-sessiond/syscall.c
> +++ b/src/bin/lttng-sessiond/syscall.c
> @@ -85,7 +85,7 @@ int syscall_init_table(void)
> 			size_t new_nbmem;
> 
> 			/* Double memory size. */
> -			new_nbmem = max(index, nbmem << 1);
> +			new_nbmem = max(index + 1, nbmem << 1);
> 			if (new_nbmem > (SIZE_MAX / sizeof(*new_list))) {
> 				/* Overflow, stop everything, something went really wrong. */
> 				ERR("Syscall listing memory size overflow. Stopping");
> --
> 2.7.4
> 
> _______________________________________________
> lttng-dev mailing list
> lttng-dev at lists.lttng.org
> https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com


More information about the lttng-dev mailing list