• Will Deacon's avatar
    arm64: futex: Fix FUTEX_WAKE_OP atomic ops with non-zero result value · 045afc24
    Will Deacon authored
    Rather embarrassingly, our futex() FUTEX_WAKE_OP implementation doesn't
    explicitly set the return value on the non-faulting path and instead
    leaves it holding the result of the underlying atomic operation. This
    means that any FUTEX_WAKE_OP atomic operation which computes a non-zero
    value will be reported as having failed. Regrettably, I wrote the buggy
    code back in 2011 and it was upstreamed as part of the initial arm64
    support in 2012.
    
    The reasons we appear to get away with this are:
    
      1. FUTEX_WAKE_OP is rarely used and therefore doesn't appear to get
         exercised by futex() test applications
    
      2. If the result of the atomic operation is zero, the system call
         behaves correctly
    
      3. Prior to version 2.25, the only operation used by GLIBC set the
         futex to zero, and therefore worked as expected. From 2.25 onwards,
         FUTEX_WAKE_OP is not used by GLIBC at all.
    
    Fix the implementation by ensuring that the return value is either 0
    to indicate that the atomic operation completed successfully, or -EFAULT
    if we encountered a fault when accessing the user mapping.
    
    Cc: <stable@kernel.org>
    Fixes: 6170a974 ("arm64: Atomic operations")
    Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
    045afc24
futex.h 3.01 KB