[LTP] [PATCH v2] syscalls/file_attr01: Dynamically expect EOPNOTSUPP on tmpfs without xattr
Wake Liu
wakel@google.com
Mon Mar 23 08:48:14 CET 2026
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 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 | 13 +++++++++++--
1 file changed, 11 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..43e0f0503 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"
@@ -115,20 +116,28 @@ 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)) {
+ const char *const kconfig[] = {"CONFIG_TMPFS_XATTR=y", NULL};
+
+ if (!strcmp(tst_device->fs_type, "tmpfs") && tst_kconfig_check(kconfig))
+ 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);
}
}
--
2.53.0.983.g0bb29b3bc5-goog
More information about the ltp
mailing list