Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] media: out-of-bounds write via unvalidated stream->vc - [Medium] media: ipu6: Early return in ipu6_isys_stop_stream_firmware() bypasses need_reset marking - [Low] media: ipu6: Primary error code overwritten during cleanup path in ipu6_isys_start_stream_firmware() --
commit 420d76dca7d258f867a9b52783e95225a692f015 Author: Sakari Ailus sakari.ailus@linux.intel.com
media: ipu6: Return errors from stream stop and close
If the firmware fails to start, stop or close a stream, either by telling about it with an error or due to a timeout, it probably requires a reset before being operational again. Mark isys needing a reset in such cases.
diff --git a/drivers/media/pci/intel/ipu6/ipu6-isys-video.c b/drivers/media/pci/intel/ipu6/ipu6-isys-video.c index 44541aff79b30..799a4be3160b5 100644 --- a/drivers/media/pci/intel/ipu6/ipu6-isys-video.c +++ b/drivers/media/pci/intel/ipu6/ipu6-isys-video.c @@ -543,25 +543,31 @@ int ipu6_isys_start_stream_firmware(struct ipu6_isys_stream *stream, out_stream_close: reinit_completion(&stream->stream_close_completion);
- scoped_guard(mutex, &stream->isys->mutex)
stream->isys->need_reset = true;- retout = fw_ops->stream_close(stream->isys, stream->stream_handle); if (retout < 0) { dev_dbg(dev, "can't close stream (%d)\n", retout);
return retout;
return ret;}
tout = wait_for_completion_timeout(&stream->stream_close_completion, IPU6_FW_CALL_TIMEOUT_JIFFIES);
- if (!tout)
- if (!tout) { dev_err(dev, "stream close time out\n");
- else if (stream->error)
ret = -ETIMEDOUT;- } else if (stream->error) { dev_err(dev, "stream close error: %d\n", stream->error);
- else
ret = -EINVAL;- } else { dev_dbg(dev, "stream close complete\n");
- }
[Severity: Low] Does this code inadvertently clobber the primary stream start error code?
If fw_ops->stream_start() fails, execution jumps to the out_stream_close label with ret holding the primary error code. If the subsequent firmware close command times out or encounters a stream error, the newly added braces update ret to -ETIMEDOUT or -EINVAL, overwriting the original error before returning it to the caller.
return ret; }
-void ipu6_isys_stop_stream_firmware(struct ipu6_isys_stream *stream) +int ipu6_isys_stop_stream_firmware(struct ipu6_isys_stream *stream) { struct ipu6_bus_device *adev = stream->asd->isys->adev; const struct ipu6_fw_isys_ops *fw_ops = adev->auxdrv_data->fw_ops; @@ -573,20 +579,30 @@ void ipu6_isys_stop_stream_firmware(struct ipu6_isys_stream *stream) ret = fw_ops->stream_flush(stream->isys, stream->stream_handle); if (ret < 0) { dev_err(dev, "can't stop stream (%d)\n", ret);
return;
return -EBUSY;
[Severity: Medium] Does this early return inadvertently bypass marking the device for a reset?
If fw_ops->stream_flush() returns an error, this path returns -EBUSY and completely skips the newly added logic at the end of the function:
if (ret) { scoped_guard(mutex, &stream->isys->mutex) stream->isys->need_reset = true; }
Because this skips the reset logic, it appears to contradict the commit message's stated intent to mark the device for reset when firmware fails to stop a stream.
}
tout = wait_for_completion_timeout(&stream->stream_stop_completion, IPU6_FW_CALL_TIMEOUT_JIFFIES);
[ ... ]
@@ -599,22 +615,33 @@ void ipu6_isys_close_stream_firmware(struct ipu6_isys_stream *stream) ret = fw_ops->stream_close(stream->isys, stream->stream_handle); if (ret < 0) { dev_err(dev, "can't close stream (%d)\n", ret);
return;
goto out_cleanup;}
tout = wait_for_completion_timeout(&stream->stream_close_completion, IPU6_FW_CALL_TIMEOUT_JIFFIES);
- if (!tout)
- if (!tout) { dev_warn(dev, "stream close time out\n");
- else if (stream->error)
ret = -ETIMEDOUT;- } else if (stream->error) { dev_warn(dev, "stream close error: %d\n", stream->error);
- else
ret = -EINVAL;- } else { dev_dbg(dev, "close stream: complete\n");
- }
+out_cleanup: scoped_guard(spinlock_irqsave, &stream->isys->streams_lock) { stream->isys->streams_by_handle[stream->stream_handle] = NULL; csi2->streams_by_vc[stream->vc] = NULL; }
[Severity: High] Does this error path introduce an out-of-bounds memory write if a malicious or buggy sensor provides an invalid vc value?
The stream->vc value originates from an external subdevice (sensor) driver's get_frame_desc operation. Because the V4L2 core does not enforce bounds on vc, the value can exceed NR_OF_CSI2_VC (16).
If a stream close fails and execution jumps to the out_cleanup label:
csi2->streams_by_vc[stream->vc] = NULL;
an unbounded vc value will overwrite subsequent fields in the ipu6_isys_csi2 struct, such as the base iomem pointer.
- if (ret) {
scoped_guard(mutex, &stream->isys->mutex)stream->isys->need_reset = true;- }
- return ret;
}
struct ipu6_isys_stream *