Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: msp3400: Avoid possible out-of-bounds array accesses in msp3400c_thread()

It's possible for max1 to remain -1 if msp_read() always fail. This
variable is further used as index for accessing arrays.

Fix that by checking max1 prior to array accesses.

It seems that restart is the preferable action in case of out-of-bounds
value.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: 8a4b275f9c19 ("V4L/DVB (3427): audmode and rxsubchans fixes (VIDIOC_G/S_TUNER)")
Cc: stable@vger.kernel.org
Signed-off-by: Ivan Abramov <i.abramov@mt-integration.ru>
Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>

authored by

Ivan Abramov and committed by
Hans Verkuil
d2bceb2e 8163419e

+2
+2
drivers/media/i2c/msp3400-kthreads.c
··· 596 596 "carrier2 val: %5d / %s\n", val, cd[i].name); 597 597 } 598 598 599 + if (max1 < 0 || max1 > 3) 600 + goto restart; 599 601 /* program the msp3400 according to the results */ 600 602 state->main = msp3400c_carrier_detect_main[max1].cdo; 601 603 switch (max1) {