RAS/AMD/ATL: Fix array overflow in get_logical_coh_st_fabric_id_mi300()

Message ID 279c8b5e-6c00-467a-9071-9c67926abea4@moroto.mountain
State New
Headers
Series RAS/AMD/ATL: Fix array overflow in get_logical_coh_st_fabric_id_mi300() |

Commit Message

Dan Carpenter Jan. 31, 2024, 8:24 a.m. UTC
  Check against ARRAY_SIZE() which is the number of elements instead of
sizeof() which is the number of bytes.  Otherwise we potentially read
beyond the end of the phy_to_log_coh_st_map_mi300[] array.

Fixes: 453f0ae79732 ("RAS/AMD/ATL: Add MI300 support")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 drivers/ras/amd/atl/denormalize.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Borislav Petkov Jan. 31, 2024, 8:49 a.m. UTC | #1
On Wed, Jan 31, 2024 at 11:24:25AM +0300, Dan Carpenter wrote:
> Check against ARRAY_SIZE() which is the number of elements instead of
> sizeof() which is the number of bytes.  Otherwise we potentially read
> beyond the end of the phy_to_log_coh_st_map_mi300[] array.
> 
> Fixes: 453f0ae79732 ("RAS/AMD/ATL: Add MI300 support")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
>  drivers/ras/amd/atl/denormalize.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/ras/amd/atl/denormalize.c b/drivers/ras/amd/atl/denormalize.c
> index d5d0e1fda159..49a900e066f1 100644
> --- a/drivers/ras/amd/atl/denormalize.c
> +++ b/drivers/ras/amd/atl/denormalize.c
> @@ -405,7 +405,7 @@ static const u16 phy_to_log_coh_st_map_mi300[] = {
>  
>  static u16 get_logical_coh_st_fabric_id_mi300(struct addr_ctx *ctx)
>  {
> -	if (ctx->inst_id >= sizeof(phy_to_log_coh_st_map_mi300)) {
> +	if (ctx->inst_id >= ARRAY_SIZE(phy_to_log_coh_st_map_mi300)) {
>  		atl_debug(ctx, "Instance ID out of range");
>  		return ~0;
>  	}
> -- 

Applied, thanks.
  

Patch

diff --git a/drivers/ras/amd/atl/denormalize.c b/drivers/ras/amd/atl/denormalize.c
index d5d0e1fda159..49a900e066f1 100644
--- a/drivers/ras/amd/atl/denormalize.c
+++ b/drivers/ras/amd/atl/denormalize.c
@@ -405,7 +405,7 @@  static const u16 phy_to_log_coh_st_map_mi300[] = {
 
 static u16 get_logical_coh_st_fabric_id_mi300(struct addr_ctx *ctx)
 {
-	if (ctx->inst_id >= sizeof(phy_to_log_coh_st_map_mi300)) {
+	if (ctx->inst_id >= ARRAY_SIZE(phy_to_log_coh_st_map_mi300)) {
 		atl_debug(ctx, "Instance ID out of range");
 		return ~0;
 	}