media: gspca: don't call stopN/stop0 after device disconnect
Subsystems (2)
PATCH 1/1 media: gspca: don't call stopN/stop0 after device disconnect
gspca_stream_off() calls the sub-driver's stopN() and stop0() callbacks unconditionally. These issue USB requests using gspca_dev->dev, which becomes a dangling pointer once the USB device has been disconnected and freed, causing a use-after-free when the video device fd is closed after disconnect.
Add a gspca_dev->present check before calling stopN() and stop0(), matching the existing check already used for gspca_input_create_urb() in the same function.
--- drivers/media/usb/gspca/gspca.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/usb/gspca/gspca.c +2 -2
@@ -733,14 +733,14 @@ static void gspca_stream_off(struct gspca_dev *gspca_dev) { gspca_dev->streaming = false; gspca_dev->usb_err =0 ; -if (gspca_dev->sd_desc->stopN) +if (gspca_dev->present && gspca_dev->sd_desc->stopN) gspca_dev->sd_desc->stopN (gspca_dev);destroy_urbs (gspca_dev);gspca_input_destroy_urb (gspca_dev);gspca_set_alt0 (gspca_dev);if (gspca_dev->present)gspca_input_create_urb (gspca_dev); -if (gspca_dev->sd_desc->stop0) +if (gspca_dev->present && gspca_dev->sd_desc->stop0) gspca_dev->sd_desc->stop0 (gspca_dev);gspca_dbg (gspca_dev,D_STREAM ,"stream off OK\n" ); }
Signature · 1 line
2.43.0
Quoted 10 lines · Deepanshu Kartikey
gspca_stream_off()calls the sub-driver'sstopN()andstop0()callbacks unconditionally. These issue USB requests usinggspca_dev->dev, which becomes a dangling pointer once the USB device has been disconnected and freed, causing a use-after-free when the video device fd is closed after disconnect.Add a
gspca_dev->presentcheck before callingstopN()andstop0(), matching the existing check already used forgspca_input_create_urb()in the same function.
Quoted 5 lines
Fixes 1f5965c4dfd7 ("media: gspca: convert to vb2")Reported-by [email protected]Tested-by [email protected]Signed-off-by Deepanshu Kartikey <[email protected]>
This is superseded by:
https://patchwork.linuxtv.org/project/linux-media/patch/[email protected]/
That's the correct fix since it forces streaming off before freeing anything.
Regards,
Hans
Quoted 25 lines
--- drivers/media/usb/gspca/gspca.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/media/usb/gspca/gspca.c +2
-2@@ -733,14 +733,14 @@ static void gspca_stream_off(struct gspca_dev *gspca_dev) { gspca_dev->streaming = false; gspca_dev->usb_err =0 ; -if (gspca_dev->sd_desc->stopN) +if (gspca_dev->present && gspca_dev->sd_desc->stopN) gspca_dev->sd_desc->stopN (gspca_dev);destroy_urbs (gspca_dev);gspca_input_destroy_urb (gspca_dev);gspca_set_alt0 (gspca_dev);if (gspca_dev->present)gspca_input_create_urb (gspca_dev); -if (gspca_dev->sd_desc->stop0) +if (gspca_dev->present && gspca_dev->sd_desc->stop0) gspca_dev->sd_desc->stop0 (gspca_dev);gspca_dbg (gspca_dev,D_STREAM ,"stream off OK\n" ); }