Skip to content

Commit 443b66f

Browse files
committed
media: em28xx: initialize refcount before kref_get
jira VULN-8755 cve CVE-2022-3239 commit-author Dongliang Mu <[email protected]> commit c08eadc The commit 47677e5("[media] em28xx: Only deallocate struct em28xx after finishing all extensions") adds kref_get to many init functions (e.g., em28xx_audio_init). However, kref_init is called too late in em28xx_usb_probe, since em28xx_init_dev before will invoke those init functions and call kref_get function. Then refcount bug occurs in my local syzkaller instance. Fix it by moving kref_init before em28xx_init_dev. This issue occurs not only in dev but also dev->dev_next. Fixes: 47677e5 ("[media] em28xx: Only deallocate struct em28xx after finishing all extensions") Reported-by: syzkaller <[email protected]> Signed-off-by: Dongliang Mu <[email protected]> Signed-off-by: Hans Verkuil <[email protected]> (cherry picked from commit c08eadc) Signed-off-by: Brett Mastbergen <[email protected]>
1 parent 2697e4a commit 443b66f

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/media/usb/em28xx/em28xx-cards.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3838,6 +3838,8 @@ static int em28xx_usb_probe(struct usb_interface *intf,
38383838
goto err_free;
38393839
}
38403840

3841+
kref_init(&dev->ref);
3842+
38413843
dev->devno = nr;
38423844
dev->model = id->driver_info;
38433845
dev->alt = -1;
@@ -3938,6 +3940,8 @@ static int em28xx_usb_probe(struct usb_interface *intf,
39383940
}
39393941

39403942
if (dev->board.has_dual_ts && em28xx_duplicate_dev(dev) == 0) {
3943+
kref_init(&dev->dev_next->ref);
3944+
39413945
dev->dev_next->ts = SECONDARY_TS;
39423946
dev->dev_next->alt = -1;
39433947
dev->dev_next->is_audio_only = has_vendor_audio &&
@@ -3992,12 +3996,8 @@ static int em28xx_usb_probe(struct usb_interface *intf,
39923996
em28xx_write_reg(dev, 0x0b, 0x82);
39933997
mdelay(100);
39943998
}
3995-
3996-
kref_init(&dev->dev_next->ref);
39973999
}
39984000

3999-
kref_init(&dev->ref);
4000-
40014001
request_modules(dev);
40024002

40034003
/*

0 commit comments

Comments
 (0)