Skip to contentSkip to conversation

fix array boundary check in find_logical_id

PATCH In review Andre Przywara 2 participants 3 messages May 17, 2022 – Oct 4, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix array boundary check in find_logical_id

When we are trying to find the array index for a given MPIDR, we check that we don't overrun the array boundary, by comparing against NR_CPUS. However the resulting conditional branch should also fire when we reach the exact number of elements, since it's all 0 based.

Change the comparison to be '>=' instead of just '>', to only allow array indicies 0 .. (NR_CPUS - 1).

---
 arch/aarch32/utils.S | 2 +-
 arch/aarch64/utils.S | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/aarch32/utils.S +1 -1
index 58279aa..d28ab19 100644
@@ -24,7 +24,7 @@ ASM_FUNC(find_logical_id)
 1:	mov	r3, #NR_CPUS
 
 	cmp	r1, r3
-	bgt	3f
+	bge	3f
 	ldr	r3, [r2, r1, lsl #2]
 	cmp	r3, r0
 	beq	2f
arch/aarch64/utils.S +1 -1
index 32393cc..89aa124 100644
@@ -22,7 +22,7 @@ ASM_FUNC(find_logical_id)
 	mov	x1, xzr
 1:	mov	x3, #NR_CPUS	// check we haven't walked off the end of the array
 	cmp	x1, x3
-	b.gt	3f
+	b.ge	3f
 	ldr	x3, [x2, x1, lsl #3]
 	cmp	x3, x0
 	b.eq	2f
Signature · 7 lines
2.25.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#1 lore raw

On Tue, 17 May 2022 14:43:05 +0100
Andre Przywara <[email protected]> wrote:

Hi,

any chance someone can please have a look at this?

Cheers,
Andre

Quoted 32 lines

When we are trying to find the array index for a given MPIDR, we check that we don't overrun the array boundary, by comparing against NR_CPUS. However the resulting conditional branch should also fire when we reach the exact number of elements, since it's all 0 based.

Change the comparison to be '>=' instead of just '>', to only allow array indicies 0 .. (NR_CPUS - 1).

---
 arch/aarch32/utils.S | 2 +-
 arch/aarch64/utils.S | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/aarch32/utils.S +1 -1
index 58279aa..d28ab19 100644
@@ -24,7 +24,7 @@ ASM_FUNC(find_logical_id)
 1:	mov	r3, #NR_CPUS
 
 	cmp	r1, r3
-	bgt	3f
+	bge	3f
 	ldr	r3, [r2, r1, lsl #2]
 	cmp	r3, r0
 	beq	2f
arch/aarch64/utils.S +0 -0
index 32393cc..89aa124 100644

arch/aarch64/utils.S ASM_FUNC(find_logical_id) · line 28

Quoted 8 lines
arch/aarch64/utils.S +1 -1
@@ -22,7 +22,7 @@ ASM_FUNC(find_logical_id)
 	mov	x1, xzr
 1:	mov	x3, #NR_CPUS	// check we haven't walked off the end of the array
 	cmp	x1, x3
-	b.gt	3f
+	b.ge	3f
 	ldr	x3, [x2, x1, lsl #3]
 	cmp	x3, x0
 	b.eq	2f

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#2 lore raw
In reply to Andre Przywara
Quoted 9 lines · Andre Przywara

When we are trying to find the array index for a given MPIDR, we check that we don't overrun the array boundary, by comparing against NR_CPUS. However the resulting conditional branch should also fire when we reach the exact number of elements, since it's all 0 based.

Change the comparison to be '>=' instead of just '>', to only allow array indicies 0 .. (NR_CPUS - 1).

Thanks; applied.

Mark.

Quoted 34 lines
---
 arch/aarch32/utils.S | 2 +-
 arch/aarch64/utils.S | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/aarch32/utils.S +1 -1
index 58279aa..d28ab19 100644
@@ -24,7 +24,7 @@ ASM_FUNC(find_logical_id)
 1:	mov	r3, #NR_CPUS
 
 	cmp	r1, r3
-	bgt	3f
+	bge	3f
 	ldr	r3, [r2, r1, lsl #2]
 	cmp	r3, r0
 	beq	2f
arch/aarch64/utils.S +1 -1
index 32393cc..89aa124 100644
@@ -22,7 +22,7 @@ ASM_FUNC(find_logical_id)
 	mov	x1, xzr
 1:	mov	x3, #NR_CPUS	// check we haven't walked off the end of the array
 	cmp	x1, x3
-	b.gt	3f
+	b.ge	3f
 	ldr	x3, [x2, x1, lsl #3]
 	cmp	x3, x0
 	b.eq	2f
Signature · 1 line
2.25.1

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel