Skip to contentSkip to conversation

RAS/AMD/FMPM: Fix off by one in error handling

PATCH Applied Dan Carpenter 2 participants 2 messages Mar 6, 2024

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 RAS/AMD/FMPM: Fix off by one in error handling

Decrement "i" before the first iteration. Depending on where this fails it could free something from one element beyond the end of the fru_records[] array.

Fixes 6f15e617cc99 ("RAS: Introduce a FRU memory poison manager")
---
 drivers/ras/amd/fmpm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/ras/amd/fmpm.c +1 -1
index 0963c9e7b853..2f4ac9591c8f 100644
@@ -817,7 +817,7 @@ static int allocate_records(void)
 	return ret;
 
 out_free:
-	for (; i >= 0; i--)
+	while (--i >= 0)
 		kfree(fru_records[i]);
 
 	kfree(fru_records);
Signature · 1 line
2.43.0
maintainer Applied
#1 lore raw
Quoted 16 lines · Dan Carpenter

Decrement "i" before the first iteration. Depending on where this fails it could free something from one element beyond the end of the fru_records[] array.

Fixes 6f15e617cc99 ("RAS: Introduce a FRU memory poison manager")
---
 drivers/ras/amd/fmpm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/ras/amd/fmpm.c +0 -0
index 0963c9e7b853..2f4ac9591c8f 100644

drivers/ras/amd/fmpm.c static int allocate_records(void) · line 823

Quoted 8 lines
drivers/ras/amd/fmpm.c +1 -1
@@ -817,7 +817,7 @@ static int allocate_records(void)
 	return ret;
 
 out_free:
-	for (; i >= 0; i--)
+	while (--i >= 0)
 		kfree(fru_records[i]);
 
 	kfree(fru_records);

Applied, thanks.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette