• Dave Chinner's avatar
    xfs: Fix a CIL UAF by getting get rid of the iclog callback lock · a1bb8505
    Dave Chinner authored
    The iclog callback chain has it's own lock. That was added way back
    in 2008 by myself to alleviate severe lock contention on the
    icloglock in commit 114d23aa ("[XFS] Per iclog callback chain
    lock"). This was long before delayed logging took the icloglock out
    of the hot transaction commit path and removed all contention on it.
    Hence the separate ic_callback_lock doesn't serve any scalability
    purpose anymore, and hasn't for close on a decade.
    
    Further, we only attach callbacks to iclogs in one place where we
    are already taking the icloglock soon after attaching the callbacks.
    We also have to drop the icloglock to run callbacks and grab it
    immediately afterwards again. So given that the icloglock is no
    longer hot, making it cover callbacks again doesn't really change
    the locking patterns very much at all.
    
    We also need to extend the icloglock to cover callback addition to
    fix a zero-day UAF in the CIL push code. This occurs when shutdown
    races with xlog_cil_push_work() and the shutdown runs the callbacks
    before the push releases the iclog. This results in the CIL context
    structure attached to the iclog being freed by the callback before
    the CIL push has finished referencing it, leading to UAF bugs.
    
    Hence, to avoid this UAF, we need the callback attachment to be
    atomic with post processing of the commit iclog and references to
    the structures being attached to the iclog. This requires holding
    the icloglock as that's the only way to serialise iclog state
    against a shutdown in progress.
    
    The result is we need to be using the icloglock to protect the
    callback list addition and removal and serialise them with shutdown.
    That makes the ic_callback_lock redundant and so it can be removed.
    
    Fixes: 71e330b5 ("xfs: Introduce delayed logging core code")
    Signed-off-by: default avatarDave Chinner <dchinner@redhat.com>
    Reviewed-by: default avatarBrian Foster <bfoster@redhat.com>
    Reviewed-by: default avatarDarrick J. Wong <djwong@kernel.org>
    Signed-off-by: default avatarDarrick J. Wong <djwong@kernel.org>
    a1bb8505
xfs_log_cil.c 40.2 KB