From: Mathieu Desnoyers Date: Mon, 14 Mar 2022 15:25:56 +0000 (-0400) Subject: Fix: lttng ABI: lttng_counter_ioctl() tainted scalar X-Git-Tag: v2.13.3~2 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=7d42b129afc8e4a0a5a4172a8abb3022091b6440;p=lttng-modules.git Fix: lttng ABI: lttng_counter_ioctl() tainted scalar Found by Coverity: >>> CID 1476250: (TAINTED_SCALAR) >>> Using tainted variable "local_counter_aggregate.index.number_dimensions" as a loop boundary. >>> CID 1476250: (TAINTED_SCALAR) >>> Using tainted variable "local_counter_clear.index.number_dimensions" as a loop boundary. >>> CID 1476250: (TAINTED_SCALAR) >>> Using tainted variable "local_counter_read.index.number_dimensions" as a loop boundary. Signed-off-by: Mathieu Desnoyers Change-Id: I7d35cf96781bb18837fe4564e4e8a34aa2ddc310 --- diff --git a/src/lttng-abi.c b/src/lttng-abi.c index eac1afd1..864df6fc 100644 --- a/src/lttng-abi.c +++ b/src/lttng-abi.c @@ -650,6 +650,8 @@ long lttng_counter_ioctl(struct file *file, unsigned int cmd, unsigned long arg) if (validate_zeroed_padding(local_counter_read.padding, sizeof(local_counter_read.padding))) return -EINVAL; + if (local_counter_read.index.number_dimensions > LTTNG_KERNEL_ABI_COUNTER_DIMENSION_MAX) + return -EINVAL; /* Cast all indexes into size_t. */ for (i = 0; i < local_counter_read.index.number_dimensions; i++) @@ -685,6 +687,8 @@ long lttng_counter_ioctl(struct file *file, unsigned int cmd, unsigned long arg) if (validate_zeroed_padding(local_counter_aggregate.padding, sizeof(local_counter_aggregate.padding))) return -EINVAL; + if (local_counter_aggregate.index.number_dimensions > LTTNG_KERNEL_ABI_COUNTER_DIMENSION_MAX) + return -EINVAL; /* Cast all indexes into size_t. */ for (i = 0; i < local_counter_aggregate.index.number_dimensions; i++) @@ -716,6 +720,8 @@ long lttng_counter_ioctl(struct file *file, unsigned int cmd, unsigned long arg) if (validate_zeroed_padding(local_counter_clear.padding, sizeof(local_counter_clear.padding))) return -EINVAL; + if (local_counter_clear.index.number_dimensions > LTTNG_KERNEL_ABI_COUNTER_DIMENSION_MAX) + return -EINVAL; /* Cast all indexes into size_t. */ for (i = 0; i < local_counter_clear.index.number_dimensions; i++)