diff mbox series

[v2,5/5] overlay: Regression test for deadlock on directory ioctl

Message ID 20210210190334.1212210-6-amir73il@gmail.com (mailing list archive)
State New, archived
Headers show
Series Tests for overlayfs immutable/append-only files | expand

Commit Message

Amir Goldstein Feb. 10, 2021, 7:03 p.m. UTC
Overlayfs added the ability to set inode flags (e.g. chattr +i) in
kernel 5.10 by commit 61536bed2149 ("ovl: support [S|G]ETFLAGS and
FS[S|G]ETXATTR ioctls for directories").
Icenowy Zheng reported [1] a regression in that commit that causes
a deadlock when setting inode flags on lower dir.

The regression was fixed by commit b854cc659dcb ("ovl: avoid deadlock
on directory ioctl") and applied to kernel 5.10.15.

[1] https://lore.kernel.org/linux-unionfs/20210101201230.768653-1-icenowy@aosc.io/

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
 tests/overlay/076     | 66 +++++++++++++++++++++++++++++++++++++++++++
 tests/overlay/076.out |  2 ++
 tests/overlay/group   |  1 +
 3 files changed, 69 insertions(+)
 create mode 100644 tests/overlay/076
 create mode 100644 tests/overlay/076.out
diff mbox series

Patch

diff --git a/tests/overlay/076 b/tests/overlay/076
new file mode 100644
index 00000000..07827c0b
--- /dev/null
+++ b/tests/overlay/076
@@ -0,0 +1,66 @@ 
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2021 CTERA Networks. All Rights Reserved.
+#
+# FS QA Test 076
+#
+# Support for chattr on overlayfs directories was added in kernel v5.10
+# by commit 61536bed2149 ("ovl: support [S|G]ETFLAGS and FS[S|G]ETXATTR
+# ioctls for directories").  That commit introduced a deadlock.
+#
+# This is a regression test for the fix commit b854cc659dcb ("ovl: avoid
+# deadlock on directory ioctl")
+#
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1        # failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+        cd /
+        $CHATTR_PROG -i $lowerdir/foo > /dev/null 2>&1
+        $CHATTR_PROG -i $upperdir/foo > /dev/null 2>&1
+        rm -f $tmp.*
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+_supported_fs overlay
+_require_scratch
+_require_chattr i
+
+# remove all files from previous runs
+_scratch_mkfs
+
+# prepare lower test file
+lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
+upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
+workdir=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
+mkdir -p $lowerdir
+mkdir $lowerdir/foo
+
+# mounting overlay
+_scratch_mount
+
+# Try to add the immutable attributes, it will invoke ioctl() on the directory
+# The ioctl will fail on kernel < 5.10, succeed on kernel >= 5.10.15 and hang
+# on kernel v5.10..v5.10.14.  Anything but hang is considered a test success.
+$CHATTR_PROG +i $SCRATCH_MNT/foo > /dev/null 2>&1
+
+$UMOUNT_PROG $SCRATCH_MNT
+
+# success, all done
+echo "Silence is golden"
+status=0
+exit
diff --git a/tests/overlay/076.out b/tests/overlay/076.out
new file mode 100644
index 00000000..248e095d
--- /dev/null
+++ b/tests/overlay/076.out
@@ -0,0 +1,2 @@ 
+QA output created by 076
+Silence is golden
diff --git a/tests/overlay/group b/tests/overlay/group
index cfc75bb1..ddc355e5 100644
--- a/tests/overlay/group
+++ b/tests/overlay/group
@@ -78,6 +78,7 @@ 
 073 auto quick whiteout
 074 auto quick exportfs dangerous
 075 auto quick perms
+076 auto quick perms dangerous
 100 auto quick union samefs
 101 auto quick union nonsamefs
 102 auto quick union nonsamefs xino