Btrfs: fix race in WAIT_SYNC ioctl
commit7d6d0aa7f8e689dfc91bf5c5b6152bc1a95c67e1
authorSage Weil <sage@redhat.com>
Fri, 26 Sep 2014 15:30:06 +0000 (26 08:30 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 30 Oct 2014 16:40:09 +0000 (30 09:40 -0700)
treed223f539a229b84fe000c077fb30deaa9f79e0b4
parentb341d2a477aac5c1bc397526182427e5189e45bc
Btrfs: fix race in WAIT_SYNC ioctl

commit 42383020beb1cfb05f5d330cc311931bc4917a97 upstream.

We check whether transid is already committed via last_trans_committed and
then search through trans_list for pending transactions.  If
last_trans_committed is updated by btrfs_commit_transaction after we check
it (there is no locking), we will fail to find the committed transaction
and return EINVAL to the caller.  This has been observed occasionally by
ceph-osd (which uses this ioctl heavily).

Fix by rechecking whether the provided transid <= last_trans_committed
after the search fails, and if so return 0.

Signed-off-by: Sage Weil <sage@redhat.com>
Signed-off-by: Chris Mason <clm@fb.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/btrfs/transaction.c