diff mbox series

[next] drm/amdgpu: Fix off by one in current_memory_partition_show()

Message ID f3cf409f-2b04-444f-88f0-9b4cfe290667@stanley.mountain (mailing list archive)
State New, archived
Headers show
Series [next] drm/amdgpu: Fix off by one in current_memory_partition_show() | expand

Commit Message

Dan Carpenter Oct. 10, 2024, 6:35 p.m. UTC
The >= ARRAY_SIZE() should be > ARRAY_SIZE() to prevent an out of
bounds read.

Fixes: 012be6f22c01 ("drm/amdgpu: Add sysfs interfaces for NPS mode")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Lazar, Lijo Oct. 11, 2024, 3:05 a.m. UTC | #1
On 10/11/2024 12:05 AM, Dan Carpenter wrote:
> The >= ARRAY_SIZE() should be > ARRAY_SIZE() to prevent an out of
> bounds read.
> 
> Fixes: 012be6f22c01 ("drm/amdgpu: Add sysfs interfaces for NPS mode")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>

Reviewed-by: Lijo Lazar <lijo.lazar@amd.com>

Thanks,
Lijo

> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
> index ddf716d27f3a..75c9291ac3eb 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
> @@ -1199,7 +1199,7 @@ static ssize_t current_memory_partition_show(
>  	enum amdgpu_memory_partition mode;
>  
>  	mode = adev->gmc.gmc_funcs->query_mem_partition_mode(adev);
> -	if ((mode > ARRAY_SIZE(nps_desc)) ||
> +	if ((mode >= ARRAY_SIZE(nps_desc)) ||
>  	    (BIT(mode) & AMDGPU_ALL_NPS_MASK) != BIT(mode))
>  		return sysfs_emit(buf, "UNKNOWN\n");
>
Alex Deucher Oct. 14, 2024, 6:04 p.m. UTC | #2
Applied.  Thanks!

Alex

On Thu, Oct 10, 2024 at 11:18 PM Lazar, Lijo <lijo.lazar@amd.com> wrote:
>
>
>
> On 10/11/2024 12:05 AM, Dan Carpenter wrote:
> > The >= ARRAY_SIZE() should be > ARRAY_SIZE() to prevent an out of
> > bounds read.
> >
> > Fixes: 012be6f22c01 ("drm/amdgpu: Add sysfs interfaces for NPS mode")
> > Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
>
> Reviewed-by: Lijo Lazar <lijo.lazar@amd.com>
>
> Thanks,
> Lijo
>
> > ---
> >  drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
> > index ddf716d27f3a..75c9291ac3eb 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
> > @@ -1199,7 +1199,7 @@ static ssize_t current_memory_partition_show(
> >       enum amdgpu_memory_partition mode;
> >
> >       mode = adev->gmc.gmc_funcs->query_mem_partition_mode(adev);
> > -     if ((mode > ARRAY_SIZE(nps_desc)) ||
> > +     if ((mode >= ARRAY_SIZE(nps_desc)) ||
> >           (BIT(mode) & AMDGPU_ALL_NPS_MASK) != BIT(mode))
> >               return sysfs_emit(buf, "UNKNOWN\n");
> >
diff mbox series

Patch

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
index ddf716d27f3a..75c9291ac3eb 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
@@ -1199,7 +1199,7 @@  static ssize_t current_memory_partition_show(
 	enum amdgpu_memory_partition mode;
 
 	mode = adev->gmc.gmc_funcs->query_mem_partition_mode(adev);
-	if ((mode > ARRAY_SIZE(nps_desc)) ||
+	if ((mode >= ARRAY_SIZE(nps_desc)) ||
 	    (BIT(mode) & AMDGPU_ALL_NPS_MASK) != BIT(mode))
 		return sysfs_emit(buf, "UNKNOWN\n");