Skip to contentSkip to conversation

add tests for race between xattr read and write

PATCH Superseded Hou Tao 4 participants 10 messages Jul 17, 2020 – Sep 2, 2020

lore
Share & tools
lore

Hou Tao

author
#0 lore raw

cover add tests for race between xattr read and write

Hi,

These two test cases are reproducers for xattr bugs [1] on ubifs. Although these bugs are ubifs specific, I still place these test cases under generic directory, because we can ensure other filesystems implement concurrent xattr read and write op correctly.

Comments are welcome.

Regards,
Tao

[1]: https://lore.kernel.org/linux-mtd/[email protected]/

Hou Tao (2):
generic: add test for race between listxattr and setxatr
generic: add test for race between getxattr and setxattr

 tests/generic/998     | 64 ++++++++++++++++++++++++++++++++++++++++
 tests/generic/998.out |  2 ++
 tests/generic/999     | 68 +++++++++++++++++++++++++++++++++++++++++++
 tests/generic/999.out |  2 ++
 tests/generic/group   |  2 ++
 5 files changed, 138 insertions(+)
 create mode 100644 tests/generic/998
 create mode 100644 tests/generic/998.out
 create mode 100644 tests/generic/999
 create mode 100644 tests/generic/999.out
Signature · 1 line
2.25.0.4.g0ad7144999
author
#1 lore raw

PATCH 1/2 generic: add test for race between listxattr and setxatr

Add reproducer for a bug on ubifs where listxattr() copies the newly created xattr names regardless of the remaining buffer size, fails the assertion of used buffer size, and may corrupt buffer memory.

---
 tests/generic/998     | 64 +++++++++++++++++++++++++++++++++++++++++++
 tests/generic/998.out |  2 ++
 tests/generic/group   |  1 +
 3 files changed, 67 insertions(+)
 create mode 100644 tests/generic/998
 create mode 100644 tests/generic/998.out
tests/generic/998 new file +64 -0
new file mode 100644
index 00000000..b108a969
@@ -0,0 +1,64 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2020 Huawei. All Rights Reserved.
+#
+# FS QA Test 998
+#
+# Test race between listxattr() and setxattr(). It reproduces a bug
+# on UBIFS where listxattr() copies the newly created xattr names
+# regardless of the remaining buffer size, fails the assertion of
+# used buffer size, and may corrupt buffer memory.
+#
+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 /
+	rm -f $tmp.*
+	rm -f $TEST_DIR/$seq
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/attr
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+_supported_fs generic
+_supported_os Linux
+_require_attrs
+
+target=$TEST_DIR/$seq
+touch $target
+
+# start a background listxattr
+runfile="$tmp.listxattr"
+touch $runfile
+while [ -e $runfile ]; do
+	${GETFATTR_PROG} $target >/dev/null 2>&1
+done &
+
+# add new xattr continuously
+largename=`for i in $(seq 0 128); do echo -n a; done`
+for i in $(seq 0 99); do
+	${SETFATTR_PROG} -n user.${largename}.$i -v $i $target
+done
+
+rm -f $runfile
+wait > /dev/null 2>&1
+rm -f $target
+
+echo Silence is golden
+
+# success, all done
+status=0
+exit
tests/generic/998.out new file +2 -0
new file mode 100644
index 00000000..d2679ae0
@@ -0,0 +1,2 @@
+QA output created by 998
+Silence is golden
tests/generic/group +1 -0
index d9ab9a31..62697ac5 100644
@@ -605,3 +605,4 @@
 600 auto quick quota
 601 auto quick quota
 602 auto quick encrypt
+998 auto quick attr
Signature · 1 line
2.25.0.4.g0ad7144999
#2 lore raw

Re: [PATCH 1/2] generic: add test for race between listxattr and setxatr

Hi Tao,

Quoted 63 lines · Hou Tao

Add reproducer for a bug on ubifs where listxattr() copies the newly created xattr names regardless of the remaining buffer size, fails the assertion of used buffer size, and may corrupt buffer memory.

---
  tests/generic/998     | 64 +++++++++++++++++++++++++++++++++++++++++++
  tests/generic/998.out |  2 ++
  tests/generic/group   |  1 +
  3 files changed, 67 insertions(+)

create mode 100644 tests/generic/998
create mode 100644 tests/generic/998.out

tests/generic/998 new file +43 -0
new file mode 100644
index 00000000..b108a969
@@ -0,0 +1,64 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2020 Huawei. All Rights Reserved.
+#
+# FS QA Test 998
+#
+# Test race between listxattr() and setxattr(). It reproduces a bug
+# on UBIFS where listxattr() copies the newly created xattr names
+# regardless of the remaining buffer size, fails the assertion of
+# used buffer size, and may corrupt buffer memory.
+#
+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 /
+	rm -f $tmp.*
+	rm -f $TEST_DIR/$seq
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/attr
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+_supported_fs generic
+_supported_os Linux
+_require_attrs
+
+target=$TEST_DIR/$seq
+touch $target
+
+# start a background listxattr

tests/generic/998 line 53

Quoted 10 lines
tests/generic/998 new file +10 -0
+runfile="$tmp.listxattr"
+touch $runfile
+while [ -e $runfile ]; do
+	${GETFATTR_PROG} $target >/dev/null 2>&1
+done &
+
+# add new xattr continuously
+largename=`for i in $(seq 0 128); do echo -n a; done`
+for i in $(seq 0 99); do
+	${SETFATTR_PROG} -n user.${largename}.$i -v $i $target

Now, f2fs just supports storing xattr in one 4KB size xattr block + inline space in inode, so this testcase will always fail with f2fs, would you please consider adjusting parameter to cover f2fs case?

Thanks,

Quoted 29 lines
tests/generic/998 new file +11 -0
+done
+
+rm -f $runfile
+wait > /dev/null 2>&1
+rm -f $target
+
+echo Silence is golden
+
+# success, all done
+status=0
+exit
tests/generic/998.out new file +2 -0
new file mode 100644
index 00000000..d2679ae0
@@ -0,0 +1,2 @@
+QA output created by 998
+Silence is golden
tests/generic/group +1 -0
index d9ab9a31..62697ac5 100644
@@ -605,3 +605,4 @@
  600 auto quick quota
  601 auto quick quota
  602 auto quick encrypt
+998 auto quick attr
author
#3 lore raw

PATCH v2 1/2 generic: add test for race between listxattr and setxatr

Add reproducer for a bug on ubifs where listxattr() copies the newly created xattr names regardless of the remaining buffer size, fails the assertion of used buffer size, and may corrupt buffer memory.

---
v2: accommodate f2fs by reducing the number of created xattrs for f2fs

 tests/generic/998     | 67 +++++++++++++++++++++++++++++++++++++++++++
 tests/generic/998.out |  2 ++
 tests/generic/group   |  1 +
 3 files changed, 70 insertions(+)
 create mode 100644 tests/generic/998
 create mode 100644 tests/generic/998.out
tests/generic/998 new file +67 -0
new file mode 100644
index 00000000..26a5b620
@@ -0,0 +1,67 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2020 Huawei. All Rights Reserved.
+#
+# FS QA Test 998
+#
+# Test race between listxattr() and setxattr(). It reproduces a bug
+# on UBIFS where listxattr() copies the newly created xattr names
+# regardless of the remaining buffer size, fails the assertion of
+# used buffer size, and may corrupt buffer memory.
+#
+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 /
+	rm -f $tmp.*
+	rm -f $TEST_DIR/$seq
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/attr
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+_supported_fs generic
+_supported_os Linux
+_require_attrs
+
+target=$TEST_DIR/$seq
+touch $target
+
+# start a background listxattr
+runfile="$tmp.listxattr"
+touch $runfile
+while [ -e $runfile ]; do
+	${GETFATTR_PROG} $target >/dev/null 2>&1
+done &
+
+# add new xattr continuously
+largename=`for i in $(seq 0 128); do echo -n a; done`
+cnt=100
+# f2fs has limited spaces for xattr
+[ $FSTYP == "f2fs" ] && cnt=30
+for i in $(seq 1 $cnt); do
+	${SETFATTR_PROG} -n user.${largename}.$i -v $i $target
+done
+
+rm -f $runfile
+wait > /dev/null 2>&1
+rm -f $target
+
+echo Silence is golden
+
+# success, all done
+status=0
+exit
tests/generic/998.out new file +2 -0
new file mode 100644
index 00000000..d2679ae0
@@ -0,0 +1,2 @@
+QA output created by 998
+Silence is golden
tests/generic/group +1 -0
index d9ab9a31..62697ac5 100644
@@ -605,3 +605,4 @@
 600 auto quick quota
 601 auto quick quota
 602 auto quick encrypt
+998 auto quick attr
Signature · 1 line
2.25.0.4.g0ad7144999
#4 lore raw

Re: [PATCH v2 1/2] generic: add test for race between listxattr and setxatr

Quoted 8 lines · Hou Tao

Add reproducer for a bug on ubifs where listxattr() copies the newly created xattr names regardless of the remaining buffer size, fails the assertion of used buffer size, and may corrupt buffer memory.

---
v2: accommodate f2fs by reducing the number of created xattrs for f2fs

Thanks for the test and revision! Is there a fix available for the ubifs bug? If so would you please mention the kernel commit ID in commit log as well?

Chao, would you please help check the update regarding to f2fs? Thanks!

Eryu

Quoted 100 lines
 tests/generic/998     | 67 +++++++++++++++++++++++++++++++++++++++++++
 tests/generic/998.out |  2 ++
 tests/generic/group   |  1 +
 3 files changed, 70 insertions(+)
 create mode 100644 tests/generic/998
 create mode 100644 tests/generic/998.out
tests/generic/998 new file +67 -0
new file mode 100644
index 00000000..26a5b620
@@ -0,0 +1,67 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2020 Huawei. All Rights Reserved.
+#
+# FS QA Test 998
+#
+# Test race between listxattr() and setxattr(). It reproduces a bug
+# on UBIFS where listxattr() copies the newly created xattr names
+# regardless of the remaining buffer size, fails the assertion of
+# used buffer size, and may corrupt buffer memory.
+#
+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 /
+	rm -f $tmp.*
+	rm -f $TEST_DIR/$seq
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/attr
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+_supported_fs generic
+_supported_os Linux
+_require_attrs
+
+target=$TEST_DIR/$seq
+touch $target
+
+# start a background listxattr
+runfile="$tmp.listxattr"
+touch $runfile
+while [ -e $runfile ]; do
+	${GETFATTR_PROG} $target >/dev/null 2>&1
+done &
+
+# add new xattr continuously
+largename=`for i in $(seq 0 128); do echo -n a; done`
+cnt=100
+# f2fs has limited spaces for xattr
+[ $FSTYP == "f2fs" ] && cnt=30
+for i in $(seq 1 $cnt); do
+	${SETFATTR_PROG} -n user.${largename}.$i -v $i $target
+done
+
+rm -f $runfile
+wait > /dev/null 2>&1
+rm -f $target
+
+echo Silence is golden
+
+# success, all done
+status=0
+exit
tests/generic/998.out new file +2 -0
new file mode 100644
index 00000000..d2679ae0
@@ -0,0 +1,2 @@
+QA output created by 998
+Silence is golden
tests/generic/group +1 -0
index d9ab9a31..62697ac5 100644
@@ -605,3 +605,4 @@
 600 auto quick quota
 601 auto quick quota
 602 auto quick encrypt
+998 auto quick attr
Signature · 1 line
2.25.0.4.g0ad7144999
Reviewed-by
#5 lore raw

Re: [PATCH v2 1/2] generic: add test for race between listxattr and setxatr

Quoted 10 lines · Eryu Guan
Quoted 8 lines · Hou Tao

Add reproducer for a bug on ubifs where listxattr() copies the newly created xattr names regardless of the remaining buffer size, fails the assertion of used buffer size, and may corrupt buffer memory.

---
v2: accommodate f2fs by reducing the number of created xattrs for f2fs

Quoted 5 lines

Thanks for the test and revision! Is there a fix available for the ubifs bug? If so would you please mention the kernel commit ID in commit log as well?

Chao, would you please help check the update regarding to f2fs? Thanks!

Hi, all,

Sorry for the delay.

I've ran the test, it looks fine to f2fs, and also parameter value 'cnt=30' is just touch upper boundary of xattr space size. :)

Thanks,

Quoted 105 lines

Eryu

Quoted 100 lines
  tests/generic/998     | 67 +++++++++++++++++++++++++++++++++++++++++++
  tests/generic/998.out |  2 ++
  tests/generic/group   |  1 +
  3 files changed, 70 insertions(+)

create mode 100644 tests/generic/998
create mode 100644 tests/generic/998.out

tests/generic/998 new file +67 -0
new file mode 100644
index 00000000..26a5b620
@@ -0,0 +1,67 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2020 Huawei. All Rights Reserved.
+#
+# FS QA Test 998
+#
+# Test race between listxattr() and setxattr(). It reproduces a bug
+# on UBIFS where listxattr() copies the newly created xattr names
+# regardless of the remaining buffer size, fails the assertion of
+# used buffer size, and may corrupt buffer memory.
+#
+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 /
+	rm -f $tmp.*
+	rm -f $TEST_DIR/$seq
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/attr
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+_supported_fs generic
+_supported_os Linux
+_require_attrs
+
+target=$TEST_DIR/$seq
+touch $target
+
+# start a background listxattr
+runfile="$tmp.listxattr"
+touch $runfile
+while [ -e $runfile ]; do
+	${GETFATTR_PROG} $target >/dev/null 2>&1
+done &
+
+# add new xattr continuously
+largename=`for i in $(seq 0 128); do echo -n a; done`
+cnt=100
+# f2fs has limited spaces for xattr
+[ $FSTYP == "f2fs" ] && cnt=30
+for i in $(seq 1 $cnt); do
+	${SETFATTR_PROG} -n user.${largename}.$i -v $i $target
+done
+
+rm -f $runfile
+wait > /dev/null 2>&1
+rm -f $target
+
+echo Silence is golden
+
+# success, all done
+status=0
+exit
tests/generic/998.out new file +2 -0
new file mode 100644
index 00000000..d2679ae0
@@ -0,0 +1,2 @@
+QA output created by 998
+Silence is golden
tests/generic/group +1 -0
index d9ab9a31..62697ac5 100644
@@ -605,3 +605,4 @@
  600 auto quick quota
  601 auto quick quota
  602 auto quick encrypt
+998 auto quick attr
Signature · 1 line
2.25.0.4.g0ad7144999

.

author
#6 lore raw

Re: [PATCH v2 1/2] generic: add test for race between listxattr and setxatr

In reply to Eryu Guan

Hi,

Quoted 6 lines · Eryu Guan
Quoted 5 lines · Hou Tao

Add reproducer for a bug on ubifs where listxattr() copies the newly created xattr names regardless of the remaining buffer size, fails the assertion of used buffer size, and may corrupt buffer memory.

Quoted 8 lines
Quoted 3 lines

---
v2: accommodate f2fs by reducing the number of created xattrs for f2fs

Thanks for the test and revision! Is there a fix available for the ubifs bug? If so would you please mention the kernel commit ID in commit log as well?

The fixes [1] have not been reviewed yet, so we may need to hold on until the fixes get merged ?

[1]: https://lore.kernel.org/linux-mtd/[email protected]/

Regards,
Tao

Quoted 106 lines

Chao, would you please help check the update regarding to f2fs? Thanks!

Eryu

Quoted 100 lines
 tests/generic/998     | 67 +++++++++++++++++++++++++++++++++++++++++++
 tests/generic/998.out |  2 ++
 tests/generic/group   |  1 +
 3 files changed, 70 insertions(+)
 create mode 100644 tests/generic/998
 create mode 100644 tests/generic/998.out
tests/generic/998 new file +67 -0
new file mode 100644
index 00000000..26a5b620
@@ -0,0 +1,67 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2020 Huawei. All Rights Reserved.
+#
+# FS QA Test 998
+#
+# Test race between listxattr() and setxattr(). It reproduces a bug
+# on UBIFS where listxattr() copies the newly created xattr names
+# regardless of the remaining buffer size, fails the assertion of
+# used buffer size, and may corrupt buffer memory.
+#
+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 /
+	rm -f $tmp.*
+	rm -f $TEST_DIR/$seq
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/attr
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+_supported_fs generic
+_supported_os Linux
+_require_attrs
+
+target=$TEST_DIR/$seq
+touch $target
+
+# start a background listxattr
+runfile="$tmp.listxattr"
+touch $runfile
+while [ -e $runfile ]; do
+	${GETFATTR_PROG} $target >/dev/null 2>&1
+done &
+
+# add new xattr continuously
+largename=`for i in $(seq 0 128); do echo -n a; done`
+cnt=100
+# f2fs has limited spaces for xattr
+[ $FSTYP == "f2fs" ] && cnt=30
+for i in $(seq 1 $cnt); do
+	${SETFATTR_PROG} -n user.${largename}.$i -v $i $target
+done
+
+rm -f $runfile
+wait > /dev/null 2>&1
+rm -f $target
+
+echo Silence is golden
+
+# success, all done
+status=0
+exit
tests/generic/998.out new file +2 -0
new file mode 100644
index 00000000..d2679ae0
@@ -0,0 +1,2 @@
+QA output created by 998
+Silence is golden
tests/generic/group +1 -0
index d9ab9a31..62697ac5 100644
@@ -605,3 +605,4 @@
 600 auto quick quota
 601 auto quick quota
 602 auto quick encrypt
+998 auto quick attr
Signature · 1 line
2.25.0.4.g0ad7144999

.

#7 lore raw

Re: [PATCH v2 1/2] generic: add test for race between listxattr and setxatr

Quoted 13 lines · Hou Tao

Hi,

Quoted 10 lines · Eryu Guan
Quoted 8 lines · Hou Tao

Add reproducer for a bug on ubifs where listxattr() copies the newly created xattr names regardless of the remaining buffer size, fails the assertion of used buffer size, and may corrupt buffer memory.

---
v2: accommodate f2fs by reducing the number of created xattrs for f2fs

Quoted 7 lines
Quoted 4 lines

Thanks for the test and revision! Is there a fix available for the ubifs bug? If so would you please mention the kernel commit ID in commit log as well?

The fixes [1] have not been reviewed yet, so we may need to hold on until the fixes get merged ?

[1]: https://lore.kernel.org/linux-mtd/[email protected]/

It's better to have the fixes merged first, but we do merge tests before the fixes landed in. But I'd like to see at least some reviews/acks on the fixes first.

Thanks,
Eryu

#8 lore raw

Re: [PATCH v2 1/2] generic: add test for race between listxattr and setxatr

In reply to Hou Tao
Quoted 59 lines · Hou Tao

Add reproducer for a bug on ubifs where listxattr() copies the newly created xattr names regardless of the remaining buffer size, fails the assertion of used buffer size, and may corrupt buffer memory.

---
v2: accommodate f2fs by reducing the number of created xattrs for f2fs

 tests/generic/998     | 67 +++++++++++++++++++++++++++++++++++++++++++
 tests/generic/998.out |  2 ++
 tests/generic/group   |  1 +
 3 files changed, 70 insertions(+)
 create mode 100644 tests/generic/998
 create mode 100644 tests/generic/998.out
tests/generic/998 new file +37 -0
new file mode 100644
index 00000000..26a5b620
@@ -0,0 +1,67 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2020 Huawei. All Rights Reserved.
+#
+# FS QA Test 998
+#
+# Test race between listxattr() and setxattr(). It reproduces a bug
+# on UBIFS where listxattr() copies the newly created xattr names
+# regardless of the remaining buffer size, fails the assertion of
+# used buffer size, and may corrupt buffer memory.
+#
+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 /
+	rm -f $tmp.*
+	rm -f $TEST_DIR/$seq
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/attr
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+_supported_fs generic
+_supported_os Linux

tests/generic/998 line 47

Quoted 10 lines
tests/generic/998 new file +10 -0
+_require_attrs
+
+target=$TEST_DIR/$seq
+touch $target
+
+# start a background listxattr
+runfile="$tmp.listxattr"
+touch $runfile
+while [ -e $runfile ]; do
+	${GETFATTR_PROG} $target >/dev/null 2>&1

Er, if the listxattr corrupts the buffer memory, how does this test detect that? Does the kernel crash or something?

tests/generic/998 line 56

Quoted 9 lines
tests/generic/998 new file +9 -0
+done &
+
+# add new xattr continuously
+largename=`for i in $(seq 0 128); do echo -n a; done`
+cnt=100
+# f2fs has limited spaces for xattr
+[ $FSTYP == "f2fs" ] && cnt=30
+for i in $(seq 1 $cnt); do
+	${SETFATTR_PROG} -n user.${largename}.$i -v $i $target

Seeing as each filesystem has different xattr limits, I wonder if instead of special casing of f2fs we ought to capture the stdout/stderr of SETFATTR_PROG and filter out the ENOSPC message?

AFAICT this test isn't trying to check that setting xattrs succeeds, but I'm a little confused on how we detect the corrupted buffer...

--D

Quoted 31 lines
tests/generic/998 new file +11 -0
+done
+
+rm -f $runfile
+wait > /dev/null 2>&1
+rm -f $target
+
+echo Silence is golden
+
+# success, all done
+status=0
+exit
tests/generic/998.out new file +2 -0
new file mode 100644
index 00000000..d2679ae0
@@ -0,0 +1,2 @@
+QA output created by 998
+Silence is golden
tests/generic/group +1 -0
index d9ab9a31..62697ac5 100644
@@ -605,3 +605,4 @@
 600 auto quick quota
 601 auto quick quota
 602 auto quick encrypt
+998 auto quick attr
Signature · 1 line
2.25.0.4.g0ad7144999
author
#9 lore raw

PATCH 2/2 generic: add test for race between getxattr and setxattr

In reply to Hou Tao

Add reproducer for a bug on UBIFS where getxattr() may fail the assertions about the size of xattr value when the xattr is being modified or deleted simultaneously.

---
 tests/generic/999     | 68 +++++++++++++++++++++++++++++++++++++++++++
 tests/generic/999.out |  2 ++
 tests/generic/group   |  1 +
 3 files changed, 71 insertions(+)
 create mode 100644 tests/generic/999
 create mode 100644 tests/generic/999.out
tests/generic/999 new file +68 -0
new file mode 100644
index 00000000..5223d4aa
@@ -0,0 +1,68 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2020 Huawei. All Rights Reserved.
+#
+# FS QA Test 999
+#
+# Test race between getxattr() and setxattr(). It reproduces a bug
+# on UBIFS where getxattr() may fail the assertions about the size of
+# xattr value when the xattr is being modified or deleted simultaneously.
+#
+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 /
+	rm -f $tmp.*
+	rm -f $TEST_DIR/$seq
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/attr
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+_supported_fs generic
+_supported_os Linux
+_require_attrs
+
+target=$TEST_DIR/$seq
+touch $target
+
+xattr=user.test
+${SETFATTR_PROG} -n $xattr -v 1 $target
+
+# start a background getxattr
+runfile="$tmp.getxattr"
+touch $runfile
+while [ -e $runfile ]; do
+	${GETFATTR_PROG} -n $xattr $target >/dev/null 2>&1
+done &
+
+# modify and remove xattr repeatedly
+largeval=`for i in $(seq 0 128); do echo -n a; done`
+for i in $(seq 0 99); do
+	${SETFATTR_PROG} -n $xattr -v $largeval $target
+	${SETFATTR_PROG} -x $xattr $target
+	${SETFATTR_PROG} -n $xattr -v 1 $target
+done
+
+rm -f $runfile
+wait > /dev/null 2>&1
+rm -f $target
+
+echo Silence is golden
+
+# success, all done
+status=0
+exit
tests/generic/999.out new file +2 -0
new file mode 100644
index 00000000..3b276ca8
@@ -0,0 +1,2 @@
+QA output created by 999
+Silence is golden
tests/generic/group +1 -0
index 62697ac5..368399f1 100644
@@ -606,3 +606,4 @@
 601 auto quick quota
 602 auto quick encrypt
 998 auto quick attr
+999 auto quick attr
Signature · 1 line
2.25.0.4.g0ad7144999