xfs: fix use-after-free on CIL context on shutdown
authorDave Chinner <dchinner@redhat.com>
Tue, 16 Jun 2020 15:57:43 +0000 (08:57 -0700)
committerDarrick J. Wong <djwong@flax.djwong.org>
Tue, 23 Jun 2020 02:22:57 +0000 (19:22 -0700)
commitc7f87f3984cfa1e6d32806a715f35c5947ad9c09
tree4a5905b8fdc7b7fe272ee88cd9ead8ec72ecee16
parentb3a9e3b9622ae10064826dccb4f7a52bd88c7407
xfs: fix use-after-free on CIL context on shutdown

xlog_wait() on the CIL context can reference a freed context if the
waiter doesn't get scheduled before the CIL context is freed. This
can happen when a task is on the hard throttle and the CIL push
aborts due to a shutdown. This was detected by generic/019:

thread 1 thread 2

__xfs_trans_commit
 xfs_log_commit_cil
  <CIL size over hard throttle limit>
  xlog_wait
   schedule
xlog_cil_push_work
wake_up_all
<shutdown aborts commit>
xlog_cil_committed
kmem_free

   remove_wait_queue
    spin_lock_irqsave --> UAF

Fix it by moving the wait queue to the CIL rather than keeping it in
in the CIL context that gets freed on push completion. Because the
wait queue is now independent of the CIL context and we might have
multiple contexts in flight at once, only wake the waiters on the
push throttle when the context we are pushing is over the hard
throttle size threshold.

Fixes: 0e7ab7efe7745 ("xfs: Throttle commits on delayed background CIL push")
Reported-by: Yu Kuai <yukuai3@huawei.com>
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
fs/xfs/xfs_log_cil.c
fs/xfs/xfs_log_priv.h