media: vivid: check vb2_is_busy before calling vivid_update_format_cap/out
Subsystems (2)
PATCH 1/1 media: vivid: check vb2_is_busy before calling vivid_update_format_cap/out
The vivid_update_format_cap/out() functions must only be called if the capture/output queue are not busy. But for several controls that is not checked.
Only when streaming starts will they be set to 'grabbed' and it is impossible to change the control, but between REQBUFS and STREAMON you are still allowed to set these controls. Since vivid_update_format_cap/out will change the format, this can cause unexpected results.
I suspect that this is the cause of this syzbot bug:
https://syzkaller.appspot.com/bug?extid=dac8f5eaa46837e97b89
But since we never have reproducers, it is hard to be certain. In any case, these checks are needed regardless.
---
drivers/media/test-drivers/vivid/vivid-ctrls.c +14 -0
@@ -608,18 +608,26 @@ static int vivid_vid_cap_s_ctrl(struct v4l2_ctrl *ctrl)tpg_s_vflip (&dev->tpg, dev->sensor_vflip ^ dev->vflip);break ;case VIVID_CID_REDUCED_FPS : +if (vb2_is_busy (&dev->vb_vid_cap_q)) +return -EBUSY ; dev->reduced_fps = ctrl->val;vivid_update_format_cap (dev, true);break ;case VIVID_CID_HAS_CROP_CAP : +if (vb2_is_busy (&dev->vb_vid_cap_q)) +return -EBUSY ; dev->has_crop_cap = ctrl->val;vivid_update_format_cap (dev, true);break ;case VIVID_CID_HAS_COMPOSE_CAP : +if (vb2_is_busy (&dev->vb_vid_cap_q)) +return -EBUSY ; dev->has_compose_cap = ctrl->val;vivid_update_format_cap (dev, true);break ;case VIVID_CID_HAS_SCALER_CAP : +if (vb2_is_busy (&dev->vb_vid_cap_q)) +return -EBUSY ; dev->has_scaler_cap = ctrl->val;vivid_update_format_cap (dev, true);break ;
@@ -1116,14 +1124,20 @@ static int vivid_vid_out_s_ctrl(struct v4l2_ctrl *ctrl)switch (ctrl->id) {case VIVID_CID_HAS_CROP_OUT : +if (vb2_is_busy (&dev->vb_vid_out_q)) +return -EBUSY ; dev->has_crop_out = ctrl->val;vivid_update_format_out (dev);break ;case VIVID_CID_HAS_COMPOSE_OUT : +if (vb2_is_busy (&dev->vb_vid_out_q)) +return -EBUSY ; dev->has_compose_out = ctrl->val;vivid_update_format_out (dev);break ;case VIVID_CID_HAS_SCALER_OUT : +if (vb2_is_busy (&dev->vb_vid_out_q)) +return -EBUSY ; dev->has_scaler_out = ctrl->val;vivid_update_format_out (dev);break ;
Quoted 11 lines · Hans Verkuil
The vivid_update_format_cap/out() functions must only be called if the capture/output queue are not busy. But for several controls that is not checked.
Only when streaming starts will they be set to 'grabbed' and it is impossible to change the control, but between REQBUFS and STREAMON you are still allowed to set these controls. Since vivid_update_format_cap/out will change the format, this can cause unexpected results.
I suspect that this is the cause of this syzbot bug:
Quoted 7 lines
https://syzkaller.appspot.com/bug?extid=dac8f5eaa46837e97b89
But since we never have reproducers, it is hard to be certain. In any case, these checks are needed regardless.
Reported-by [email protected]Signed-off-by Hans Verkuil <[email protected]>
Oops, this should be Hans Verkuil <[email protected]>. Also add:
Regards,
Hans
Quoted 54 lines
---
drivers/media/test-drivers/vivid/vivid-ctrls.c +14
-0@@ -608,18 +608,26 @@ static int vivid_vid_cap_s_ctrl(struct v4l2_ctrl *ctrl)tpg_s_vflip (&dev->tpg, dev->sensor_vflip ^ dev->vflip);break ;case VIVID_CID_REDUCED_FPS : +if (vb2_is_busy (&dev->vb_vid_cap_q)) +return -EBUSY ; dev->reduced_fps = ctrl->val;vivid_update_format_cap (dev, true);break ;case VIVID_CID_HAS_CROP_CAP : +if (vb2_is_busy (&dev->vb_vid_cap_q)) +return -EBUSY ; dev->has_crop_cap = ctrl->val;vivid_update_format_cap (dev, true);break ;case VIVID_CID_HAS_COMPOSE_CAP : +if (vb2_is_busy (&dev->vb_vid_cap_q)) +return -EBUSY ; dev->has_compose_cap = ctrl->val;vivid_update_format_cap (dev, true);break ;case VIVID_CID_HAS_SCALER_CAP : +if (vb2_is_busy (&dev->vb_vid_cap_q)) +return -EBUSY ; dev->has_scaler_cap = ctrl->val;vivid_update_format_cap (dev, true);break ;@@ -1116,14 +1124,20 @@ static int vivid_vid_out_s_ctrl(struct v4l2_ctrl *ctrl)switch (ctrl->id) {case VIVID_CID_HAS_CROP_OUT : +if (vb2_is_busy (&dev->vb_vid_out_q)) +return -EBUSY ; dev->has_crop_out = ctrl->val;vivid_update_format_out (dev);break ;case VIVID_CID_HAS_COMPOSE_OUT : +if (vb2_is_busy (&dev->vb_vid_out_q)) +return -EBUSY ; dev->has_compose_out = ctrl->val;vivid_update_format_out (dev);break ;case VIVID_CID_HAS_SCALER_OUT : +if (vb2_is_busy (&dev->vb_vid_out_q)) +return -EBUSY ; dev->has_scaler_out = ctrl->val;vivid_update_format_out (dev);break ;
Le mercredi 13 mai 2026 à 10:52 +0200, Hans Verkuil a écrit :
Quoted 28 lines
The vivid_update_format_cap/out() functions must only be called if the capture/output queue are not busy. But for several controls that is not checked.
Only when streaming starts will they be set to 'grabbed' and it is impossible to change the control, but between REQBUFS and STREAMON you are still allowed to set these controls. Since vivid_update_format_cap/out will change the format, this can cause unexpected results.
I suspect that this is the cause of this syzbot bug:
https://syzkaller.appspot.com/bug?extid=dac8f5eaa46837e97b89
But since we never have reproducers, it is hard to be certain. In any case, these checks are needed regardless.
Reported-by [email protected]Signed-off-by Hans Verkuil <[email protected]>---
drivers/media/test-drivers/vivid/vivid-ctrls.c +0
-0@@ -608,18 +608,26 @@ static int vivid_vid_cap_s_ctrl(struct v4l2_ctrl *ctrl) tpg_s_vflip(&dev->tpg, dev->sensor_vflip ^ dev->vflip); break;case
VIVID_CID_REDUCED_FPS:
drivers/media/test-drivers/vivid/vivid-ctrls.c
Quoted 2 lines
drivers/media/test-drivers/vivid/vivid-ctrls.c +2
-0+if (vb2_is_busy (&dev->vb_vid_cap_q)) +return -EBUSY ;
It is unclear to me why users need to free all the buffers to enable this feature. Should that one only be limited to not being streaming ? I believe it will only affect the HDMI DV Timings and the frame internal in params right ?
Quoted 43 lines
dev->reduced_fps=ctrl->val;vivid_update_format_cap(dev, true); break;
caseVIVID_CID_HAS_CROP_CAP:drivers/media/test-drivers/vivid/vivid-ctrls.c +2
-0+if (vb2_is_busy (&dev->vb_vid_cap_q)) +return -EBUSY ;
dev->has_crop_cap=ctrl->val;vivid_update_format_cap(dev, true); break;
caseVIVID_CID_HAS_COMPOSE_CAP:drivers/media/test-drivers/vivid/vivid-ctrls.c +2
-0+if (vb2_is_busy (&dev->vb_vid_cap_q)) +return -EBUSY ;
dev->has_compose_cap=ctrl->val;vivid_update_format_cap(dev, true); break;
caseVIVID_CID_HAS_SCALER_CAP:drivers/media/test-drivers/vivid/vivid-ctrls.c +2
-0+if (vb2_is_busy (&dev->vb_vid_cap_q)) +return -EBUSY ;
dev->has_scaler_cap=ctrl->val;vivid_update_format_cap(dev, true); break;drivers/media/test-drivers/vivid/vivid-ctrls.c +0
-0@@ -1116,14 +1124,20 @@ static int vivid_vid_out_s_ctrl(struct v4l2_ctrl *ctrl) switch (ctrl->id) {case
VIVID_CID_HAS_CROP_OUT:drivers/media/test-drivers/vivid/vivid-ctrls.c +2
-0+if (vb2_is_busy (&dev->vb_vid_out_q)) +return -EBUSY ;
dev->has_crop_out=ctrl->val;
vivid_update_format_out(dev);
break;
caseVIVID_CID_HAS_COMPOSE_OUT:drivers/media/test-drivers/vivid/vivid-ctrls.c +2
-0+if (vb2_is_busy (&dev->vb_vid_out_q)) +return -EBUSY ;
dev->has_compose_out=ctrl->val;
vivid_update_format_out(dev);
break;
caseVIVID_CID_HAS_SCALER_OUT:drivers/media/test-drivers/vivid/vivid-ctrls.c +2
-0+if (vb2_is_busy (&dev->vb_vid_out_q)) +return -EBUSY ;
dev->has_scaler_out=ctrl->val;
vivid_update_format_out(dev);
break;
Quoted 27 lines · Nicolas Dufresne
Le mercredi 13 mai 2026 à 10:52 +0200, Hans Verkuil a écrit :
Quoted 26 lines
The vivid_update_format_cap/out() functions must only be called if the capture/output queue are not busy. But for several controls that is not checked.
Only when streaming starts will they be set to 'grabbed' and it is impossible to change the control, but between REQBUFS and STREAMON you are still allowed to set these controls. Since vivid_update_format_cap/out will change the format, this can cause unexpected results.
I suspect that this is the cause of this syzbot bug:
https://syzkaller.appspot.com/bug?extid=dac8f5eaa46837e97b89
But since we never have reproducers, it is hard to be certain. In any case, these checks are needed regardless.
Reported-by [email protected]Signed-off-by Hans Verkuil <[email protected]>---
drivers/media/test-drivers/vivid/vivid-ctrls.c +0
-0@@ -608,18 +608,26 @@ static int vivid_vid_cap_s_ctrl(struct v4l2_ctrl *ctrl) tpg_s_vflip(&dev->tpg, dev->sensor_vflip ^ dev->vflip);
Quoted 8 lines
drivers/media/test-drivers/vivid/vivid-ctrls.c
Quoted 4 lines
drivers/media/test-drivers/vivid/vivid-ctrls.c +0
-0break;case
VIVID_CID_REDUCED_FPS:drivers/media/test-drivers/vivid/vivid-ctrls.c +2
-0+if (vb2_is_busy (&dev->vb_vid_cap_q)) +return -EBUSY ;It is unclear to me why users need to free all the buffers to enable this feature. Should that one only be limited to not being streaming ? I believe it will only affect the HDMI DV Timings and the frame internal in params right ?
The problem is that vivid_update_format_cap() resets the format, as you expect when changing input or standard, or timing.
This control implies a new timing, so that's why vivid_update_format_cap is called. And that requires the is_busy check.
It could be implemented differently, but then this control shouldn't use vivid_update_format_cap().
It's something for another time, for now I want to be consistent in always checking vb2_is_busy before vivid_update_format_cap can be called.
Regards,
Hans
Quoted 44 lines
Quoted 44 lines
dev->reduced_fps=ctrl->val;vivid_update_format_cap(dev, true); break;
caseVIVID_CID_HAS_CROP_CAP:drivers/media/test-drivers/vivid/vivid-ctrls.c +2
-0+if (vb2_is_busy (&dev->vb_vid_cap_q)) +return -EBUSY ;
dev->has_crop_cap=ctrl->val;vivid_update_format_cap(dev, true); break;
caseVIVID_CID_HAS_COMPOSE_CAP:drivers/media/test-drivers/vivid/vivid-ctrls.c +2
-0+if (vb2_is_busy (&dev->vb_vid_cap_q)) +return -EBUSY ;
dev->has_compose_cap=ctrl->val;vivid_update_format_cap(dev, true); break;
caseVIVID_CID_HAS_SCALER_CAP:drivers/media/test-drivers/vivid/vivid-ctrls.c +2
-0+if (vb2_is_busy (&dev->vb_vid_cap_q)) +return -EBUSY ;
dev->has_scaler_cap=ctrl->val;vivid_update_format_cap(dev, true); break;drivers/media/test-drivers/vivid/vivid-ctrls.c +0
-0@@ -1116,14 +1124,20 @@ static int vivid_vid_out_s_ctrl(struct v4l2_ctrl *ctrl) switch (ctrl->id) {case
VIVID_CID_HAS_CROP_OUT:drivers/media/test-drivers/vivid/vivid-ctrls.c +2
-0+if (vb2_is_busy (&dev->vb_vid_out_q)) +return -EBUSY ;
dev->has_crop_out=ctrl->val;
vivid_update_format_out(dev);
break;
caseVIVID_CID_HAS_COMPOSE_OUT:drivers/media/test-drivers/vivid/vivid-ctrls.c +2
-0+if (vb2_is_busy (&dev->vb_vid_out_q)) +return -EBUSY ;
dev->has_compose_out=ctrl->val;
vivid_update_format_out(dev);
break;
caseVIVID_CID_HAS_SCALER_OUT:drivers/media/test-drivers/vivid/vivid-ctrls.c +2
-0+if (vb2_is_busy (&dev->vb_vid_out_q)) +return -EBUSY ;
dev->has_scaler_out=ctrl->val;
vivid_update_format_out(dev);
break;
Nicolas Dufresne
Reviewed-byLe mardi 19 mai 2026 à 15:30 +0200, Hans Verkuil a écrit :
Quoted 37 lines · Nicolas Dufresne
Quoted 27 lines
Le mercredi 13 mai 2026 à 10:52 +0200, Hans Verkuil a écrit :
Quoted 26 lines
The vivid_update_format_cap/out() functions must only be called if the capture/output queue are not busy. But for several controls that is not checked.
Only when streaming starts will they be set to 'grabbed' and it is impossible to change the control, but between REQBUFS and STREAMON you are still allowed to set these controls. Since vivid_update_format_cap/out will change the format, this can cause unexpected results.
I suspect that this is the cause of this syzbot bug:
https://syzkaller.appspot.com/bug?extid=dac8f5eaa46837e97b89
But since we never have reproducers, it is hard to be certain. In any case, these checks are needed regardless.
Reported-by [email protected]Signed-off-by Hans Verkuil <[email protected]>---
drivers/media/test-drivers/vivid/vivid-ctrls.c +0
-0@@ -608,18 +608,26 @@ static int vivid_vid_cap_s_ctrl(struct v4l2_ctrl *ctrl) tpg_s_vflip(&dev->tpg, dev->sensor_vflip ^ dev->vflip);Quoted 8 lines
drivers/media/test-drivers/vivid/vivid-ctrls.c
Quoted 4 lines
drivers/media/test-drivers/vivid/vivid-ctrls.c +0
-0break;case
VIVID_CID_REDUCED_FPS:drivers/media/test-drivers/vivid/vivid-ctrls.c +2
-0+if (vb2_is_busy (&dev->vb_vid_cap_q)) +return -EBUSY ;It is unclear to me why users need to free all the buffers to enable this feature. Should that one only be limited to not being streaming ? I believe it will only affect the HDMI DV Timings and the frame internal in params right ?
Quoted 5 lines
The problem is that
vivid_update_format_cap()resets the format, as you expect when changing input or standard, or timing.This control implies a new timing, so that's why
vivid_update_format_capis called. And that requires theis_busycheck.
I did check again, and the timing is only changed if !vb2_is_busy(). That matched my first impression that the vivid_update_format_cap() just copy over the same information without actually changing it.
Quoted 3 lines
It could be implemented differently, but then this control shouldn't use
vivid_update_format_cap().
It would be much more elegant to separate the changes from each other yes. At separate between what affects the v4l2_fmt (memory allocation) and what doesn't. Also because its very error prone to trust vivid_update_format_cap() to not have any side effects.
Quoted 3 lines
It's something for another time, for now I want to be consistent in always checking
vb2_is_busybeforevivid_update_format_capcan be called.
Please add some sort of comment, so future visitors knows this code is illogically tied together.
Nicolas
Quoted 49 lines
Regards,
Hans
Quoted 44 lines
Quoted 44 lines
dev->reduced_fps=ctrl->val;vivid_update_format_cap(dev, true); break;
caseVIVID_CID_HAS_CROP_CAP:drivers/media/test-drivers/vivid/vivid-ctrls.c +2
-0+if (vb2_is_busy (&dev->vb_vid_cap_q)) +return -EBUSY ;
dev->has_crop_cap=ctrl->val;vivid_update_format_cap(dev, true); break;
caseVIVID_CID_HAS_COMPOSE_CAP:drivers/media/test-drivers/vivid/vivid-ctrls.c +2
-0+if (vb2_is_busy (&dev->vb_vid_cap_q)) +return -EBUSY ;
dev->has_compose_cap=ctrl->val;vivid_update_format_cap(dev, true); break;
caseVIVID_CID_HAS_SCALER_CAP:drivers/media/test-drivers/vivid/vivid-ctrls.c +2
-0+if (vb2_is_busy (&dev->vb_vid_cap_q)) +return -EBUSY ;
dev->has_scaler_cap=ctrl->val;vivid_update_format_cap(dev, true); break;drivers/media/test-drivers/vivid/vivid-ctrls.c +0
-0@@ -1116,14 +1124,20 @@ static int vivid_vid_out_s_ctrl(struct v4l2_ctrl *ctrl) switch (ctrl->id) {case
VIVID_CID_HAS_CROP_OUT:drivers/media/test-drivers/vivid/vivid-ctrls.c +2
-0+if (vb2_is_busy (&dev->vb_vid_out_q)) +return -EBUSY ;
dev->has_crop_out=ctrl->val;
vivid_update_format_out(dev);
break;
caseVIVID_CID_HAS_COMPOSE_OUT:drivers/media/test-drivers/vivid/vivid-ctrls.c +2
-0+if (vb2_is_busy (&dev->vb_vid_out_q)) +return -EBUSY ;
dev->has_compose_out=ctrl->val;
vivid_update_format_out(dev);
break;
caseVIVID_CID_HAS_SCALER_OUT:drivers/media/test-drivers/vivid/vivid-ctrls.c +2
-0+if (vb2_is_busy (&dev->vb_vid_out_q)) +return -EBUSY ;
dev->has_scaler_out=ctrl->val;
vivid_update_format_out(dev);
break;
Quoted 57 lines · Nicolas Dufresne
Le mardi 19 mai 2026 à 15:30 +0200, Hans Verkuil a écrit :
Quoted 37 lines · Nicolas Dufresne
Quoted 27 lines
Le mercredi 13 mai 2026 à 10:52 +0200, Hans Verkuil a écrit :
Quoted 26 lines
The vivid_update_format_cap/out() functions must only be called if the capture/output queue are not busy. But for several controls that is not checked.
Only when streaming starts will they be set to 'grabbed' and it is impossible to change the control, but between REQBUFS and STREAMON you are still allowed to set these controls. Since vivid_update_format_cap/out will change the format, this can cause unexpected results.
I suspect that this is the cause of this syzbot bug:
https://syzkaller.appspot.com/bug?extid=dac8f5eaa46837e97b89
But since we never have reproducers, it is hard to be certain. In any case, these checks are needed regardless.
Reported-by [email protected]Signed-off-by Hans Verkuil <[email protected]>---
drivers/media/test-drivers/vivid/vivid-ctrls.c +0
-0@@ -608,18 +608,26 @@ static int vivid_vid_cap_s_ctrl(struct v4l2_ctrl *ctrl) tpg_s_vflip(&dev->tpg, dev->sensor_vflip ^ dev->vflip);Quoted 8 lines
drivers/media/test-drivers/vivid/vivid-ctrls.c
Quoted 4 lines
drivers/media/test-drivers/vivid/vivid-ctrls.c +0
-0break;case
VIVID_CID_REDUCED_FPS:drivers/media/test-drivers/vivid/vivid-ctrls.c +2
-0+if (vb2_is_busy (&dev->vb_vid_cap_q)) +return -EBUSY ;It is unclear to me why users need to free all the buffers to enable this feature. Should that one only be limited to not being streaming ? I believe it will only affect the HDMI DV Timings and the frame internal in params right ?
Quoted 5 lines
The problem is that
vivid_update_format_cap()resets the format, as you expect when changing input or standard, or timing.This control implies a new timing, so that's why
vivid_update_format_capis called. And that requires theis_busycheck.I did check again, and the timing is only changed if !vb2_is_busy(). That matched my first impression that the
vivid_update_format_cap()just copy over the same information without actually changing it.Quoted 3 lines
It could be implemented differently, but then this control shouldn't use
vivid_update_format_cap().It would be much more elegant to separate the changes from each other yes. At separate between what affects the
v4l2_fmt(memory allocation) and what doesn't. Also because its very error prone to trustvivid_update_format_cap()to not have any side effects.Quoted 1 line
Quoted 5 lines
Quoted 2 lines
It's something for another time, for now I want to be consistent in always checking
vb2_is_busybeforevivid_update_format_capcan be called.Please add some sort of comment, so future visitors knows this code is illogically tied together.
I decided to make a v2, changing REDUCED_FPS to not need vivid_update_format_cap anymore.
Regards,
Hans
Quoted 54 lines
Reviewed-by Nicolas Dufresne <[email protected]>Nicolas
Quoted 49 lines
Regards,
Hans
Quoted 44 lines
Quoted 44 lines
dev->reduced_fps=ctrl->val;vivid_update_format_cap(dev, true); break;
caseVIVID_CID_HAS_CROP_CAP:drivers/media/test-drivers/vivid/vivid-ctrls.c +2
-0+if (vb2_is_busy (&dev->vb_vid_cap_q)) +return -EBUSY ;
dev->has_crop_cap=ctrl->val;vivid_update_format_cap(dev, true); break;
caseVIVID_CID_HAS_COMPOSE_CAP:drivers/media/test-drivers/vivid/vivid-ctrls.c +2
-0+if (vb2_is_busy (&dev->vb_vid_cap_q)) +return -EBUSY ;
dev->has_compose_cap=ctrl->val;vivid_update_format_cap(dev, true); break;
caseVIVID_CID_HAS_SCALER_CAP:drivers/media/test-drivers/vivid/vivid-ctrls.c +2
-0+if (vb2_is_busy (&dev->vb_vid_cap_q)) +return -EBUSY ;
dev->has_scaler_cap=ctrl->val;vivid_update_format_cap(dev, true); break;drivers/media/test-drivers/vivid/vivid-ctrls.c +0
-0@@ -1116,14 +1124,20 @@ static int vivid_vid_out_s_ctrl(struct v4l2_ctrl *ctrl) switch (ctrl->id) {case
VIVID_CID_HAS_CROP_OUT:drivers/media/test-drivers/vivid/vivid-ctrls.c +2
-0+if (vb2_is_busy (&dev->vb_vid_out_q)) +return -EBUSY ;
dev->has_crop_out=ctrl->val;
vivid_update_format_out(dev);
break;
caseVIVID_CID_HAS_COMPOSE_OUT:drivers/media/test-drivers/vivid/vivid-ctrls.c +2
-0+if (vb2_is_busy (&dev->vb_vid_out_q)) +return -EBUSY ;
dev->has_compose_out=ctrl->val;
vivid_update_format_out(dev);
break;
caseVIVID_CID_HAS_SCALER_OUT:drivers/media/test-drivers/vivid/vivid-ctrls.c +2
-0+if (vb2_is_busy (&dev->vb_vid_out_q)) +return -EBUSY ;
dev->has_scaler_out=ctrl->val;
vivid_update_format_out(dev);
break;