[LTP] [PATCH v3] syscalls/file_attr01: Dynamically expect EOPNOTSUPP on tmpfs without xattr

Wake Liu wakel@google.com
Wed Apr 29 08:26:50 CEST 2026


From: Wake Liu via ltp <ltp@lists.linux.it>

The syscalls file_getattr and file_setattr return EOPNOTSUPP instead of
EFAULT when the ufattr argument is NULL on tmpfs without xattr support
(CONFIG_TMPFS_XATTR=n). This is because the kernel checks for the
filesystem operation support before dereferencing the user pointer.

This patch adds a runtime check for CONFIG_TMPFS_XATTR when testing
on tmpfs, ensuring the correct errno is expected based on the kernel
configuration. This prevents hiding potential kernel bugs where
EOPNOTSUPP might be returned even when xattr is supported.

Changes in v3:
- Moved tst_kconfig_check() to setup() to avoid parsing the kernel
  config in each iteration of run(), as suggested by Cyril Hrubis.

Changes in v2:
- Replaced the TST_EXP_FAIL_ARR approach with a dynamic check in run().
- Included tst_kconfig.h and used tst_kconfig_check() to verify
  CONFIG_TMPFS_XATTR status.
- Expected EOPNOTSUPP only on tmpfs when xattr support is missing,
  otherwise default to EFAULT.

Signed-off-by: Wake Liu <wakel@google.com>
---
 testcases/kernel/syscalls/file_attr/file_attr01.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/testcases/kernel/syscalls/file_attr/file_attr01.c b/testcases/kernel/syscalls/file_attr/file_attr01.c
index c9c9288a1..419d54c36 100644
--- a/testcases/kernel/syscalls/file_attr/file_attr01.c
+++ b/testcases/kernel/syscalls/file_attr/file_attr01.c
@@ -18,6 +18,7 @@
 
 #include <string.h>
 #include "tst_test.h"
+#include "tst_kconfig.h"
 #include "lapi/fs.h"
 #include "lapi/fcntl.h"
 
@@ -35,6 +36,7 @@ static size_t small_usize;
 static size_t valid_usize;
 static size_t big_usize;
 static struct file_attr *valid_file_attr;
+static int missing_tmpfs_xattr;
 
 static struct tcase {
 	int *dfd;
@@ -115,20 +117,24 @@ static struct tcase {
 static void run(unsigned int i)
 {
 	struct tcase *tc = &tcases[i];
+	int exp_errno = tc->exp_errno;
+
+	if (tc->ufattr == (struct file_attr **)(&null_ptr) && missing_tmpfs_xattr)
+		exp_errno = EOPNOTSUPP;
 
 	if (tst_variant) {
 		TST_EXP_FAIL(file_getattr(
 			*tc->dfd, *tc->filename,
 			*tc->ufattr, *tc->usize,
 			tc->at_flags),
-			tc->exp_errno,
+			exp_errno,
 			"%s", tc->msg);
 	} else {
 		TST_EXP_FAIL(file_setattr(
 			*tc->dfd, *tc->filename,
 			*tc->ufattr, *tc->usize,
 			tc->at_flags),
-			tc->exp_errno,
+			exp_errno,
 			"%s", tc->msg);
 	}
 }
@@ -144,6 +150,11 @@ static void setup(void)
 	valid_usize = FILE_ATTR_SIZE_LATEST;
 	small_usize = FILE_ATTR_SIZE_VER0 - 1;
 	big_usize = SAFE_SYSCONF(_SC_PAGESIZE) + 100;
+
+	if (!strcmp(tst_device->fs_type, "tmpfs")) {
+		const char *const kconfig[] = {"CONFIG_TMPFS_XATTR=y", NULL};
+		missing_tmpfs_xattr = tst_kconfig_check(kconfig);
+	}
 }
 
 static void cleanup(void)
-- 
2.54.0.545.g6539524ca2-goog



More information about the ltp mailing list