aboutsummaryrefslogtreecommitdiff
path: root/drivers/media/usb
diff options
context:
space:
mode:
authorGravatar Luke Nowakowski-Krijger <lnowakow@eng.ucsd.edu> 2019-07-17 10:19:46 -0400
committerGravatar Mauro Carvalho Chehab <mchehab+samsung@kernel.org> 2019-07-25 06:23:35 -0400
commitd4a6a9537bc32811486282206ecfb7c53754b74d (patch)
tree922d20b5ed372ec8759cff83c7eaf9ae2ff92151 /drivers/media/usb
parentmedia: staging: media: cedrus: Fix misuse of GENMASK macro (diff)
downloadlinux-d4a6a9537bc32811486282206ecfb7c53754b74d.tar.gz
linux-d4a6a9537bc32811486282206ecfb7c53754b74d.tar.bz2
linux-d4a6a9537bc32811486282206ecfb7c53754b74d.zip
media: hdpvr: Add device num check and handling
Add hdpvr device num check and error handling We need to increment the device count atomically before we checkout a device to make sure that we do not reach the max count, otherwise we get out-of-bounds errors as reported by syzbot. Reported-and-tested-by: syzbot+aac8d0d7205f112045d2@syzkaller.appspotmail.com Signed-off-by: Luke Nowakowski-Krijger <lnowakow@eng.ucsd.edu> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
Diffstat (limited to 'drivers/media/usb')
-rw-r--r--drivers/media/usb/hdpvr/hdpvr-core.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/drivers/media/usb/hdpvr/hdpvr-core.c b/drivers/media/usb/hdpvr/hdpvr-core.c
index 9b9d894d29bc..a0905c81d2cb 100644
--- a/drivers/media/usb/hdpvr/hdpvr-core.c
+++ b/drivers/media/usb/hdpvr/hdpvr-core.c
@@ -271,6 +271,7 @@ static int hdpvr_probe(struct usb_interface *interface,
#endif
size_t buffer_size;
int i;
+ int dev_num;
int retval = -ENOMEM;
/* allocate memory for our device state and initialize it */
@@ -368,8 +369,17 @@ static int hdpvr_probe(struct usb_interface *interface,
}
#endif
+ dev_num = atomic_inc_return(&dev_nr);
+ if (dev_num >= HDPVR_MAX) {
+ v4l2_err(&dev->v4l2_dev,
+ "max device number reached, device register failed\n");
+ atomic_dec(&dev_nr);
+ retval = -ENODEV;
+ goto reg_fail;
+ }
+
retval = hdpvr_register_videodev(dev, &interface->dev,
- video_nr[atomic_inc_return(&dev_nr)]);
+ video_nr[dev_num]);
if (retval < 0) {
v4l2_err(&dev->v4l2_dev, "registering videodev failed\n");
goto reg_fail;