Linux Test Project
 help / color / mirror / Atom feed
From: Wake Liu via ltp <ltp@lists.linux.it>
To: chrubis@suse.cz
Cc: wakel@google.com, ltp@lists.linux.it
Subject: [LTP] [PATCH v3] syscalls/file_attr01: Dynamically expect EOPNOTSUPP on tmpfs without xattr
Date: Wed, 29 Apr 2026 14:26:50 +0800	[thread overview]
Message-ID: <20260429062650.3191021-1-wakel@google.com> (raw)
In-Reply-To: <aeDpBp_TNCJYCDzG@yuki.lan>

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


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  reply	other threads:[~2026-04-29  6:27 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-20  7:57 [LTP] [PATCH] syscalls/file_attr01: Allow EOPNOTSUPP when attributes is NULL Wake Liu via ltp
2026-03-20  8:57 ` Andrea Cervesato via ltp
2026-03-23  7:26   ` Wake Liu via ltp
2026-03-23  7:48     ` [LTP] [PATCH v2] syscalls/file_attr01: Dynamically expect EOPNOTSUPP on tmpfs without xattr Wake Liu via ltp
2026-03-23  9:07       ` Andrea Cervesato via ltp
2026-04-16 13:49       ` Cyril Hrubis
2026-04-29  6:26         ` Wake Liu via ltp [this message]
2026-04-29  7:34           ` [LTP] " linuxtestproject.agent
2026-04-29  9:22             ` Wake Liu via ltp
2026-05-12 13:25           ` [LTP] [PATCH v3] " Cyril Hrubis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260429062650.3191021-1-wakel@google.com \
    --to=ltp@lists.linux.it \
    --cc=chrubis@suse.cz \
    --cc=wakel@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox