media: pvrusb2: fix array-index-out-of-bounds in pvr2_i2c_core_init
authorPavel Skripkin <paskripkin@gmail.com>
Fri, 15 Apr 2022 21:24:48 +0000 (23:24 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 14 Jun 2022 14:53:49 +0000 (16:53 +0200)
commit2e004fe914b243db41fa96f9e583385f360ea58e
treec5ab54ef42a41734315bbd1a7e96603fbfd13ed8
parent31ef17546f024ef5b9ae162e2c432d018238b58b
media: pvrusb2: fix array-index-out-of-bounds in pvr2_i2c_core_init

[ Upstream commit 471bec68457aaf981add77b4f590d65dd7da1059 ]

Syzbot reported that -1 is used as array index. The problem was in
missing validation check.

hdw->unit_number is initialized with -1 and then if init table walk fails
this value remains unchanged. Since code blindly uses this member for
array indexing adding sanity check is the easiest fix for that.

hdw->workpoll initialization moved upper to prevent warning in
__flush_work.

Reported-and-tested-by: syzbot+1a247e36149ffd709a9b@syzkaller.appspotmail.com
Fixes: d855497edbfb ("V4L/DVB (4228a): pvrusb2 to kernel 2.6.18")
Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/media/usb/pvrusb2/pvrusb2-hdw.c