]> www.infradead.org Git - users/hch/misc.git/commitdiff
ASoC: SOF: ipc3-dtrace: fix potential integer overflow in allocation
authorSamasth Norway Ananda <samasth.norway.ananda@oracle.com>
Tue, 9 Sep 2025 22:51:11 +0000 (15:51 -0700)
committerMark Brown <broonie@kernel.org>
Thu, 18 Sep 2025 21:26:31 +0000 (22:26 +0100)
Fix a potential integer overflow vulnerability in trace_filter_parse()
where the allocation size calculation could overflow.

The issue occurs when:
1. capacity is calculated by adding TRACE_FILTER_ELEMENTS_PER_ENTRY in a
   loop for each entry found in the input string.
2. capacity * sizeof(**out) multiplication could overflow if many
   entries are present in the input.
3. This results in a smaller allocation than expected, leading to
   potential buffer overflow.

Replace kmalloc() with kmalloc_array() which provides built-in overflow
checking and will safely fail the allocation if overflow would occur,
preventing memory corruption.

Signed-off-by: Samasth Norway Ananda <samasth.norway.ananda@oracle.com>
Link: https://patch.msgid.link/20250909225111.3740029-1-samasth.norway.ananda@oracle.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/sof/ipc3-dtrace.c

index e5c8fec173c4f2d8dbf413e1e4262f50dbef86fb..6ec391fd39a9029da5b58154d82e3783f5ae0518 100644 (file)
@@ -126,7 +126,7 @@ static int trace_filter_parse(struct snd_sof_dev *sdev, char *string,
                capacity += TRACE_FILTER_ELEMENTS_PER_ENTRY;
                entry = strchr(entry + 1, entry_delimiter[0]);
        }
-       *out = kmalloc(capacity * sizeof(**out), GFP_KERNEL);
+       *out = kmalloc_array(capacity, sizeof(**out), GFP_KERNEL);
        if (!*out)
                return -ENOMEM;