Re: [PATCH v3 1/3] accel/rocket: Validate BO handle counts on job submission
From: Sidong Yang
Date: Fri Aug 28 2026 - 01:49:20 EST
On Fri, Aug 28, 2026 at 01:08:03PM +0800, MoGGuU wrote:
> The input and output BO handle counts are __u32, while GEM lookup and
> reservation helpers take int counts. A count above INT_MAX cannot be
> represented safely by the GEM lookup helper.
>
> Reject each count above INT_MAX before looking up the BOs.
>
> rocket_job_push() already uses check_add_overflow() for the combined count,
> but stores the result in u32, so it only detects unsigned wraparound. Store
> the result in int so sums above INT_MAX are rejected before the count is
> passed to the reservation helpers.
>
> Fixes: 0810d5ad88a1 ("accel/rocket: Add job submission IOCTL")
> Cc: stable@xxxxxxxxxxxxxxx
> Tested-by: Sidong Yang <sidong.yang@xxxxxxxxxx>
> Signed-off-by: MoGGuU <Naixumogu@xxxxxxxxxxx>
> ---
> drivers/accel/rocket/rocket_job.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/accel/rocket/rocket_job.c b/drivers/accel/rocket/rocket_job.c
> index bb77b6bf0f231..e6052d1973afa 100644
> --- a/drivers/accel/rocket/rocket_job.c
> +++ b/drivers/accel/rocket/rocket_job.c
> @@ -190,7 +190,7 @@ static int rocket_job_push(struct rocket_job *job)
> struct rocket_device *rdev = job->rdev;
> struct drm_gem_object **bos;
> struct ww_acquire_ctx acquire_ctx;
> - u32 bo_count;
> + int bo_count;
> int ret = 0;
>
> if (check_add_overflow(job->in_bo_count, job->out_bo_count, &bo_count))
> @@ -556,6 +556,11 @@ static int rocket_ioctl_submit_job(struct drm_device *dev, struct drm_file *file
> if (job->task_count == 0)
> return -EINVAL;
>
> + /* GEM lookup takes a signed object count. */
> + if (job->in_bo_handle_count > INT_MAX ||
> + job->out_bo_handle_count > INT_MAX)
> + return -EINVAL;
> +
> rjob = kzalloc_obj(*rjob);
> if (!rjob)
> return -ENOMEM;
> --
> 2.43.0
>
Looks good now, thanks.
Reviewed-by: Sidong Yang <sidong.yang@xxxxxxxxxx>