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

media: dvb-usb: pctv452e: move snd/rcv len check before kmalloc

syzbot reported a uninit-value in pctv452e_i2c_msg. [1]

When the snd_len or rcv_len check fails and jumps to failed, buf is
uninitialized, triggering the uninit-value issue.

Move the snd/rcv length check before kmalloc, and return -EINVAL directly
if the condition is met.

[1]
BUG: KMSAN: uninit-value in hex_string+0x681/0x740 lib/vsprintf.c:1220
pctv452e_i2c_msg+0x82a/0x8f0 drivers/media/usb/dvb-usb/pctv452e.c:467
pctv452e_i2c_xfer+0x2e6/0x4c0 drivers/media/usb/dvb-usb/pctv452e.c:502

Reported-by: syzbot+480edd2cadb85ddb4bbe@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=480edd2cadb85ddb4bbe
Signed-off-by: Edward Adam Davis <eadavis@qq.com>
Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>

authored by

Edward Adam Davis and committed by
Hans Verkuil
1a31cb27 2d71d7b5

+3 -4
+3 -4
drivers/media/usb/dvb-usb/pctv452e.c
··· 422 422 u8 id; 423 423 int ret; 424 424 425 + if (snd_len > 64 - 7 || rcv_len > 64 - 7) 426 + return -EINVAL; 427 + 425 428 buf = kmalloc(64, GFP_KERNEL); 426 429 if (!buf) 427 430 return -ENOMEM; 428 431 429 432 id = state->c++; 430 - 431 - ret = -EINVAL; 432 - if (snd_len > 64 - 7 || rcv_len > 64 - 7) 433 - goto failed; 434 433 435 434 buf[0] = SYNC_BYTE_OUT; 436 435 buf[1] = id;