Skip to contentSkip to conversation

powerpc/kexec_file: Use inclusive range checks in add_usable_mem()

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

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc/kexec_file: Use inclusive range checks in add_usable_mem()

add_usable_mem() adds usable memory ranges for the kdump kernel.

The ranges are inclusive, but the partial overlap check uses exclusive comparisons. This skips ranges with base == loc_end or end == loc_base. Use inclusive comparisons instead.

Fixes 7c64e21a1c5a ("powerpc/kexec_file: Restrict memory usage of kdump kernel")
---
 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 8c72e12ea44e..f9e872693ca7 100644
@@ -113,7 +113,7 @@ static int add_usable_mem(struct umem_info *um_info, u64 base, u64 end)
 		loc_end = um_info->ranges[i].end;
 		if (loc_base >= base && loc_end <= end)
 			add = true;
-		else if (base < loc_end && end > loc_base) {
+		else if (base <= loc_end && end >= loc_base) {
 			if (loc_base < base)
 				loc_base = base;
 			if (loc_end > end)
#1 lore raw
Quoted 17 lines · Thorsten Blum

add_usable_mem() adds usable memory ranges for the kdump kernel.

The ranges are inclusive, but the partial overlap check uses exclusive comparisons. This skips ranges with base == loc_end or end == loc_base. Use inclusive comparisons instead.

Fixes 7c64e21a1c5a ("powerpc/kexec_file: Restrict memory usage of kdump kernel")
---
  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 8c72e12ea44e..f9e872693ca7 100644

arch/powerpc/kexec/file_load_64.c static int add_usable_mem(struct umem_info *um_info, u64 base, u64 end) · line 116

Quoted 5 lines
arch/powerpc/kexec/file_load_64.c +1 -1
@@ -113,7 +113,7 @@ static int add_usable_mem(struct umem_info *um_info, u64 base, u64 end)
  		loc_end = um_info->ranges[i].end;
  		if (loc_base >= base && loc_end <= end)
  			add = true;
-		else if (base < loc_end && end > loc_base) {
+		else if (base <= loc_end && end >= loc_base) {

This is interesting. The updated condition basically handles exactly a one-byte overlap on either side of the usable memory ranges. In practice, it is very unlikely that we would have such usable memory and LMB ranges.

Thorsten, have you encountered any problem that led you to propose this fix?

- Sourabh Jain

Quoted 3 lines
arch/powerpc/kexec/file_load_64.c +0 -0
  			if (loc_base < base)
  				loc_base = base;
  			if (loc_end > end)
#2 lore raw
Quoted 28 lines · Sourabh Jain
Quoted 17 lines · Thorsten Blum

add_usable_mem() adds usable memory ranges for the kdump kernel.

The ranges are inclusive, but the partial overlap check uses exclusive comparisons. This skips ranges with base == loc_end or end == loc_base. Use inclusive comparisons instead.

Fixes 7c64e21a1c5a ("powerpc/kexec_file: Restrict memory usage of kdump kernel")
---
  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 8c72e12ea44e..f9e872693ca7 100644

arch/powerpc/kexec/file_load_64.c static int add_usable_mem(struct umem_info *um_info, u64 base, u64 end) · line 116

Quoted 5 lines
arch/powerpc/kexec/file_load_64.c +1 -1
@@ -113,7 +113,7 @@ static int add_usable_mem(struct umem_info *um_info, u64 base, u64 end)
  		loc_end = um_info->ranges[i].end;
  		if (loc_base >= base && loc_end <= end)
  			add = true;
-		else if (base < loc_end && end > loc_base) {
+		else if (base <= loc_end && end >= loc_base) {

This is interesting. The updated condition basically handles exactly a one-byte overlap on either side of the usable memory ranges. In practice, it is very unlikely that we would have such usable memory and LMB ranges.

Quoted 1 line

Thorsten, have you encountered any problem that led you to propose this fix?

Found by inspection only and I agree that this is unlikely in practice, which is why I didn't cc stable. Same for the other patch [1].

Thanks for the review.

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

Reviewed-by
#3 lore raw
Quoted 28 lines · Thorsten Blum
Quoted 27 lines · Sourabh Jain
Quoted 17 lines · Thorsten Blum

add_usable_mem() adds usable memory ranges for the kdump kernel.

The ranges are inclusive, but the partial overlap check uses exclusive comparisons. This skips ranges with base == loc_end or end == loc_base. Use inclusive comparisons instead.

Fixes 7c64e21a1c5a ("powerpc/kexec_file: Restrict memory usage of kdump kernel")
---
   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 8c72e12ea44e..f9e872693ca7 100644

arch/powerpc/kexec/file_load_64.c static int add_usable_mem(struct umem_info *um_info, u64 base, u64 end) · line 116

Quoted 5 lines
arch/powerpc/kexec/file_load_64.c +1 -1
@@ -113,7 +113,7 @@ static int add_usable_mem(struct umem_info *um_info, u64 base, u64 end)
   		loc_end = um_info->ranges[i].end;
   		if (loc_base >= base && loc_end <= end)
   			add = true;
-		else if (base < loc_end && end > loc_base) {
+		else if (base <= loc_end && end >= loc_base) {

This is interesting. The updated condition basically handles exactly a one-byte overlap on either side of the usable memory ranges. In practice, it is very unlikely that we would have such usable memory and LMB ranges.

Quoted 7 lines
Quoted 1 line

Thorsten, have you encountered any problem that led you to propose this fix?

Found by inspection only and I agree that this is unlikely in practice, which is why I didn't cc stable. Same for the other patch [1].

Thanks for the review.

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

The changes look good to me. Feel free to add:

maintainer Applied
#4 lore raw
In reply to Thorsten Blum
Quoted 8 lines · Thorsten Blum

add_usable_mem() adds usable memory ranges for the kdump kernel.

The ranges are inclusive, but the partial overlap check uses exclusive comparisons. This skips ranges with base == loc_end or end == loc_base. Use inclusive comparisons instead.

[...]

Applied to powerpc/fixes.

[1/1] powerpc/kexec_file: Use inclusive range checks in add_usable_mem()

      https://git.kernel.org/powerpc/c/c6755be4838d6ccd641effbcdc3d917b82631ff9

cheers