Skip to contentSkip to conversation

powerpc/kexec_file: Use inclusive range checks for excluded memory

PATCH Applied Thorsten Blum 3 participants 3 messages Aug 10 – Sep 9 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc/kexec_file: Use inclusive range checks for excluded memory

arch_check_excluded_range() checks if a kexec segment overlaps an excluded memory range.

Both ranges use inclusive end addresses, but the overlap check uses exclusive comparisons. This skips ranges with start == ->ranges[i].end or end == ->ranges[i].start. Use inclusive comparisons instead.

Fixes 6e5250eaa665 ("powerpc/crash: use generic APIs to locate memory hole for kdump")

---
Sashiko found this issue when reviewing another patch:
https://sashiko.dev/#/patchset/20260809162403.18142-2-thorsten.blum%40linux.dev

---
 arch/powerpc/kexec/file_load_64.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kexec/file_load_64.c +1 -1
index 40b74cc4ed3e..32e2b7412a9f 100644
@@ -58,7 +58,7 @@ int arch_check_excluded_range(struct kimage *image, unsigned long start,
 
 	emem = image->arch.exclude_ranges;
 	for (i = 0; i < emem->nr_ranges; i++)
-		if (start < emem->ranges[i].end && end > emem->ranges[i].start)
+		if (start <= emem->ranges[i].end && end >= emem->ranges[i].start)
 			return 1;
 
 	return 0;
Reviewed-by on v1 1/1
#1 lore raw
Quoted 21 lines · Thorsten Blum

arch_check_excluded_range() checks if a kexec segment overlaps an excluded memory range.

Both ranges use inclusive end addresses, but the overlap check uses exclusive comparisons. This skips ranges with start == ->ranges[i].end or end == ->ranges[i].start. Use inclusive comparisons instead.

Fixes 6e5250eaa665 ("powerpc/crash: use generic APIs to locate memory hole for kdump")

---
Sashiko found this issue when reviewing another patch:
https://sashiko.dev/#/patchset/20260809162403.18142-2-thorsten.blum%40linux.dev

---
  arch/powerpc/kexec/file_load_64.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kexec/file_load_64.c +0 -0
index 40b74cc4ed3e..32e2b7412a9f 100644

arch/powerpc/kexec/file_load_64.c int arch_check_excluded_range(struct kimage *image, unsigned long start, · line 61

Quoted 5 lines
arch/powerpc/kexec/file_load_64.c +1 -1
@@ -58,7 +58,7 @@ int arch_check_excluded_range(struct kimage *image, unsigned long start,
 
  	emem = image->arch.exclude_ranges;
  	for (i = 0; i < emem->nr_ranges; i++)
-		if (start < emem->ranges[i].end && end > emem->ranges[i].start)
+		if (start <= emem->ranges[i].end && end >= emem->ranges[i].start)

Like [1] this also extends the condition to check for a 1-byte overlap. It is unlikely to occur in practice, but I don't see any harm in doing so. Hence the changes looks good to me. Feel free to add.

[1] https://lore.kernel.org/all/[email protected]/

Quoted 3 lines
arch/powerpc/kexec/file_load_64.c +0 -0
  			return 1;
 
  	return 0;
maintainer Applied
#2 lore raw
In reply to Thorsten Blum
Quoted 8 lines · Thorsten Blum

arch_check_excluded_range() checks if a kexec segment overlaps an excluded memory range.

Both ranges use inclusive end addresses, but the overlap check uses exclusive comparisons. This skips ranges with start == ->ranges[i].end or end == ->ranges[i].start. Use inclusive comparisons instead.

[...]

Applied to powerpc/fixes.

[1/1] powerpc/kexec_file: Use inclusive range checks for excluded memory

      https://git.kernel.org/powerpc/c/449f60f99f8f3cbe80a9bd2242945e827c5ed003

cheers