All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/imagination: Fixed infinite loop in pvr_vm_mips_map()
@ 2023-12-08 16:08 ` Donald Robson
  0 siblings, 0 replies; 4+ messages in thread
From: Donald Robson @ 2023-12-08 16:08 UTC (permalink / raw)
  To: dri-devel, linux-kernel
  Cc: frank.binns, donald.robson, matt.coster, maarten.lankhorst,
	mripard, tzimmermann, airlied, daniel, Dan Carpenter

Unwinding loop in error path for this function uses unsigned limit
variable, causing the promotion of the signed counter variable.

--> 204         for (; pfn >= start_pfn; pfn--)
                       ^^^^^^^^^^^^^^^^
If start_pfn can be zero then this is an endless loop.  I've seen this
code in other places as well.  This loop is slightly off as well.  It
should decrement pfn on the first iteration.

Fix by making the loop limit variables signed. Also fix missing
predecrement by modifying to while loop.

Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Donald Robson <donald.robson@imgtec.com>
---
 drivers/gpu/drm/imagination/pvr_vm_mips.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/imagination/pvr_vm_mips.c b/drivers/gpu/drm/imagination/pvr_vm_mips.c
index 2bc7181a4c3e..b7fef3c797e6 100644
--- a/drivers/gpu/drm/imagination/pvr_vm_mips.c
+++ b/drivers/gpu/drm/imagination/pvr_vm_mips.c
@@ -152,8 +152,8 @@ pvr_vm_mips_map(struct pvr_device *pvr_dev, struct pvr_fw_object *fw_obj)
 	u64 end;
 	u32 cache_policy;
 	u32 pte_flags;
-	u32 start_pfn;
-	u32 end_pfn;
+	s32 start_pfn;
+	s32 end_pfn;
 	s32 pfn;
 	int err;
 
@@ -201,7 +201,7 @@ pvr_vm_mips_map(struct pvr_device *pvr_dev, struct pvr_fw_object *fw_obj)
 	return 0;
 
 err_unmap_pages:
-	for (; pfn >= start_pfn; pfn--)
+	while (--pfn >= start_pfn)
 		WRITE_ONCE(mips_data->pt[pfn], 0);
 
 	pvr_mmu_flush_request_all(pvr_dev);
-- 
2.25.1


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

* [PATCH] drm/imagination: Fixed infinite loop in pvr_vm_mips_map()
@ 2023-12-08 16:08 ` Donald Robson
  0 siblings, 0 replies; 4+ messages in thread
From: Donald Robson @ 2023-12-08 16:08 UTC (permalink / raw)
  To: dri-devel, linux-kernel
  Cc: mripard, matt.coster, donald.robson, tzimmermann, Dan Carpenter

Unwinding loop in error path for this function uses unsigned limit
variable, causing the promotion of the signed counter variable.

--> 204         for (; pfn >= start_pfn; pfn--)
                       ^^^^^^^^^^^^^^^^
If start_pfn can be zero then this is an endless loop.  I've seen this
code in other places as well.  This loop is slightly off as well.  It
should decrement pfn on the first iteration.

Fix by making the loop limit variables signed. Also fix missing
predecrement by modifying to while loop.

Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Donald Robson <donald.robson@imgtec.com>
---
 drivers/gpu/drm/imagination/pvr_vm_mips.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/imagination/pvr_vm_mips.c b/drivers/gpu/drm/imagination/pvr_vm_mips.c
index 2bc7181a4c3e..b7fef3c797e6 100644
--- a/drivers/gpu/drm/imagination/pvr_vm_mips.c
+++ b/drivers/gpu/drm/imagination/pvr_vm_mips.c
@@ -152,8 +152,8 @@ pvr_vm_mips_map(struct pvr_device *pvr_dev, struct pvr_fw_object *fw_obj)
 	u64 end;
 	u32 cache_policy;
 	u32 pte_flags;
-	u32 start_pfn;
-	u32 end_pfn;
+	s32 start_pfn;
+	s32 end_pfn;
 	s32 pfn;
 	int err;
 
@@ -201,7 +201,7 @@ pvr_vm_mips_map(struct pvr_device *pvr_dev, struct pvr_fw_object *fw_obj)
 	return 0;
 
 err_unmap_pages:
-	for (; pfn >= start_pfn; pfn--)
+	while (--pfn >= start_pfn)
 		WRITE_ONCE(mips_data->pt[pfn], 0);
 
 	pvr_mmu_flush_request_all(pvr_dev);
-- 
2.25.1


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

* Re: (subset) [PATCH] drm/imagination: Fixed infinite loop in pvr_vm_mips_map()
  2023-12-08 16:08 ` Donald Robson
@ 2023-12-15 13:13   ` Maxime Ripard
  -1 siblings, 0 replies; 4+ messages in thread
From: Maxime Ripard @ 2023-12-15 13:13 UTC (permalink / raw)
  To: dri-devel, linux-kernel, Donald Robson
  Cc: frank.binns, matt.coster, maarten.lankhorst, tzimmermann,
	airlied, daniel, Dan Carpenter

On Fri, 08 Dec 2023 16:08:25 +0000, Donald Robson wrote:
> Unwinding loop in error path for this function uses unsigned limit
> variable, causing the promotion of the signed counter variable.
> 
> --> 204         for (; pfn >= start_pfn; pfn--)
>                        ^^^^^^^^^^^^^^^^
> If start_pfn can be zero then this is an endless loop.  I've seen this
> code in other places as well.  This loop is slightly off as well.  It
> should decrement pfn on the first iteration.
> 
> [...]

Applied to drm/drm-misc (drm-misc-next-fixes).

Thanks!
Maxime


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

* Re: (subset) [PATCH] drm/imagination: Fixed infinite loop in pvr_vm_mips_map()
@ 2023-12-15 13:13   ` Maxime Ripard
  0 siblings, 0 replies; 4+ messages in thread
From: Maxime Ripard @ 2023-12-15 13:13 UTC (permalink / raw)
  To: dri-devel, linux-kernel, Donald Robson
  Cc: tzimmermann, matt.coster, Dan Carpenter

On Fri, 08 Dec 2023 16:08:25 +0000, Donald Robson wrote:
> Unwinding loop in error path for this function uses unsigned limit
> variable, causing the promotion of the signed counter variable.
> 
> --> 204         for (; pfn >= start_pfn; pfn--)
>                        ^^^^^^^^^^^^^^^^
> If start_pfn can be zero then this is an endless loop.  I've seen this
> code in other places as well.  This loop is slightly off as well.  It
> should decrement pfn on the first iteration.
> 
> [...]

Applied to drm/drm-misc (drm-misc-next-fixes).

Thanks!
Maxime


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

end of thread, other threads:[~2023-12-15 13:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-08 16:08 [PATCH] drm/imagination: Fixed infinite loop in pvr_vm_mips_map() Donald Robson
2023-12-08 16:08 ` Donald Robson
2023-12-15 13:13 ` (subset) " Maxime Ripard
2023-12-15 13:13   ` Maxime Ripard

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.