• Dave Chinner's avatar
    xfs: buffer pins need to hold a buffer reference · 89a4bf0d
    Dave Chinner authored
    When a buffer is unpinned by xfs_buf_item_unpin(), we need to access
    the buffer after we've dropped the buffer log item reference count.
    This opens a window where we can have two racing unpins for the
    buffer item (e.g. shutdown checkpoint context callback processing
    racing with journal IO iclog completion processing) and both attempt
    to access the buffer after dropping the BLI reference count.  If we
    are unlucky, the "BLI freed" context wins the race and frees the
    buffer before the "BLI still active" case checks the buffer pin
    count.
    
    This results in a use after free that can only be triggered
    in active filesystem shutdown situations.
    
    To fix this, we need to ensure that buffer existence extends beyond
    the BLI reference count checks and until the unpin processing is
    complete. This implies that a buffer pin operation must also take a
    buffer reference to ensure that the buffer cannot be freed until the
    buffer unpin processing is complete.
    Reported-by: default avataryangerkun <yangerkun@huawei.com>
    Signed-off-by: default avatarDave Chinner <dchinner@redhat.com>
    Reviewed-by: default avatarDarrick J. Wong <djwong@kernel.org>
    Reviewed-by: Christoph Hellwig <hch@lst.de> 
    Signed-off-by: default avatarDave Chinner <david@fromorbit.com>
    89a4bf0d
xfs_buf_item.c 30.5 KB