FSTests Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 0/2] add tests for race between xattr read and write
@ 2020-07-17  8:44 Hou Tao
  2020-07-17  8:44 ` [PATCH 1/2] generic: add test for race between listxattr and setxatr Hou Tao
  2020-07-17  8:44 ` [PATCH 2/2] generic: add test for race between getxattr and setxattr Hou Tao
  0 siblings, 2 replies; 4+ messages in thread
From: Hou Tao @ 2020-07-17  8:44 UTC (permalink / raw)
  To: guaneryu, Richard Weinberger; +Cc: fstests, houtao1

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/20200630130438.141649-1-houtao1@huawei.com/

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

-- 
2.25.0.4.g0ad7144999


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] generic: add test for race between listxattr and setxatr
  2020-07-17  8:44 [PATCH 0/2] add tests for race between xattr read and write Hou Tao
@ 2020-07-17  8:44 ` Hou Tao
  2020-07-20  3:40   ` Chao Yu
  2020-07-17  8:44 ` [PATCH 2/2] generic: add test for race between getxattr and setxattr Hou Tao
  1 sibling, 1 reply; 4+ messages in thread
From: Hou Tao @ 2020-07-17  8:44 UTC (permalink / raw)
  To: guaneryu, Richard Weinberger; +Cc: fstests, houtao1

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.

Signed-off-by: Hou Tao <houtao1@huawei.com>
---
 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

diff --git a/tests/generic/998 b/tests/generic/998
new file mode 100644
index 00000000..b108a969
--- /dev/null
+++ b/tests/generic/998
@@ -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
diff --git a/tests/generic/998.out b/tests/generic/998.out
new file mode 100644
index 00000000..d2679ae0
--- /dev/null
+++ b/tests/generic/998.out
@@ -0,0 +1,2 @@
+QA output created by 998
+Silence is golden
diff --git a/tests/generic/group b/tests/generic/group
index d9ab9a31..62697ac5 100644
--- a/tests/generic/group
+++ b/tests/generic/group
@@ -605,3 +605,4 @@
 600 auto quick quota
 601 auto quick quota
 602 auto quick encrypt
+998 auto quick attr
-- 
2.25.0.4.g0ad7144999


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/2] generic: add test for race between getxattr and setxattr
  2020-07-17  8:44 [PATCH 0/2] add tests for race between xattr read and write Hou Tao
  2020-07-17  8:44 ` [PATCH 1/2] generic: add test for race between listxattr and setxatr Hou Tao
@ 2020-07-17  8:44 ` Hou Tao
  1 sibling, 0 replies; 4+ messages in thread
From: Hou Tao @ 2020-07-17  8:44 UTC (permalink / raw)
  To: guaneryu, Richard Weinberger; +Cc: fstests, houtao1

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.

Signed-off-by: Hou Tao <houtao1@huawei.com>
---
 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

diff --git a/tests/generic/999 b/tests/generic/999
new file mode 100644
index 00000000..5223d4aa
--- /dev/null
+++ b/tests/generic/999
@@ -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
diff --git a/tests/generic/999.out b/tests/generic/999.out
new file mode 100644
index 00000000..3b276ca8
--- /dev/null
+++ b/tests/generic/999.out
@@ -0,0 +1,2 @@
+QA output created by 999
+Silence is golden
diff --git a/tests/generic/group b/tests/generic/group
index 62697ac5..368399f1 100644
--- a/tests/generic/group
+++ b/tests/generic/group
@@ -606,3 +606,4 @@
 601 auto quick quota
 602 auto quick encrypt
 998 auto quick attr
+999 auto quick attr
-- 
2.25.0.4.g0ad7144999


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] generic: add test for race between listxattr and setxatr
  2020-07-17  8:44 ` [PATCH 1/2] generic: add test for race between listxattr and setxatr Hou Tao
@ 2020-07-20  3:40   ` Chao Yu
  0 siblings, 0 replies; 4+ messages in thread
From: Chao Yu @ 2020-07-20  3:40 UTC (permalink / raw)
  To: Hou Tao, guaneryu, Richard Weinberger; +Cc: fstests

Hi Tao,

On 2020/7/17 16:44, Hou Tao wrote:
> 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.
> 
> Signed-off-by: Hou Tao <houtao1@huawei.com>
> ---
>   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
> 
> diff --git a/tests/generic/998 b/tests/generic/998
> new file mode 100644
> index 00000000..b108a969
> --- /dev/null
> +++ b/tests/generic/998
> @@ -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

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,

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-17  8:44 [PATCH 0/2] add tests for race between xattr read and write Hou Tao
2020-07-17  8:44 ` [PATCH 1/2] generic: add test for race between listxattr and setxatr Hou Tao
2020-07-20  3:40   ` Chao Yu
2020-07-17  8:44 ` [PATCH 2/2] generic: add test for race between getxattr and setxattr Hou Tao

FSTests Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/fstests/0 fstests/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 fstests fstests/ https://lore.kernel.org/fstests \
		fstests@vger.kernel.org
	public-inbox-index fstests

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.fstests


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git