Skip to content

Commit ec85bd3

Browse files
author
Russell King (Oracle)
committed
ARM: findbit: fix overflowing offset
When offset is larger than the size of the bit array, we should not attempt to access the array as we can perform an access beyond the end of the array. Fix this by changing the pre-condition. Using "cmp r2, r1; bhs ..." covers us for the size == 0 case, since this will always take the branch when r1 is zero, irrespective of the value of r2. This means we can fix this bug without adding any additional code! Tested-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
1 parent fb0fd34 commit ec85bd3

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

arch/arm/lib/findbit.S

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ ENDPROC(_find_first_zero_bit_le)
4040
* Prototype: int find_next_zero_bit(void *addr, unsigned int maxbit, int offset)
4141
*/
4242
ENTRY(_find_next_zero_bit_le)
43-
teq r1, #0
44-
beq 3b
43+
cmp r2, r1
44+
bhs 3b
4545
ands ip, r2, #7
4646
beq 1b @ If new byte, goto old routine
4747
ARM( ldrb r3, [r0, r2, lsr #3] )
@@ -81,8 +81,8 @@ ENDPROC(_find_first_bit_le)
8181
* Prototype: int find_next_zero_bit(void *addr, unsigned int maxbit, int offset)
8282
*/
8383
ENTRY(_find_next_bit_le)
84-
teq r1, #0
85-
beq 3b
84+
cmp r2, r1
85+
bhs 3b
8686
ands ip, r2, #7
8787
beq 1b @ If new byte, goto old routine
8888
ARM( ldrb r3, [r0, r2, lsr #3] )
@@ -115,8 +115,8 @@ ENTRY(_find_first_zero_bit_be)
115115
ENDPROC(_find_first_zero_bit_be)
116116

117117
ENTRY(_find_next_zero_bit_be)
118-
teq r1, #0
119-
beq 3b
118+
cmp r2, r1
119+
bhs 3b
120120
ands ip, r2, #7
121121
beq 1b @ If new byte, goto old routine
122122
eor r3, r2, #0x18 @ big endian byte ordering
@@ -149,8 +149,8 @@ ENTRY(_find_first_bit_be)
149149
ENDPROC(_find_first_bit_be)
150150

151151
ENTRY(_find_next_bit_be)
152-
teq r1, #0
153-
beq 3b
152+
cmp r2, r1
153+
bhs 3b
154154
ands ip, r2, #7
155155
beq 1b @ If new byte, goto old routine
156156
eor r3, r2, #0x18 @ big endian byte ordering

0 commit comments

Comments
 (0)