All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/3] safe_macros: remove unused code in xattr related functions
@ 2017-03-02 10:37 Xiao Yang
  2017-03-02 10:37 ` [LTP] [PATCH 2/3] safe_macros: add safe_removexattr() Xiao Yang
  2017-03-02 10:37 ` [LTP] [PATCH 3/3] syscalls/getxattr04.c: Add new regression test Xiao Yang
  0 siblings, 2 replies; 11+ messages in thread
From: Xiao Yang @ 2017-03-02 10:37 UTC (permalink / raw)
  To: ltp

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 lib/safe_macros.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/lib/safe_macros.c b/lib/safe_macros.c
index 42e7d98..6476246 100644
--- a/lib/safe_macros.c
+++ b/lib/safe_macros.c
@@ -803,7 +803,6 @@ int safe_setxattr(const char *file, const int lineno, const char *path,
 			tst_brkm(TCONF, NULL,
 				 "%s:%d: no xattr support in fs or mounted "
 				 "without user_xattr option", file, lineno);
-			return rval;
 		}
 
 		tst_brkm(TBROK | TERRNO, NULL, "%s:%d: setxattr() failed",
@@ -825,7 +824,6 @@ int safe_lsetxattr(const char *file, const int lineno, const char *path,
 			tst_brkm(TCONF, NULL,
 				 "%s:%d: no xattr support in fs or mounted "
 				 "without user_xattr option", file, lineno);
-			return rval;
 		}
 
 		tst_brkm(TBROK | TERRNO, NULL, "%s:%d: lsetxattr() failed",
@@ -847,7 +845,6 @@ int safe_fsetxattr(const char *file, const int lineno, int fd, const char *name,
 			tst_brkm(TCONF, NULL,
 				 "%s:%d: no xattr support in fs or mounted "
 				 "without user_xattr option", file, lineno);
-			return rval;
 		}
 
 		tst_brkm(TBROK | TERRNO, NULL, "%s:%d: fsetxattr() failed",
-- 
1.8.3.1




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

* [LTP] [PATCH 2/3] safe_macros: add safe_removexattr()
  2017-03-02 10:37 [LTP] [PATCH 1/3] safe_macros: remove unused code in xattr related functions Xiao Yang
@ 2017-03-02 10:37 ` Xiao Yang
  2017-03-02 10:37 ` [LTP] [PATCH 3/3] syscalls/getxattr04.c: Add new regression test Xiao Yang
  1 sibling, 0 replies; 11+ messages in thread
From: Xiao Yang @ 2017-03-02 10:37 UTC (permalink / raw)
  To: ltp

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 include/tst_safe_macros.h |  5 +++++
 lib/safe_macros.c         | 21 +++++++++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h
index 241b92a..7683109 100644
--- a/include/tst_safe_macros.h
+++ b/include/tst_safe_macros.h
@@ -422,4 +422,9 @@ int safe_fsetxattr(const char *file, const int lineno, int fd, const char *name,
 #define SAFE_FSETXATTR(fd, name, value, size, flags) \
 	safe_fsetxattr(__FILE__, __LINE__, (fd), (name), (value), (size), (flags))
 
+int safe_removexattr(const char *file, const int lineno, const char *path,
+		const char *name);
+#define SAFE_REMOVEXATTR(path, name) \
+	safe_removexattr(__FILE__, __LINE__, (path), (name))
+
 #endif /* SAFE_MACROS_H__ */
diff --git a/lib/safe_macros.c b/lib/safe_macros.c
index 6476246..df0df7f 100644
--- a/lib/safe_macros.c
+++ b/lib/safe_macros.c
@@ -853,3 +853,24 @@ int safe_fsetxattr(const char *file, const int lineno, int fd, const char *name,
 
 	return rval;
 }
+
+int safe_removexattr(const char *file, const int lineno, const char *path,
+		const char *name)
+{
+	int rval;
+
+	rval = removexattr(path, name);
+
+	if (rval) {
+		if (errno == ENOTSUP) {
+			tst_brkm(TCONF, NULL,
+				"%s:%d: no xattr support in fs or mounted "
+				"without user_xattr option", file, lineno);
+		}
+
+		tst_brkm(TBROK | TERRNO, NULL, "%s:%d: removexattr() failed",
+			file, lineno);
+	}
+
+	return rval;
+}
-- 
1.8.3.1




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

* [LTP] [PATCH 3/3] syscalls/getxattr04.c: Add new regression test
  2017-03-02 10:37 [LTP] [PATCH 1/3] safe_macros: remove unused code in xattr related functions Xiao Yang
  2017-03-02 10:37 ` [LTP] [PATCH 2/3] safe_macros: add safe_removexattr() Xiao Yang
@ 2017-03-02 10:37 ` Xiao Yang
  2017-03-02 16:23   ` Cyril Hrubis
  1 sibling, 1 reply; 11+ messages in thread
From: Xiao Yang @ 2017-03-02 10:37 UTC (permalink / raw)
  To: ltp

This is a regression test for the race between getting an existing
xattr and setting/removing a large xattr.  This bug leads to that
getxattr() fails to get an existing xattr and returns ENOATTR in xfs
filesystem.  Thie bug has been fixed in:

commit 5a93790d4e2df73e30c965ec6e49be82fc3ccfce
Author: Brian Foster <bfoster@redhat.com>
Date:   Wed Jan 25 07:53:43 2017 -0800

	xfs: remove racy hasattr check from attr ops

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 runtest/syscalls                                |   1 +
 testcases/kernel/syscalls/.gitignore            |   1 +
 testcases/kernel/syscalls/getxattr/getxattr04.c | 146 ++++++++++++++++++++++++
 3 files changed, 148 insertions(+)
 create mode 100644 testcases/kernel/syscalls/getxattr/getxattr04.c

diff --git a/runtest/syscalls b/runtest/syscalls
index c3ea212..edf0674 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -444,6 +444,7 @@ getuid03_16 getuid03_16
 getxattr01 getxattr01
 getxattr02 getxattr02
 getxattr03 getxattr03
+getxattr04 getxattr04
 
 #Needs tty device.
 #ioctl01 ioctl01 -D /dev/tty0
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index 9d7b947..2728509 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -368,6 +368,7 @@
 /getxattr/getxattr01
 /getxattr/getxattr02
 /getxattr/getxattr03
+/getxattr/getxattr04
 /inotify/inotify01
 /inotify/inotify02
 /inotify/inotify03
diff --git a/testcases/kernel/syscalls/getxattr/getxattr04.c b/testcases/kernel/syscalls/getxattr/getxattr04.c
new file mode 100644
index 0000000..fa2fdc8
--- /dev/null
+++ b/testcases/kernel/syscalls/getxattr/getxattr04.c
@@ -0,0 +1,146 @@
+/*
+ * Copyright (c) 2017 Fujitsu Ltd.
+ * Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU General Public License
+ * alone with this program.
+ *
+ */
+
+/*
+ * This is a regression test for the race between getting an existing
+ * xattr and setting/removing a large xattr.  This bug leads to that
+ * getxattr() fails to get an existing xattr and returns ENOATTR in xfs
+ * filesystem.
+ *
+ * Thie bug has been fixed in:
+ *
+ * commit 5a93790d4e2df73e30c965ec6e49be82fc3ccfce
+ * Author: Brian Foster <bfoster@redhat.com>
+ * Date:   Wed Jan 25 07:53:43 2017 -0800
+ *
+ * xfs: remove racy hasattr check from attr ops
+ */
+
+#include "config.h"
+#include <errno.h>
+#include <sys/types.h>
+#include <string.h>
+#include <unistd.h>
+#include <signal.h>
+
+#ifdef HAVE_SYS_XATTR_H
+# include <sys/xattr.h>
+#endif
+
+#include "tst_test.h"
+
+#ifdef HAVE_SYS_XATTR_H
+
+#define MNTPOINT	"mntpoint"
+#define TEST_FILE	MNTPOINT "/file"
+#define TRUSTED_BIG	"trusted.big"
+#define TRUSTED_SMALL	"trusted.small"
+
+static int mount_flag;
+static int end;
+static char big_value[512];
+static char small_value[32];
+
+static void sigproc(int sig)
+{
+	end = sig;
+}
+
+static void loop_getxattr(void)
+{
+	int res;
+
+	while (1) {
+		res = getxattr(TEST_FILE, TRUSTED_SMALL, NULL, 0);
+		if (res == -1) {
+			if (errno == ENODATA) {
+				tst_res(TFAIL, "getxattr() failed to get an "
+					"existing attribute");
+			} else {
+				tst_res(TFAIL | TERRNO,
+					"getxattr() failed without ENOATTR");
+			}
+
+			return;
+		}
+
+		if (end)
+			break;
+	}
+
+	tst_res(TPASS, "getxattr() succeeded to get an existing attribute");
+}
+
+static void verify_getxattr(void)
+{
+	pid_t pid;
+	int n;
+
+	pid = SAFE_FORK();
+	if (!pid) {
+		loop_getxattr();
+		_exit(0);
+	}
+
+	for (n = 0; n < 99; n++) {
+		SAFE_SETXATTR(TEST_FILE, TRUSTED_BIG, big_value,
+				sizeof(big_value), XATTR_CREATE);
+		SAFE_REMOVEXATTR(TEST_FILE, TRUSTED_BIG);
+	}
+
+	kill(pid, SIGUSR1);
+	tst_reap_children();
+}
+
+static void setup(void)
+{
+	SAFE_SIGNAL(SIGUSR1, sigproc);
+
+	SAFE_MKDIR(MNTPOINT, 0755);
+	SAFE_MKFS(tst_device->dev, "xfs", NULL, NULL);
+	SAFE_MOUNT(tst_device->dev, MNTPOINT, "xfs", 0, NULL);
+	mount_flag = 1;
+
+	SAFE_TOUCH(TEST_FILE, 0644, NULL);
+
+	memset(big_value, 'a', sizeof(big_value));
+	memset(small_value, 'a', sizeof(small_value));
+
+	SAFE_SETXATTR(TEST_FILE, TRUSTED_SMALL, small_value,
+			sizeof(small_value), XATTR_CREATE);
+}
+
+static void cleanup(void)
+{
+	if (mount_flag)
+		tst_umount(MNTPOINT);
+}
+
+static struct tst_test test = {
+	.tid = "getxattr04",
+	.needs_tmpdir = 1,
+	.needs_root = 1,
+	.needs_device = 1,
+	.forks_child = 1,
+	.test_all = verify_getxattr,
+	.setup = setup,
+	.cleanup = cleanup
+};
+
+#else /* HAVE_SYS_XATTR_H */
+	TST_TEST_TCONF("<sys/xattr.h> does not exist.");
+#endif
-- 
1.8.3.1




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

* [LTP] [PATCH 3/3] syscalls/getxattr04.c: Add new regression test
  2017-03-02 10:37 ` [LTP] [PATCH 3/3] syscalls/getxattr04.c: Add new regression test Xiao Yang
@ 2017-03-02 16:23   ` Cyril Hrubis
  2017-03-03  1:21     ` [LTP] [PATCH v2 3/3] syscalls/getxattr04.c: add " Xiao Yang
                       ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Cyril Hrubis @ 2017-03-02 16:23 UTC (permalink / raw)
  To: ltp

Hi!
> + * Copyright (c) 2017 Fujitsu Ltd.
> + * Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms of version 2 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
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> + *
> + * You should have received a copy of the GNU General Public License
> + * alone with this program.
> + *
> + */
> +
> +/*
> + * This is a regression test for the race between getting an existing
> + * xattr and setting/removing a large xattr.  This bug leads to that
> + * getxattr() fails to get an existing xattr and returns ENOATTR in xfs
> + * filesystem.
> + *
> + * Thie bug has been fixed in:
> + *
> + * commit 5a93790d4e2df73e30c965ec6e49be82fc3ccfce
> + * Author: Brian Foster <bfoster@redhat.com>
> + * Date:   Wed Jan 25 07:53:43 2017 -0800
> + *
> + * xfs: remove racy hasattr check from attr ops
> + */
> +
> +#include "config.h"
> +#include <errno.h>
> +#include <sys/types.h>
> +#include <string.h>
> +#include <unistd.h>
> +#include <signal.h>
> +
> +#ifdef HAVE_SYS_XATTR_H
> +# include <sys/xattr.h>
> +#endif
> +
> +#include "tst_test.h"
> +
> +#ifdef HAVE_SYS_XATTR_H
> +
> +#define MNTPOINT	"mntpoint"
> +#define TEST_FILE	MNTPOINT "/file"
> +#define TRUSTED_BIG	"trusted.big"
> +#define TRUSTED_SMALL	"trusted.small"
> +
> +static int mount_flag;
> +static int end;

This should be volatile since it's changed from a signal handler.

> +static char big_value[512];
> +static char small_value[32];
> +
> +static void sigproc(int sig)
> +{
> +	end = sig;
> +}
> +
> +static void loop_getxattr(void)
> +{
> +	int res;
> +
> +	while (1) {
> +		res = getxattr(TEST_FILE, TRUSTED_SMALL, NULL, 0);
> +		if (res == -1) {
> +			if (errno == ENODATA) {
> +				tst_res(TFAIL, "getxattr() failed to get an "
> +					"existing attribute");
> +			} else {
> +				tst_res(TFAIL | TERRNO,
> +					"getxattr() failed without ENOATTR");
> +			}
> +
> +			return;
> +		}
> +
> +		if (end)
> +			break;

Why not just while (!end) { ... } ?

> +	}
> +
> +	tst_res(TPASS, "getxattr() succeeded to get an existing attribute");
> +}
> +
> +static void verify_getxattr(void)
> +{
> +	pid_t pid;
> +	int n;
> +
> +	pid = SAFE_FORK();
> +	if (!pid) {
> +		loop_getxattr();
> +		_exit(0);
                  ^
		  Why _exit()? We are not calling this code from a
		  signal handler, are we?

Also why don't we call exit() in the loop_getxattr() function?

> +	}
> +
> +	for (n = 0; n < 99; n++) {
> +		SAFE_SETXATTR(TEST_FILE, TRUSTED_BIG, big_value,
> +				sizeof(big_value), XATTR_CREATE);
> +		SAFE_REMOVEXATTR(TEST_FILE, TRUSTED_BIG);
> +	}
> +
> +	kill(pid, SIGUSR1);
> +	tst_reap_children();
> +}
> +
> +static void setup(void)
> +{
> +	SAFE_SIGNAL(SIGUSR1, sigproc);
> +
> +	SAFE_MKDIR(MNTPOINT, 0755);
> +	SAFE_MKFS(tst_device->dev, "xfs", NULL, NULL);
> +	SAFE_MOUNT(tst_device->dev, MNTPOINT, "xfs", 0, NULL);
> +	mount_flag = 1;

You should make use of the mount_device flag introduced meanwhile:

https://github.com/linux-test-project/ltp/wiki/Test-Writing-Guidelines#2214-testing-with-a-block-device

> +	SAFE_TOUCH(TEST_FILE, 0644, NULL);
> +
> +	memset(big_value, 'a', sizeof(big_value));
> +	memset(small_value, 'a', sizeof(small_value));
> +
> +	SAFE_SETXATTR(TEST_FILE, TRUSTED_SMALL, small_value,
> +			sizeof(small_value), XATTR_CREATE);
> +}
> +
> +static void cleanup(void)
> +{
> +	if (mount_flag)
> +		tst_umount(MNTPOINT);
> +}
> +
> +static struct tst_test test = {
> +	.tid = "getxattr04",
> +	.needs_tmpdir = 1,
> +	.needs_root = 1,
> +	.needs_device = 1,
> +	.forks_child = 1,
> +	.test_all = verify_getxattr,
> +	.setup = setup,
> +	.cleanup = cleanup
> +};
> +
> +#else /* HAVE_SYS_XATTR_H */
> +	TST_TEST_TCONF("<sys/xattr.h> does not exist.");
> +#endif
> -- 
> 1.8.3.1
> 
> 
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH v2 3/3] syscalls/getxattr04.c: add new regression test
  2017-03-02 16:23   ` Cyril Hrubis
@ 2017-03-03  1:21     ` Xiao Yang
  2017-03-03  2:14       ` Xiao Yang
  2017-03-03  1:34     ` [LTP] [PATCH 3/3] syscalls/getxattr04.c: Add " Xiao Yang
  2017-03-03  2:18     ` [LTP] [PATCH v3 3/3] syscalls/getxattr04.c: add " Xiao Yang
  2 siblings, 1 reply; 11+ messages in thread
From: Xiao Yang @ 2017-03-03  1:21 UTC (permalink / raw)
  To: ltp

This is a regression test for the race between getting an existing
xattr and setting/removing a large xattr.  This bug leads to that
getxattr() fails to get an existing xattr and returns ENOATTR in xfs
filesystem.  Thie bug has been fixed in:

commit 5a93790d4e2df73e30c965ec6e49be82fc3ccfce
Author: Brian Foster <bfoster@redhat.com>
Date:   Wed Jan 25 07:53:43 2017 -0800

	xfs: remove racy hasattr check from attr ops

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 runtest/syscalls                                |   1 +
 testcases/kernel/syscalls/.gitignore            |   1 +
 testcases/kernel/syscalls/getxattr/getxattr04.c | 131 ++++++++++++++++++++++++
 3 files changed, 133 insertions(+)
 create mode 100644 testcases/kernel/syscalls/getxattr/getxattr04.c

diff --git a/runtest/syscalls b/runtest/syscalls
index c3ea212..edf0674 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -444,6 +444,7 @@ getuid03_16 getuid03_16
 getxattr01 getxattr01
 getxattr02 getxattr02
 getxattr03 getxattr03
+getxattr04 getxattr04
 
 #Needs tty device.
 #ioctl01 ioctl01 -D /dev/tty0
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index 9d7b947..2728509 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -368,6 +368,7 @@
 /getxattr/getxattr01
 /getxattr/getxattr02
 /getxattr/getxattr03
+/getxattr/getxattr04
 /inotify/inotify01
 /inotify/inotify02
 /inotify/inotify03
diff --git a/testcases/kernel/syscalls/getxattr/getxattr04.c b/testcases/kernel/syscalls/getxattr/getxattr04.c
new file mode 100644
index 0000000..779918e
--- /dev/null
+++ b/testcases/kernel/syscalls/getxattr/getxattr04.c
@@ -0,0 +1,131 @@
+/*
+ * Copyright (c) 2017 Fujitsu Ltd.
+ * Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU General Public License
+ * alone with this program.
+ *
+ */
+
+/*
+ * This is a regression test for the race between getting an existing
+ * xattr and setting/removing a large xattr.  This bug leads to that
+ * getxattr() fails to get an existing xattr and returns ENOATTR in xfs
+ * filesystem.
+ *
+ * Thie bug has been fixed in:
+ *
+ * commit 5a93790d4e2df73e30c965ec6e49be82fc3ccfce
+ * Author: Brian Foster <bfoster@redhat.com>
+ * Date:   Wed Jan 25 07:53:43 2017 -0800
+ *
+ * xfs: remove racy hasattr check from attr ops
+ */
+
+#include "config.h"
+#include <errno.h>
+#include <sys/types.h>
+#include <string.h>
+#include <unistd.h>
+#include <signal.h>
+
+#ifdef HAVE_SYS_XATTR_H
+# include <sys/xattr.h>
+#endif
+
+#include "tst_test.h"
+
+#ifdef HAVE_SYS_XATTR_H
+
+#define MNTPOINT	"mntpoint"
+#define TEST_FILE	MNTPOINT "/file"
+#define TRUSTED_BIG	"trusted.big"
+#define TRUSTED_SMALL	"trusted.small"
+
+static volatile int end;
+static char big_value[512];
+static char small_value[32];
+
+static void sigproc(int sig)
+{
+	end = sig;
+}
+
+static void loop_getxattr(void)
+{
+	int res;
+
+	while (!end) {
+		res = getxattr(TEST_FILE, TRUSTED_SMALL, NULL, 0);
+		if (res == -1) {
+			if (errno == ENODATA) {
+				tst_res(TFAIL, "getxattr() failed to get an "
+					"existing attribute");
+			} else {
+				tst_res(TFAIL | TERRNO,
+					"getxattr() failed without ENOATTR");
+			}
+
+			_exit(0);
+		}
+	}
+
+	tst_res(TPASS, "getxattr() succeeded to get an existing attribute");
+	_exit(0);
+}
+
+static void verify_getxattr(void)
+{
+	pid_t pid;
+	int n;
+
+	pid = SAFE_FORK();
+	if (!pid)
+		loop_getxattr();
+
+	for (n = 0; n < 99; n++) {
+		SAFE_SETXATTR(TEST_FILE, TRUSTED_BIG, big_value,
+				sizeof(big_value), XATTR_CREATE);
+		SAFE_REMOVEXATTR(TEST_FILE, TRUSTED_BIG);
+	}
+
+	kill(pid, SIGUSR1);
+	tst_reap_children();
+}
+
+static void setup(void)
+{
+	SAFE_SIGNAL(SIGUSR1, sigproc);
+
+	SAFE_TOUCH(TEST_FILE, 0644, NULL);
+
+	memset(big_value, 'a', sizeof(big_value));
+	memset(small_value, 'a', sizeof(small_value));
+
+	SAFE_SETXATTR(TEST_FILE, TRUSTED_SMALL, small_value,
+			sizeof(small_value), XATTR_CREATE);
+}
+
+static struct tst_test test = {
+	.tid = "getxattr04",
+	.needs_tmpdir = 1,
+	.needs_root = 1,
+	.mount_device = 1,
+	.dev_fs_type = "xfs",
+	.mntpoint = MNTPOINT,
+	.forks_child = 1,
+	.test_all = verify_getxattr,
+	.setup = setup
+};
+
+#else /* HAVE_SYS_XATTR_H */
+	TST_TEST_TCONF("<sys/xattr.h> does not exist.");
+#endif
-- 
1.8.3.1




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

* [LTP] [PATCH 3/3] syscalls/getxattr04.c: Add new regression test
  2017-03-02 16:23   ` Cyril Hrubis
  2017-03-03  1:21     ` [LTP] [PATCH v2 3/3] syscalls/getxattr04.c: add " Xiao Yang
@ 2017-03-03  1:34     ` Xiao Yang
  2017-03-03  2:18     ` [LTP] [PATCH v3 3/3] syscalls/getxattr04.c: add " Xiao Yang
  2 siblings, 0 replies; 11+ messages in thread
From: Xiao Yang @ 2017-03-03  1:34 UTC (permalink / raw)
  To: ltp

On 2017/03/03 0:23, Cyril Hrubis wrote:
Hi Cyril

Thanks for your comment, i will send v2 patch soon.

Regards,
Xiao Yang
> Hi!
>> + * Copyright (c) 2017 Fujitsu Ltd.
>> + * Author: Xiao Yang<yangx.jy@cn.fujitsu.com>
>> + *
>> + * This program is free software; you can redistribute it and/or modify it
>> + * under the terms of version 2 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
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
>> + *
>> + * You should have received a copy of the GNU General Public License
>> + * alone with this program.
>> + *
>> + */
>> +
>> +/*
>> + * This is a regression test for the race between getting an existing
>> + * xattr and setting/removing a large xattr.  This bug leads to that
>> + * getxattr() fails to get an existing xattr and returns ENOATTR in xfs
>> + * filesystem.
>> + *
>> + * Thie bug has been fixed in:
>> + *
>> + * commit 5a93790d4e2df73e30c965ec6e49be82fc3ccfce
>> + * Author: Brian Foster<bfoster@redhat.com>
>> + * Date:   Wed Jan 25 07:53:43 2017 -0800
>> + *
>> + * xfs: remove racy hasattr check from attr ops
>> + */
>> +
>> +#include "config.h"
>> +#include<errno.h>
>> +#include<sys/types.h>
>> +#include<string.h>
>> +#include<unistd.h>
>> +#include<signal.h>
>> +
>> +#ifdef HAVE_SYS_XATTR_H
>> +# include<sys/xattr.h>
>> +#endif
>> +
>> +#include "tst_test.h"
>> +
>> +#ifdef HAVE_SYS_XATTR_H
>> +
>> +#define MNTPOINT	"mntpoint"
>> +#define TEST_FILE	MNTPOINT "/file"
>> +#define TRUSTED_BIG	"trusted.big"
>> +#define TRUSTED_SMALL	"trusted.small"
>> +
>> +static int mount_flag;
>> +static int end;
> This should be volatile since it's changed from a signal handler.
>
>> +static char big_value[512];
>> +static char small_value[32];
>> +
>> +static void sigproc(int sig)
>> +{
>> +	end = sig;
>> +}
>> +
>> +static void loop_getxattr(void)
>> +{
>> +	int res;
>> +
>> +	while (1) {
>> +		res = getxattr(TEST_FILE, TRUSTED_SMALL, NULL, 0);
>> +		if (res == -1) {
>> +			if (errno == ENODATA) {
>> +				tst_res(TFAIL, "getxattr() failed to get an "
>> +					"existing attribute");
>> +			} else {
>> +				tst_res(TFAIL | TERRNO,
>> +					"getxattr() failed without ENOATTR");
>> +			}
>> +
>> +			return;
>> +		}
>> +
>> +		if (end)
>> +			break;
> Why not just while (!end) { ... } ?
>
>> +	}
>> +
>> +	tst_res(TPASS, "getxattr() succeeded to get an existing attribute");
>> +}
>> +
>> +static void verify_getxattr(void)
>> +{
>> +	pid_t pid;
>> +	int n;
>> +
>> +	pid = SAFE_FORK();
>> +	if (!pid) {
>> +		loop_getxattr();
>> +		_exit(0);
>                    ^
> 		  Why _exit()? We are not calling this code from a
> 		  signal handler, are we?
>
> Also why don't we call exit() in the loop_getxattr() function?
>
>> +	}
>> +
>> +	for (n = 0; n<  99; n++) {
>> +		SAFE_SETXATTR(TEST_FILE, TRUSTED_BIG, big_value,
>> +				sizeof(big_value), XATTR_CREATE);
>> +		SAFE_REMOVEXATTR(TEST_FILE, TRUSTED_BIG);
>> +	}
>> +
>> +	kill(pid, SIGUSR1);
>> +	tst_reap_children();
>> +}
>> +
>> +static void setup(void)
>> +{
>> +	SAFE_SIGNAL(SIGUSR1, sigproc);
>> +
>> +	SAFE_MKDIR(MNTPOINT, 0755);
>> +	SAFE_MKFS(tst_device->dev, "xfs", NULL, NULL);
>> +	SAFE_MOUNT(tst_device->dev, MNTPOINT, "xfs", 0, NULL);
>> +	mount_flag = 1;
> You should make use of the mount_device flag introduced meanwhile:
>
> https://github.com/linux-test-project/ltp/wiki/Test-Writing-Guidelines#2214-testing-with-a-block-device
>
>> +	SAFE_TOUCH(TEST_FILE, 0644, NULL);
>> +
>> +	memset(big_value, 'a', sizeof(big_value));
>> +	memset(small_value, 'a', sizeof(small_value));
>> +
>> +	SAFE_SETXATTR(TEST_FILE, TRUSTED_SMALL, small_value,
>> +			sizeof(small_value), XATTR_CREATE);
>> +}
>> +
>> +static void cleanup(void)
>> +{
>> +	if (mount_flag)
>> +		tst_umount(MNTPOINT);
>> +}
>> +
>> +static struct tst_test test = {
>> +	.tid = "getxattr04",
>> +	.needs_tmpdir = 1,
>> +	.needs_root = 1,
>> +	.needs_device = 1,
>> +	.forks_child = 1,
>> +	.test_all = verify_getxattr,
>> +	.setup = setup,
>> +	.cleanup = cleanup
>> +};
>> +
>> +#else /* HAVE_SYS_XATTR_H */
>> +	TST_TEST_TCONF("<sys/xattr.h>  does not exist.");
>> +#endif
>> -- 
>> 1.8.3.1
>>
>>
>>
>>
>> -- 
>> Mailing list info: https://lists.linux.it/listinfo/ltp




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

* [LTP] [PATCH v2 3/3] syscalls/getxattr04.c: add new regression test
  2017-03-03  1:21     ` [LTP] [PATCH v2 3/3] syscalls/getxattr04.c: add " Xiao Yang
@ 2017-03-03  2:14       ` Xiao Yang
  0 siblings, 0 replies; 11+ messages in thread
From: Xiao Yang @ 2017-03-03  2:14 UTC (permalink / raw)
  To: ltp

Hi Cyril

Sorry, This case doesn't need to use _exit actually, but i forget to
use exit() instead of _exit() as you said. Please ignore this pacth.

Thanks,
Xiao Yang.
On 2017/03/03 9:21, Xiao Yang Wrote:
> This is a regression test for the race between getting an existing
> xattr and setting/removing a large xattr.  This bug leads to that
> getxattr() fails to get an existing xattr and returns ENOATTR in xfs
> filesystem.  Thie bug has been fixed in:
>
> commit 5a93790d4e2df73e30c965ec6e49be82fc3ccfce
> Author: Brian Foster <bfoster@redhat.com>
> Date:   Wed Jan 25 07:53:43 2017 -0800
>
> 	xfs: remove racy hasattr check from attr ops
>
> Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
> ---
>  runtest/syscalls                                |   1 +
>  testcases/kernel/syscalls/.gitignore            |   1 +
>  testcases/kernel/syscalls/getxattr/getxattr04.c | 131 ++++++++++++++++++++++++
>  3 files changed, 133 insertions(+)
>  create mode 100644 testcases/kernel/syscalls/getxattr/getxattr04.c
>
> diff --git a/runtest/syscalls b/runtest/syscalls
> index c3ea212..edf0674 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -444,6 +444,7 @@ getuid03_16 getuid03_16
>  getxattr01 getxattr01
>  getxattr02 getxattr02
>  getxattr03 getxattr03
> +getxattr04 getxattr04
>  
>  #Needs tty device.
>  #ioctl01 ioctl01 -D /dev/tty0
> diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
> index 9d7b947..2728509 100644
> --- a/testcases/kernel/syscalls/.gitignore
> +++ b/testcases/kernel/syscalls/.gitignore
> @@ -368,6 +368,7 @@
>  /getxattr/getxattr01
>  /getxattr/getxattr02
>  /getxattr/getxattr03
> +/getxattr/getxattr04
>  /inotify/inotify01
>  /inotify/inotify02
>  /inotify/inotify03
> diff --git a/testcases/kernel/syscalls/getxattr/getxattr04.c b/testcases/kernel/syscalls/getxattr/getxattr04.c
> new file mode 100644
> index 0000000..779918e
> --- /dev/null
> +++ b/testcases/kernel/syscalls/getxattr/getxattr04.c
> @@ -0,0 +1,131 @@
> +/*
> + * Copyright (c) 2017 Fujitsu Ltd.
> + * Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms of version 2 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
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> + *
> + * You should have received a copy of the GNU General Public License
> + * alone with this program.
> + *
> + */
> +
> +/*
> + * This is a regression test for the race between getting an existing
> + * xattr and setting/removing a large xattr.  This bug leads to that
> + * getxattr() fails to get an existing xattr and returns ENOATTR in xfs
> + * filesystem.
> + *
> + * Thie bug has been fixed in:
> + *
> + * commit 5a93790d4e2df73e30c965ec6e49be82fc3ccfce
> + * Author: Brian Foster <bfoster@redhat.com>
> + * Date:   Wed Jan 25 07:53:43 2017 -0800
> + *
> + * xfs: remove racy hasattr check from attr ops
> + */
> +
> +#include "config.h"
> +#include <errno.h>
> +#include <sys/types.h>
> +#include <string.h>
> +#include <unistd.h>
> +#include <signal.h>
> +
> +#ifdef HAVE_SYS_XATTR_H
> +# include <sys/xattr.h>
> +#endif
> +
> +#include "tst_test.h"
> +
> +#ifdef HAVE_SYS_XATTR_H
> +
> +#define MNTPOINT	"mntpoint"
> +#define TEST_FILE	MNTPOINT "/file"
> +#define TRUSTED_BIG	"trusted.big"
> +#define TRUSTED_SMALL	"trusted.small"
> +
> +static volatile int end;
> +static char big_value[512];
> +static char small_value[32];
> +
> +static void sigproc(int sig)
> +{
> +	end = sig;
> +}
> +
> +static void loop_getxattr(void)
> +{
> +	int res;
> +
> +	while (!end) {
> +		res = getxattr(TEST_FILE, TRUSTED_SMALL, NULL, 0);
> +		if (res == -1) {
> +			if (errno == ENODATA) {
> +				tst_res(TFAIL, "getxattr() failed to get an "
> +					"existing attribute");
> +			} else {
> +				tst_res(TFAIL | TERRNO,
> +					"getxattr() failed without ENOATTR");
> +			}
> +
> +			_exit(0);
> +		}
> +	}
> +
> +	tst_res(TPASS, "getxattr() succeeded to get an existing attribute");
> +	_exit(0);
> +}
> +
> +static void verify_getxattr(void)
> +{
> +	pid_t pid;
> +	int n;
> +
> +	pid = SAFE_FORK();
> +	if (!pid)
> +		loop_getxattr();
> +
> +	for (n = 0; n < 99; n++) {
> +		SAFE_SETXATTR(TEST_FILE, TRUSTED_BIG, big_value,
> +				sizeof(big_value), XATTR_CREATE);
> +		SAFE_REMOVEXATTR(TEST_FILE, TRUSTED_BIG);
> +	}
> +
> +	kill(pid, SIGUSR1);
> +	tst_reap_children();
> +}
> +
> +static void setup(void)
> +{
> +	SAFE_SIGNAL(SIGUSR1, sigproc);
> +
> +	SAFE_TOUCH(TEST_FILE, 0644, NULL);
> +
> +	memset(big_value, 'a', sizeof(big_value));
> +	memset(small_value, 'a', sizeof(small_value));
> +
> +	SAFE_SETXATTR(TEST_FILE, TRUSTED_SMALL, small_value,
> +			sizeof(small_value), XATTR_CREATE);
> +}
> +
> +static struct tst_test test = {
> +	.tid = "getxattr04",
> +	.needs_tmpdir = 1,
> +	.needs_root = 1,
> +	.mount_device = 1,
> +	.dev_fs_type = "xfs",
> +	.mntpoint = MNTPOINT,
> +	.forks_child = 1,
> +	.test_all = verify_getxattr,
> +	.setup = setup
> +};
> +
> +#else /* HAVE_SYS_XATTR_H */
> +	TST_TEST_TCONF("<sys/xattr.h> does not exist.");
> +#endif




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

* [LTP] [PATCH v3 3/3] syscalls/getxattr04.c: add new regression test
  2017-03-02 16:23   ` Cyril Hrubis
  2017-03-03  1:21     ` [LTP] [PATCH v2 3/3] syscalls/getxattr04.c: add " Xiao Yang
  2017-03-03  1:34     ` [LTP] [PATCH 3/3] syscalls/getxattr04.c: Add " Xiao Yang
@ 2017-03-03  2:18     ` Xiao Yang
  2017-03-03  9:57       ` Cyril Hrubis
  2 siblings, 1 reply; 11+ messages in thread
From: Xiao Yang @ 2017-03-03  2:18 UTC (permalink / raw)
  To: ltp

This is a regression test for the race between getting an existing
xattr and setting/removing a large xattr.  This bug leads to that
getxattr() fails to get an existing xattr and returns ENOATTR in xfs
filesystem.  Thie bug has been fixed in:

commit 5a93790d4e2df73e30c965ec6e49be82fc3ccfce
Author: Brian Foster <bfoster@redhat.com>
Date:   Wed Jan 25 07:53:43 2017 -0800

	xfs: remove racy hasattr check from attr ops

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 runtest/syscalls                                |   1 +
 testcases/kernel/syscalls/.gitignore            |   1 +
 testcases/kernel/syscalls/getxattr/getxattr04.c | 131 ++++++++++++++++++++++++
 3 files changed, 133 insertions(+)
 create mode 100644 testcases/kernel/syscalls/getxattr/getxattr04.c

diff --git a/runtest/syscalls b/runtest/syscalls
index c3ea212..edf0674 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -444,6 +444,7 @@ getuid03_16 getuid03_16
 getxattr01 getxattr01
 getxattr02 getxattr02
 getxattr03 getxattr03
+getxattr04 getxattr04
 
 #Needs tty device.
 #ioctl01 ioctl01 -D /dev/tty0
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index 9d7b947..2728509 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -368,6 +368,7 @@
 /getxattr/getxattr01
 /getxattr/getxattr02
 /getxattr/getxattr03
+/getxattr/getxattr04
 /inotify/inotify01
 /inotify/inotify02
 /inotify/inotify03
diff --git a/testcases/kernel/syscalls/getxattr/getxattr04.c b/testcases/kernel/syscalls/getxattr/getxattr04.c
new file mode 100644
index 0000000..1a793b9
--- /dev/null
+++ b/testcases/kernel/syscalls/getxattr/getxattr04.c
@@ -0,0 +1,131 @@
+/*
+ * Copyright (c) 2017 Fujitsu Ltd.
+ * Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU General Public License
+ * alone with this program.
+ *
+ */
+
+/*
+ * This is a regression test for the race between getting an existing
+ * xattr and setting/removing a large xattr.  This bug leads to that
+ * getxattr() fails to get an existing xattr and returns ENOATTR in xfs
+ * filesystem.
+ *
+ * Thie bug has been fixed in:
+ *
+ * commit 5a93790d4e2df73e30c965ec6e49be82fc3ccfce
+ * Author: Brian Foster <bfoster@redhat.com>
+ * Date:   Wed Jan 25 07:53:43 2017 -0800
+ *
+ * xfs: remove racy hasattr check from attr ops
+ */
+
+#include "config.h"
+#include <errno.h>
+#include <sys/types.h>
+#include <string.h>
+#include <stdlib.h>
+#include <signal.h>
+
+#ifdef HAVE_SYS_XATTR_H
+# include <sys/xattr.h>
+#endif
+
+#include "tst_test.h"
+
+#ifdef HAVE_SYS_XATTR_H
+
+#define MNTPOINT	"mntpoint"
+#define TEST_FILE	MNTPOINT "/file"
+#define TRUSTED_BIG	"trusted.big"
+#define TRUSTED_SMALL	"trusted.small"
+
+static volatile int end;
+static char big_value[512];
+static char small_value[32];
+
+static void sigproc(int sig)
+{
+	end = sig;
+}
+
+static void loop_getxattr(void)
+{
+	int res;
+
+	while (!end) {
+		res = getxattr(TEST_FILE, TRUSTED_SMALL, NULL, 0);
+		if (res == -1) {
+			if (errno == ENODATA) {
+				tst_res(TFAIL, "getxattr() failed to get an "
+					"existing attribute");
+			} else {
+				tst_res(TFAIL | TERRNO,
+					"getxattr() failed without ENOATTR");
+			}
+
+			exit(0);
+		}
+	}
+
+	tst_res(TPASS, "getxattr() succeeded to get an existing attribute");
+	exit(0);
+}
+
+static void verify_getxattr(void)
+{
+	pid_t pid;
+	int n;
+
+	pid = SAFE_FORK();
+	if (!pid)
+		loop_getxattr();
+
+	for (n = 0; n < 99; n++) {
+		SAFE_SETXATTR(TEST_FILE, TRUSTED_BIG, big_value,
+				sizeof(big_value), XATTR_CREATE);
+		SAFE_REMOVEXATTR(TEST_FILE, TRUSTED_BIG);
+	}
+
+	kill(pid, SIGUSR1);
+	tst_reap_children();
+}
+
+static void setup(void)
+{
+	SAFE_SIGNAL(SIGUSR1, sigproc);
+
+	SAFE_TOUCH(TEST_FILE, 0644, NULL);
+
+	memset(big_value, 'a', sizeof(big_value));
+	memset(small_value, 'a', sizeof(small_value));
+
+	SAFE_SETXATTR(TEST_FILE, TRUSTED_SMALL, small_value,
+			sizeof(small_value), XATTR_CREATE);
+}
+
+static struct tst_test test = {
+	.tid = "getxattr04",
+	.needs_tmpdir = 1,
+	.needs_root = 1,
+	.mount_device = 1,
+	.dev_fs_type = "xfs",
+	.mntpoint = MNTPOINT,
+	.forks_child = 1,
+	.test_all = verify_getxattr,
+	.setup = setup
+};
+
+#else /* HAVE_SYS_XATTR_H */
+	TST_TEST_TCONF("<sys/xattr.h> does not exist.");
+#endif
-- 
1.8.3.1




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

* [LTP] [PATCH v3 3/3] syscalls/getxattr04.c: add new regression test
  2017-03-03  2:18     ` [LTP] [PATCH v3 3/3] syscalls/getxattr04.c: add " Xiao Yang
@ 2017-03-03  9:57       ` Cyril Hrubis
  2017-03-06  8:50         ` [LTP] [PATCH v4 " Xiao Yang
  0 siblings, 1 reply; 11+ messages in thread
From: Cyril Hrubis @ 2017-03-03  9:57 UTC (permalink / raw)
  To: ltp

Hi!
> +/*
> + * Copyright (c) 2017 Fujitsu Ltd.
> + * Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms of version 2 of the GNU General Public License as
> + * published by the Free Software Foundation.

Can we please use GPLv2+ (the one with any later clausule)?

> + * This program is distributed in the hope that it would be useful, but
> + * WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> + *
> + * You should have received a copy of the GNU General Public License
> + * alone with this program.
> + *
> + */
> +

...

> +static void loop_getxattr(void)
> +{
> +	int res;
> +
> +	while (!end) {
> +		res = getxattr(TEST_FILE, TRUSTED_SMALL, NULL, 0);
> +		if (res == -1) {
> +			if (errno == ENODATA) {
> +				tst_res(TFAIL, "getxattr() failed to get an "
> +					"existing attribute");
> +			} else {
> +				tst_res(TFAIL | TERRNO,
> +					"getxattr() failed without ENOATTR");
> +			}
> +
> +			exit(0);
> +		}
> +	}
> +
> +	tst_res(TPASS, "getxattr() succeeded to get an existing attribute");
> +	exit(0);
> +}
> +
> +static void verify_getxattr(void)
> +{
> +	pid_t pid;
> +	int n;

We should reset the end variable here, in case that the program is
looping (-i option).


Otherwise it look good.

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH v4 3/3] syscalls/getxattr04.c: add new regression test
  2017-03-03  9:57       ` Cyril Hrubis
@ 2017-03-06  8:50         ` Xiao Yang
  2017-03-06  9:58           ` Cyril Hrubis
  0 siblings, 1 reply; 11+ messages in thread
From: Xiao Yang @ 2017-03-06  8:50 UTC (permalink / raw)
  To: ltp

This is a regression test for the race between getting an existing
xattr and setting/removing a large xattr.  This bug leads to that
getxattr() fails to get an existing xattr and returns ENOATTR in xfs
filesystem.  Thie bug has been fixed in:

commit 5a93790d4e2df73e30c965ec6e49be82fc3ccfce
Author: Brian Foster <bfoster@redhat.com>
Date:   Wed Jan 25 07:53:43 2017 -0800

	xfs: remove racy hasattr check from attr ops

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 runtest/syscalls                                |   1 +
 testcases/kernel/syscalls/.gitignore            |   1 +
 testcases/kernel/syscalls/getxattr/getxattr04.c | 134 ++++++++++++++++++++++++
 3 files changed, 136 insertions(+)
 create mode 100644 testcases/kernel/syscalls/getxattr/getxattr04.c

diff --git a/runtest/syscalls b/runtest/syscalls
index c3ea212..edf0674 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -444,6 +444,7 @@ getuid03_16 getuid03_16
 getxattr01 getxattr01
 getxattr02 getxattr02
 getxattr03 getxattr03
+getxattr04 getxattr04
 
 #Needs tty device.
 #ioctl01 ioctl01 -D /dev/tty0
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index 9d7b947..2728509 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -368,6 +368,7 @@
 /getxattr/getxattr01
 /getxattr/getxattr02
 /getxattr/getxattr03
+/getxattr/getxattr04
 /inotify/inotify01
 /inotify/inotify02
 /inotify/inotify03
diff --git a/testcases/kernel/syscalls/getxattr/getxattr04.c b/testcases/kernel/syscalls/getxattr/getxattr04.c
new file mode 100644
index 0000000..625337d
--- /dev/null
+++ b/testcases/kernel/syscalls/getxattr/getxattr04.c
@@ -0,0 +1,134 @@
+/*
+ * Copyright (c) 2017 Fujitsu Ltd.
+ * Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
+ *
+ * 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, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * 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, see <http://www.gnu.org/licenses/>.*
+ */
+
+/*
+ * This is a regression test for the race between getting an existing
+ * xattr and setting/removing a large xattr.  This bug leads to that
+ * getxattr() fails to get an existing xattr and returns ENOATTR in xfs
+ * filesystem.
+ *
+ * Thie bug has been fixed in:
+ *
+ * commit 5a93790d4e2df73e30c965ec6e49be82fc3ccfce
+ * Author: Brian Foster <bfoster@redhat.com>
+ * Date:   Wed Jan 25 07:53:43 2017 -0800
+ *
+ * xfs: remove racy hasattr check from attr ops
+ */
+
+#include "config.h"
+#include <errno.h>
+#include <sys/types.h>
+#include <string.h>
+#include <stdlib.h>
+#include <signal.h>
+
+#ifdef HAVE_SYS_XATTR_H
+# include <sys/xattr.h>
+#endif
+
+#include "tst_test.h"
+
+#ifdef HAVE_SYS_XATTR_H
+
+#define MNTPOINT	"mntpoint"
+#define TEST_FILE	MNTPOINT "/file"
+#define TRUSTED_BIG	"trusted.big"
+#define TRUSTED_SMALL	"trusted.small"
+
+static volatile int end;
+static char big_value[512];
+static char small_value[32];
+
+static void sigproc(int sig)
+{
+	end = sig;
+}
+
+static void loop_getxattr(void)
+{
+	int res;
+
+	while (!end) {
+		res = getxattr(TEST_FILE, TRUSTED_SMALL, NULL, 0);
+		if (res == -1) {
+			if (errno == ENODATA) {
+				tst_res(TFAIL, "getxattr() failed to get an "
+					"existing attribute");
+			} else {
+				tst_res(TFAIL | TERRNO,
+					"getxattr() failed without ENOATTR");
+			}
+
+			exit(0);
+		}
+	}
+
+	tst_res(TPASS, "getxattr() succeeded to get an existing attribute");
+	exit(0);
+}
+
+static void verify_getxattr(void)
+{
+	pid_t pid;
+	int n;
+
+	end = 0;
+
+	pid = SAFE_FORK();
+	if (!pid)
+		loop_getxattr();
+
+	for (n = 0; n < 99; n++) {
+		SAFE_SETXATTR(TEST_FILE, TRUSTED_BIG, big_value,
+				sizeof(big_value), XATTR_CREATE);
+		SAFE_REMOVEXATTR(TEST_FILE, TRUSTED_BIG);
+	}
+
+	kill(pid, SIGUSR1);
+	tst_reap_children();
+}
+
+static void setup(void)
+{
+	SAFE_SIGNAL(SIGUSR1, sigproc);
+
+	SAFE_TOUCH(TEST_FILE, 0644, NULL);
+
+	memset(big_value, 'a', sizeof(big_value));
+	memset(small_value, 'a', sizeof(small_value));
+
+	SAFE_SETXATTR(TEST_FILE, TRUSTED_SMALL, small_value,
+			sizeof(small_value), XATTR_CREATE);
+}
+
+static struct tst_test test = {
+	.tid = "getxattr04",
+	.needs_tmpdir = 1,
+	.needs_root = 1,
+	.mount_device = 1,
+	.dev_fs_type = "xfs",
+	.mntpoint = MNTPOINT,
+	.forks_child = 1,
+	.test_all = verify_getxattr,
+	.setup = setup
+};
+
+#else /* HAVE_SYS_XATTR_H */
+	TST_TEST_TCONF("<sys/xattr.h> does not exist.");
+#endif
-- 
1.8.3.1




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

* [LTP] [PATCH v4 3/3] syscalls/getxattr04.c: add new regression test
  2017-03-06  8:50         ` [LTP] [PATCH v4 " Xiao Yang
@ 2017-03-06  9:58           ` Cyril Hrubis
  0 siblings, 0 replies; 11+ messages in thread
From: Cyril Hrubis @ 2017-03-06  9:58 UTC (permalink / raw)
  To: ltp

Hi!
Whole patchset pushed, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

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

end of thread, other threads:[~2017-03-06  9:58 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-02 10:37 [LTP] [PATCH 1/3] safe_macros: remove unused code in xattr related functions Xiao Yang
2017-03-02 10:37 ` [LTP] [PATCH 2/3] safe_macros: add safe_removexattr() Xiao Yang
2017-03-02 10:37 ` [LTP] [PATCH 3/3] syscalls/getxattr04.c: Add new regression test Xiao Yang
2017-03-02 16:23   ` Cyril Hrubis
2017-03-03  1:21     ` [LTP] [PATCH v2 3/3] syscalls/getxattr04.c: add " Xiao Yang
2017-03-03  2:14       ` Xiao Yang
2017-03-03  1:34     ` [LTP] [PATCH 3/3] syscalls/getxattr04.c: Add " Xiao Yang
2017-03-03  2:18     ` [LTP] [PATCH v3 3/3] syscalls/getxattr04.c: add " Xiao Yang
2017-03-03  9:57       ` Cyril Hrubis
2017-03-06  8:50         ` [LTP] [PATCH v4 " Xiao Yang
2017-03-06  9:58           ` Cyril Hrubis

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.