staging: media: atomisp: validate DVS 6-axis config dimensions
Subsystems (4)
PATCH v2 1/1 staging: media: atomisp: validate DVS 6-axis config dimensions
The atomisp driver allocates the DVS 6-axis coordinate buffers using the stream geometry, but copies from userspace using the dimensions supplied in the ioctl argument. If the user-supplied dimensions are larger than the stream geometry, copy_from_compatible() writes past the end of the allocated buffer.
Validate that the user-supplied dimensions match the allocated table before copying.
Note on commit d178c7ca8fef ("staging: media: atomisp: use array3_size() for overflow-safe allocation"): that commit fixed the multiplication wrap in these same allocations. It does not change which dimensions are used for the copy, so the two issues are independent.
---
Changes in v2:
- Use the existing error path (set ret to -EINVAL and goto error) instead of an open-coded free and return, as reported by the Media CI smatch check ("missing unwind goto?").
- Wrap the dev_err_ratelimited() call.
- Cc all atomisp and staging maintainers.
.../staging/media/atomisp/pci/atomisp_cmd.c | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+)
drivers/staging/media/atomisp/pci/atomisp_cmd.c +20 -0
@@ -2629,6 +2629,16 @@ int atomisp_cp_dvs_6axis_config(struct atomisp_sub_device *asd,return -ENOMEM ; } +if (t_6axis_config.width_y != dvs_6axis_config->width_y || + t_6axis_config.height_y != dvs_6axis_config->height_y || + t_6axis_config.width_uv != dvs_6axis_config->width_uv || + t_6axis_config.height_uv != dvs_6axis_config->height_uv) { +dev_err_ratelimited (asd->isp->dev, +"invalid DVS 6-axis table dimensions\n" ); + ret = -EINVAL ; + goto error; + } + dvs_6axis_config->exp_id = t_6axis_config.exp_id; if (copy_from_compatible(dvs_6axis_config->xcoords_y,
@@ -2681,6 +2691,16 @@ int atomisp_cp_dvs_6axis_config(struct atomisp_sub_device *asd, } } +if (source_6axis_config->width_y != dvs_6axis_config->width_y || + source_6axis_config->height_y != dvs_6axis_config->height_y || + source_6axis_config->width_uv != dvs_6axis_config->width_uv || + source_6axis_config->height_uv != dvs_6axis_config->height_uv) { +dev_err_ratelimited (asd->isp->dev, +"invalid DVS 6-axis table dimensions\n" ); + ret = -EINVAL ; + goto error; + } + dvs_6axis_config->exp_id = source_6axis_config->exp_id; if (copy_from_compatible(dvs_6axis_config->xcoords_y,
Signature · 1 line
2.55.0