• Arnd Bergmann's avatar
    futex_compat: fix list traversal bugs · 179c85ea
    Arnd Bergmann authored
    The futex list traversal on the compat side appears to have
    a bug.
    
    It's loop termination condition compares:
    
            while (compat_ptr(uentry) != &head->list)
    
    But that can't be right because "uentry" has the special
    "pi" indicator bit still potentially set at bit 0.  This
    is cleared by fetch_robust_entry() into the "entry"
    return value.
    
    What this seems to mean is that the list won't terminate
    when list iteration gets back to the the head.  And we'll
    also process the list head like a normal entry, which could
    cause all kinds of problems.
    
    So we should check for equality with "entry".  That pointer
    is of the non-compat type so we have to do a little casting
    to keep the compiler and sparse happy.
    
    The same problem can in theory occur with the 'pending'
    variable, although that has not been reported from users
    so far.
    
    Based on the original patch from David Miller.
    Acked-by: default avatarIngo Molnar <mingo@elte.hu>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: David Miller <davem@davemloft.net>
    Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
    Cc: <stable@kernel.org>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    179c85ea
futex_compat.c 3.68 KB