lkml.org 
[lkml]   [2022]   [Aug]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 4.14 049/229] ARM: findbit: fix overflowing offset
    Date
    From: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>

    [ Upstream commit ec85bd369fd2bfaed6f45dd678706429d4f75b48 ]

    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>
    Signed-off-by: Sasha Levin <sashal@kernel.org>
    ---
    arch/arm/lib/findbit.S | 16 ++++++++--------
    1 file changed, 8 insertions(+), 8 deletions(-)

    diff --git a/arch/arm/lib/findbit.S b/arch/arm/lib/findbit.S
    index 7848780e8834..20fef6c41f6f 100644
    --- a/arch/arm/lib/findbit.S
    +++ b/arch/arm/lib/findbit.S
    @@ -43,8 +43,8 @@ ENDPROC(_find_first_zero_bit_le)
    * Prototype: int find_next_zero_bit(void *addr, unsigned int maxbit, int offset)
    */
    ENTRY(_find_next_zero_bit_le)
    - teq r1, #0
    - beq 3b
    + cmp r2, r1
    + bhs 3b
    ands ip, r2, #7
    beq 1b @ If new byte, goto old routine
    ARM( ldrb r3, [r0, r2, lsr #3] )
    @@ -84,8 +84,8 @@ ENDPROC(_find_first_bit_le)
    * Prototype: int find_next_zero_bit(void *addr, unsigned int maxbit, int offset)
    */
    ENTRY(_find_next_bit_le)
    - teq r1, #0
    - beq 3b
    + cmp r2, r1
    + bhs 3b
    ands ip, r2, #7
    beq 1b @ If new byte, goto old routine
    ARM( ldrb r3, [r0, r2, lsr #3] )
    @@ -118,8 +118,8 @@ ENTRY(_find_first_zero_bit_be)
    ENDPROC(_find_first_zero_bit_be)

    ENTRY(_find_next_zero_bit_be)
    - teq r1, #0
    - beq 3b
    + cmp r2, r1
    + bhs 3b
    ands ip, r2, #7
    beq 1b @ If new byte, goto old routine
    eor r3, r2, #0x18 @ big endian byte ordering
    @@ -152,8 +152,8 @@ ENTRY(_find_first_bit_be)
    ENDPROC(_find_first_bit_be)

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


    \
     
     \ /
      Last update: 2022-08-23 11:35    [W:4.050 / U:0.096 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site