media: em28xx: Fix use-after-free in em28xx_alloc_urbs
authorDinghao Liu <dinghao.liu@zju.edu.cn>
Mon, 28 Dec 2020 13:02:05 +0000 (14:02 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 4 Mar 2021 10:37:39 +0000 (11:37 +0100)
commit451c7cb236ef4a1223583b68831211c2c59da3b9
tree7c26ed77d85880a1513e4735f96143b6675ab165
parent27dfb2c856f596a2ba1cb94631c1df75679c9209
media: em28xx: Fix use-after-free in em28xx_alloc_urbs

[ Upstream commit a26efd1961a18b91ae4cd2e433adbcf865b40fa3 ]

When kzalloc() fails, em28xx_uninit_usb_xfer() will free
usb_bufs->buf and set it to NULL. Thus the later access
to usb_bufs->buf[i] will lead to null pointer dereference.
Also the kfree(usb_bufs->buf) after that is redundant.

Fixes: d571b592c6206 ("media: em28xx: don't use coherent buffer for DMA transfers")
Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/media/usb/em28xx/em28xx-core.c