Linux ARM-MSM sub-architecture
 help / color / mirror / Atom feed
* [PATCH] accel/qaic: Fix integer overflow in qaic_validate_req()
@ 2025-03-05 15:53 Dan Carpenter
  2025-03-06 19:12 ` Jeff Hugo
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2025-03-05 15:53 UTC (permalink / raw)
  To: Jeff Hugo
  Cc: Carl Vanderlip, Oded Gabbay, Jacek Lawrynowicz, Stanislaw Gruszka,
	linux-arm-msm, dri-devel, linux-kernel, kernel-janitors

These are u64 variables that come from the user via
qaic_attach_slice_bo_ioctl().  Ensure that the math doesn't have an
integer wrapping bug.

Cc: stable@vger.kernel.org
Fixes: ff13be830333 ("accel/qaic: Add datapath")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 drivers/accel/qaic/qaic_data.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/accel/qaic/qaic_data.c b/drivers/accel/qaic/qaic_data.c
index c20eb63750f5..cd5a31edba66 100644
--- a/drivers/accel/qaic/qaic_data.c
+++ b/drivers/accel/qaic/qaic_data.c
@@ -563,7 +563,8 @@ static int qaic_validate_req(struct qaic_device *qdev, struct qaic_attach_slice_
 		      invalid_sem(&slice_ent[i].sem2) || invalid_sem(&slice_ent[i].sem3))
 			return -EINVAL;
 
-		if (slice_ent[i].offset + slice_ent[i].size > total_size)
+		if (slice_ent[i].offset > U64_MAX - slice_ent[i].size ||
+		    slice_ent[i].offset + slice_ent[i].size > total_size)
 			return -EINVAL;
 	}
 
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] accel/qaic: Fix integer overflow in qaic_validate_req()
  2025-03-05 15:53 [PATCH] accel/qaic: Fix integer overflow in qaic_validate_req() Dan Carpenter
@ 2025-03-06 19:12 ` Jeff Hugo
  2025-03-07  7:28   ` Dan Carpenter
  0 siblings, 1 reply; 3+ messages in thread
From: Jeff Hugo @ 2025-03-06 19:12 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Carl Vanderlip, Oded Gabbay, Jacek Lawrynowicz, Stanislaw Gruszka,
	linux-arm-msm, dri-devel, linux-kernel, kernel-janitors

On 3/5/2025 8:53 AM, Dan Carpenter wrote:
> These are u64 variables that come from the user via
> qaic_attach_slice_bo_ioctl().  Ensure that the math doesn't have an
> integer wrapping bug.
> 
> Cc: stable@vger.kernel.org
> Fixes: ff13be830333 ("accel/qaic: Add datapath")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
>   drivers/accel/qaic/qaic_data.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/accel/qaic/qaic_data.c b/drivers/accel/qaic/qaic_data.c
> index c20eb63750f5..cd5a31edba66 100644
> --- a/drivers/accel/qaic/qaic_data.c
> +++ b/drivers/accel/qaic/qaic_data.c
> @@ -563,7 +563,8 @@ static int qaic_validate_req(struct qaic_device *qdev, struct qaic_attach_slice_
>   		      invalid_sem(&slice_ent[i].sem2) || invalid_sem(&slice_ent[i].sem3))
>   			return -EINVAL;
>   
> -		if (slice_ent[i].offset + slice_ent[i].size > total_size)
> +		if (slice_ent[i].offset > U64_MAX - slice_ent[i].size ||
> +		    slice_ent[i].offset + slice_ent[i].size > total_size)
>   			return -EINVAL;
>   	}
>   

I agree this is an issue that needs to be addressed.  However, it seems 
that overflow checking helpers exist (include/linux/overflow.h), 
therefore open coding a check feels non-preferable.  I think 
check_add_overflow() would be the way to go.  Do you agree?

-Jeff

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] accel/qaic: Fix integer overflow in qaic_validate_req()
  2025-03-06 19:12 ` Jeff Hugo
@ 2025-03-07  7:28   ` Dan Carpenter
  0 siblings, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2025-03-07  7:28 UTC (permalink / raw)
  To: Jeff Hugo
  Cc: Carl Vanderlip, Oded Gabbay, Jacek Lawrynowicz, Stanislaw Gruszka,
	linux-arm-msm, dri-devel, linux-kernel, kernel-janitors

On Thu, Mar 06, 2025 at 12:12:53PM -0700, Jeff Hugo wrote:
> On 3/5/2025 8:53 AM, Dan Carpenter wrote:
> > These are u64 variables that come from the user via
> > qaic_attach_slice_bo_ioctl().  Ensure that the math doesn't have an
> > integer wrapping bug.
> > 
> > Cc: stable@vger.kernel.org
> > Fixes: ff13be830333 ("accel/qaic: Add datapath")
> > Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> > ---
> >   drivers/accel/qaic/qaic_data.c | 3 ++-
> >   1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/accel/qaic/qaic_data.c b/drivers/accel/qaic/qaic_data.c
> > index c20eb63750f5..cd5a31edba66 100644
> > --- a/drivers/accel/qaic/qaic_data.c
> > +++ b/drivers/accel/qaic/qaic_data.c
> > @@ -563,7 +563,8 @@ static int qaic_validate_req(struct qaic_device *qdev, struct qaic_attach_slice_
> >   		      invalid_sem(&slice_ent[i].sem2) || invalid_sem(&slice_ent[i].sem3))
> >   			return -EINVAL;
> > -		if (slice_ent[i].offset + slice_ent[i].size > total_size)
> > +		if (slice_ent[i].offset > U64_MAX - slice_ent[i].size ||
> > +		    slice_ent[i].offset + slice_ent[i].size > total_size)
> >   			return -EINVAL;
> >   	}
> 
> I agree this is an issue that needs to be addressed.  However, it seems that
> overflow checking helpers exist (include/linux/overflow.h), therefore open
> coding a check feels non-preferable.  I think check_add_overflow() would be
> the way to go.  Do you agree?

Sure.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-03-07  7:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-05 15:53 [PATCH] accel/qaic: Fix integer overflow in qaic_validate_req() Dan Carpenter
2025-03-06 19:12 ` Jeff Hugo
2025-03-07  7:28   ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox