Skip to content

Commit

Permalink
media: em28xx: Fix use-after-free in em28xx_alloc_urbs
Browse files Browse the repository at this point in the history
[ Upstream commit a26efd1 ]

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: d571b59 ("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>
  • Loading branch information
dinghaoliu authored and gregkh committed Mar 4, 2021
1 parent d025f26 commit c28ea51
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions drivers/media/usb/em28xx/em28xx-core.c
Expand Up @@ -956,14 +956,10 @@ int em28xx_alloc_urbs(struct em28xx *dev, enum em28xx_mode mode, int xfer_bulk,

usb_bufs->buf[i] = kzalloc(sb_size, GFP_KERNEL);
if (!usb_bufs->buf[i]) {
em28xx_uninit_usb_xfer(dev, mode);

for (i--; i >= 0; i--)
kfree(usb_bufs->buf[i]);

kfree(usb_bufs->buf);
usb_bufs->buf = NULL;

em28xx_uninit_usb_xfer(dev, mode);
return -ENOMEM;
}

Expand Down

0 comments on commit c28ea51

Please sign in to comment.