[Top] [All Lists]

[PATCH 2/2] xfs/051: test buffer use after free race on I/O failure in X

To: fstests@xxxxxxxxxxxxxxx
Subject: [PATCH 2/2] xfs/051: test buffer use after free race on I/O failure in XFS log recovery
From: Brian Foster <bfoster@xxxxxxxxxx>
Date: Tue, 2 Sep 2014 10:22:41 -0400
Cc: xfs@xxxxxxxxxxx
Delivered-to: xfs@xxxxxxxxxxx
In-reply-to: <1409667761-50248-1-git-send-email-bfoster@xxxxxxxxxx>
References: <1409667761-50248-1-git-send-email-bfoster@xxxxxxxxxx>
A buffer use after free race was discovered in the XFS log recovery
codepath if I/O failures occur during recovery. The I/O submission path
can abort the mount and release the only reference held on some buffers
before I/O completion processing (e.g., async workqueue processing)
might have completed. Badness ensues if the I/O completion path
subsequently attempts to access said buffers.

The test manufactures the race by forcing all writes to fail (via
dm-flakey) after a fixed period of time. A delay is inserted into the
mount codepath to synchronize write failures with log recovery.

Credit for discovery of the race and definition of the reproducible test
case goes to Alex Lyakas.

Signed-off-by: Brian Foster <bfoster@xxxxxxxxxx>
Reported-by: Alex Lyakas <alex@xxxxxxxxxxxxxxxxx>
 tests/xfs/051     | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/xfs/051.out |  2 ++
 tests/xfs/group   |  1 +
 3 files changed, 98 insertions(+)
 create mode 100755 tests/xfs/051
 create mode 100644 tests/xfs/051.out

diff --git a/tests/xfs/051 b/tests/xfs/051
new file mode 100755
index 0000000..a84746b
--- /dev/null
+++ b/tests/xfs/051
@@ -0,0 +1,95 @@
+#! /bin/bash
+# FS QA Test No. 051
+# Simulate a buffer use after free race in XFS log recovery. The race triggers
+# on I/O failures during log recovery. Note that this test is dangerous as it
+# causes BUG() errors or a panic.
+# Copyright (c) 2013 Oracle, Inc.  All Rights Reserved.
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# GNU General Public License for more details.
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+seq=`basename $0`
+echo "QA output created by $seq"
+status=1       # failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+       cd /
+       rm -f $tmp.*
+       killall -9 $FSSTRESS_PROG > /dev/null 2>&1
+       _scratch_unmount > /dev/null 2>&1
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/dmflakey
+# Modify as appropriate.
+_supported_fs xfs
+_supported_os Linux
+_require_xfs_sysfs debug/log_recovery_delay
+echo "Silence is golden."
+_scratch_mkfs_xfs >/dev/null 2>&1
+# Start a workload and shutdown the fs. The subsequent mount will require log
+# recovery.
+$FSSTRESS_PROG -n 9999 -p 2 -w -d $SCRATCH_MNT > /dev/null 2>&1 &
+sleep 5
+src/godown -f $SCRATCH_MNT
+killall -q $FSSTRESS_PROG
+# Initialize a dm-flakey device that will pass I/Os for 5s and fail thereafter.
+BLK_DEV_SIZE=`blockdev --getsz $SCRATCH_DEV`
+_load_flakey_table $FLAKEY_ALLOW_WRITES
+# Set a 10s log recovery delay and mount the flakey device. This should allow
+# initial writes to proceed (e.g., stale log block reset) and then let the
+# flakey uptime timer expire such that I/Os will fail by the time log recovery
+# starts.
+echo 10 > /sys/fs/xfs/debug/log_recovery_delay
+# The mount should fail due to dm-flakey. Note that this is dangerous on 
+# without the xfs_buf log recovery race fixes.
+_mount_flakey > /dev/null 2>&1
+echo 0 > /sys/fs/xfs/debug/log_recovery_delay
+# replay the log
+# success, all done
diff --git a/tests/xfs/051.out b/tests/xfs/051.out
new file mode 100644
index 0000000..5180bc4
--- /dev/null
+++ b/tests/xfs/051.out
@@ -0,0 +1,2 @@
+QA output created by 051
+Silence is golden.
diff --git a/tests/xfs/group b/tests/xfs/group
index 4d35df5..9784dea 100644
--- a/tests/xfs/group
+++ b/tests/xfs/group
@@ -47,6 +47,7 @@
 048 other auto quick
 049 rw auto quick
 050 quota auto quick
+051 dangerous
 052 quota db auto quick
 054 quota auto quick
 055 dump ioctl remote tape

<Prev in Thread] Current Thread [Next in Thread>