• Thomas Gleixner's avatar
    x86/apic/vector: Prevent hlist corruption and leaks · 80ae7b1a
    Thomas Gleixner authored
    Several people observed the WARN_ON() in irq_matrix_free() which triggers
    when the caller tries to free an vector which is not in the allocation
    range. Song provided the trace information which allowed to decode the root
    cause.
    
    The rework of the vector allocation mechanism failed to preserve a sanity
    check, which prevents setting a new target vector/CPU when the previous
    affinity change has not fully completed.
    
    As a result a half finished affinity change can be overwritten, which can
    cause the leak of a irq descriptor pointer on the previous target CPU and
    double enqueue of the hlist head into the cleanup lists of two or more
    CPUs. After one CPU cleaned up its vector the next CPU will invoke the
    cleanup handler with vector 0, which triggers the out of range warning in
    the matrix allocator.
    
    Prevent this by checking the apic_data of the interrupt whether the
    move_in_progress flag is false and the hlist node is not hashed. Return
    -EBUSY if not.
    
    This prevents the damage and restores the behaviour before the vector
    allocation rework, but due to other changes in that area it also widens the
    chance that user space can observe -EBUSY. In theory this should be fine,
    but actually not all user space tools handle -EBUSY correctly. Addressing
    that is not part of this fix, but will be addressed in follow up patches.
    
    Fixes: 69cde000 ("x86/vector: Use matrix allocator for vector assignment")
    Reported-by: default avatarDmitry Safonov <0x7f454c46@gmail.com>
    Reported-by: default avatarTariq Toukan <tariqt@mellanox.com>
    Reported-by: default avatarSong Liu <liu.song.a23@gmail.com>
    Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
    Tested-by: default avatarSong Liu <songliubraving@fb.com>
    Cc: Joerg Roedel <jroedel@suse.de>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: stable@vger.kernel.org
    Cc: Mike Travis <mike.travis@hpe.com>
    Cc: Borislav Petkov <bp@alien8.de>
    Link: https://lkml.kernel.org/r/20180604162224.303870257@linutronix.de
    80ae7b1a
vector.c 32.7 KB