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
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 <[email protected]>
Signed-off-by: Hans Verkuil <[email protected]>
Signed-off-by: Mauro Carvalho Chehab <[email protected]>
  • Loading branch information
dinghaoliu authored and mchehab committed Jan 12, 2021
1 parent dbfa04e commit a26efd1
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions drivers/media/usb/em28xx/em28xx-core.c
Original file line number Diff line number Diff line change
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 a26efd1

Please sign in to comment.