X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fsyscall.c;h=1fc68d2ca5d73319ebddb7f395106b2fc083ad57;hb=00a620843422e5c972aee0ada2181b811fc81b92;hp=ee7578051e2a12d3322cb6e3d9fd4ae2946da1a7;hpb=4b47b6a9070be168eb81fd204e4490d0f1d3be87;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/syscall.c b/src/bin/lttng-sessiond/syscall.c index ee7578051..1fc68d2ca 100644 --- a/src/bin/lttng-sessiond/syscall.c +++ b/src/bin/lttng-sessiond/syscall.c @@ -16,6 +16,7 @@ */ #define _GNU_SOURCE +#define _LGPL_SOURCE #include #include #include @@ -35,7 +36,7 @@ static size_t syscall_table_nb_entry; * Populate the system call table using the kernel tracer. * * Return 0 on success and the syscall table is allocated. On error, a negative - * value is returned and the syscall table is set to NULL. + * value is returned. */ int syscall_init_table(void) { @@ -72,7 +73,7 @@ int syscall_init_table(void) } while (fscanf(fp, - "syscall { index = %lu; \ + "syscall { index = %zu; \ name = %" XSTR(SYSCALL_NAME_LEN) "[^;]; \ bitness = %u; };\n", &index, name, &bitness) == 3) { @@ -82,6 +83,14 @@ int syscall_init_table(void) /* Double memory size. */ new_nbmem = max(index, nbmem << 1); + if (new_nbmem < nbmem) { + /* Overflow, stop everything, something went really wrong. */ + ERR("Syscall listing memory size overflow. Stopping"); + free(syscall_table); + syscall_table = NULL; + ret = -EINVAL; + goto error; + } DBG("Reallocating syscall table from %zu to %zu entries", nbmem, new_nbmem); @@ -396,11 +405,15 @@ ssize_t syscall_list_channel(struct ltt_kernel_channel *kchan, events = new_events; } + rcu_read_lock(); ksyscall = lookup_syscall(syscalls_ht, syscall_table[i].name); if (ksyscall) { update_event_syscall_bitness(events, i, ksyscall->index); + rcu_read_unlock(); continue; } + ksyscall = NULL; + rcu_read_unlock(); ret = add_syscall_to_ht(syscalls_ht, i, count); if (ret < 0) { @@ -420,7 +433,10 @@ ssize_t syscall_list_channel(struct ltt_kernel_channel *kchan, return count; error: + rcu_read_lock(); destroy_syscall_ht(syscalls_ht); + rcu_read_unlock(); + free(events); return ret; }