Skip to contentSkip to conversation

syscalls/file_attr01: Allow EOPNOTSUPP when attributes is NULL

PATCH In review Wake Liu via ltp 3 participants 13 messages Mar 20 – May 20

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 syscalls/file_attr01: Allow EOPNOTSUPP when attributes is NULL

The syscalls file_getattr and file_setattr may return EOPNOTSUPP instead of EFAULT when the ufattr argument is NULL, specifically on filesystems that do not support extended attributes (e.g., tmpfs when CONFIG_TMPFS_XATTR is disabled).

In the kernel, the fileattr_get/set operations are checked before the pointer dereference. If the filesystem does not define these operations, the kernel returns -ENOIOCTLCMD (translated to EOPNOTSUPP in userspace) before checking the validity of the user-provided pointer.

This is a valid behavior for kernel configurations where extended attributes are not enabled for certain filesystems. This leads to test failures on such systems:
TFAIL: File attributes is NULL expected EFAULT: EOPNOTSUPP (95)

This patch updates the test case to support multiple expected errnos using TST_EXP_FAIL_ARR, allowing both EFAULT and EOPNOTSUPP for the NULL attributes test case.

---
 .../kernel/syscalls/file_attr/file_attr01.c   | 35 ++++++++++++-------
 1 file changed, 22 insertions(+), 13 deletions(-)
testcases/kernel/syscalls/file_attr/file_attr01.c +22 -13
index c9c9288a1..02aea66a6 100644
@@ -42,7 +42,8 @@ static struct tcase {
 	struct file_attr **ufattr;
 	size_t *usize;
 	int at_flags;
-	int exp_errno;
+	int exp_errs[2];
+	int exp_errs_cnt;
 	char *msg;
 } tcases[] = {
 	{
@@ -50,7 +51,8 @@ static struct tcase {
 		.filename = &valid_filename,
 		.ufattr = &valid_file_attr,
 		.usize = &valid_usize,
-		.exp_errno = EBADF,
+		.exp_errs = {EBADF},
+		.exp_errs_cnt = 1,
 		.msg = "Invalid file descriptor",
 	},
 	{
@@ -58,7 +60,8 @@ static struct tcase {
 		.filename = &invalid_filename,
 		.ufattr = &valid_file_attr,
 		.usize = &valid_usize,
-		.exp_errno = ENOENT,
+		.exp_errs = {ENOENT},
+		.exp_errs_cnt = 1,
 		.msg = "File doesn't exist",
 	},
 	{
@@ -66,7 +69,8 @@ static struct tcase {
 		.filename = &null_ptr,
 		.ufattr = &valid_file_attr,
 		.usize = &valid_usize,
-		.exp_errno = EFAULT,
+		.exp_errs = {EFAULT},
+		.exp_errs_cnt = 1,
 		.msg = "Filename is NULL",
 	},
 	{
@@ -74,7 +78,8 @@ static struct tcase {
 		.filename = &valid_filename,
 		.ufattr = (struct file_attr **)(&null_ptr),
 		.usize = &valid_usize,
-		.exp_errno = EFAULT,
+		.exp_errs = {EFAULT, EOPNOTSUPP},
+		.exp_errs_cnt = 2,
 		.msg = "File attributes is NULL",
 	},
 	{
@@ -82,7 +87,8 @@ static struct tcase {
 		.filename = &valid_filename,
 		.ufattr = &valid_file_attr,
 		.usize = &zero,
-		.exp_errno = EINVAL,
+		.exp_errs = {EINVAL},
+		.exp_errs_cnt = 1,
 		.msg = "File attributes size is zero",
 	},
 	{
@@ -90,7 +96,8 @@ static struct tcase {
 		.filename = &valid_filename,
 		.ufattr = &valid_file_attr,
 		.usize = &small_usize,
-		.exp_errno = EINVAL,
+		.exp_errs = {EINVAL},
+		.exp_errs_cnt = 1,
 		.msg = "File attributes size is too small",
 	},
 	{
@@ -98,7 +105,8 @@ static struct tcase {
 		.filename = &valid_filename,
 		.ufattr = &valid_file_attr,
 		.usize = &big_usize,
-		.exp_errno = E2BIG,
+		.exp_errs = {E2BIG},
+		.exp_errs_cnt = 1,
 		.msg = "File attributes size is too big",
 	},
 	{
@@ -107,7 +115,8 @@ static struct tcase {
 		.ufattr = &valid_file_attr,
 		.usize = &valid_usize,
 		.at_flags = -1,
-		.exp_errno = EINVAL,
+		.exp_errs = {EINVAL},
+		.exp_errs_cnt = 1,
 		.msg = "Invalid AT flags",
 	},
 };
@@ -117,18 +126,18 @@ static void run(unsigned int i)
 	struct tcase *tc = &tcases[i];
 
 	if (tst_variant) {
-		TST_EXP_FAIL(file_getattr(
+		TST_EXP_FAIL_ARR(file_getattr(
 			*tc->dfd, *tc->filename,
 			*tc->ufattr, *tc->usize,
 			tc->at_flags),
-			tc->exp_errno,
+			tc->exp_errs, tc->exp_errs_cnt,
 			"%s", tc->msg);
 	} else {
-		TST_EXP_FAIL(file_setattr(
+		TST_EXP_FAIL_ARR(file_setattr(
 			*tc->dfd, *tc->filename,
 			*tc->ufattr, *tc->usize,
 			tc->at_flags),
-			tc->exp_errno,
+			tc->exp_errs, tc->exp_errs_cnt,
 			"%s", tc->msg);
 	}
 }
Signature · 5 lines
2.53.0.983.g0bb29b3bc5-goog


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi Wake,

Quoted 4 lines

The syscalls file_getattr and file_setattr may return EOPNOTSUPP instead of EFAULT when the ufattr argument is NULL, specifically on filesystems that do not support extended attributes (e.g., tmpfs when CONFIG_TMPFS_XATTR is disabled).

Patch is technically correct but EOPNOTSUPP should not be tested int this way, since we are not checking the underlying kernel configuration. For instance, we might have xattr support, but getting EOPNOTSUPP and have a TPASS. This would be a kernel bug hidden by the test structure.

In other circumstances (if xattr was our testing goal) we might have used .needs_kconfig, but in this case we should use a different approach:

- we verify at runtime that our kernel supports xattr via tst_kconfig_check()
- if kernel doesn't support xattr, we expect EOPNOTSUPP. Otherwise, EFAULT

In this way we make sure that syscalls are raising the proper error according to the kernel configuration.

WDYT?

--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw
Quoted 21 lines

Hi Wake,

Quoted 4 lines

The syscalls file_getattr and file_setattr may return EOPNOTSUPP instead of EFAULT when the ufattr argument is NULL, specifically on filesystems that do not support extended attributes (e.g., tmpfs when CONFIG_TMPFS_XATTR is disabled).

Patch is technically correct but EOPNOTSUPP should not be tested int this way, since we are not checking the underlying kernel configuration. For instance, we might have xattr support, but getting EOPNOTSUPP and have a TPASS. This would be a kernel bug hidden by the test structure.

In other circumstances (if xattr was our testing goal) we might have used .needs_kconfig, but in this case we should use a different approach:

- we verify at runtime that our kernel supports xattr via tst_kconfig_check()
- if kernel doesn't support xattr, we expect EOPNOTSUPP. Otherwise, EFAULT

In this way we make sure that syscalls are raising the proper error according to the kernel configuration.

Quoted 6 lines

WDYT?

--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]

Hi Andrea,

Thanks for the quick review and the detailed feedback.

I agree with your assessment that allowing EOPNOTSUPP unconditionally could potentially mask a kernel bug if xattr support is present but returns the wrong error. That's definitely something we should avoid.

Your suggested approach using tst_kconfig_check() at runtime to verify kernel xattr support is much more robust and is the correct way to handle this. It ensures the syscalls raise the proper error based on the configuration.

I will revise the patch (v2) to implement this logic:

*   Check xattr support via tst_kconfig_check().
*   If xattr is not supported, expect EOPNOTSUPP.
*   Otherwise, expect EFAULT.

I'll send it out shortly.

Thanks again,

Signature · 5 lines
Best Regards,
Wake Liu

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

PATCH v2 1/1 syscalls/file_attr01: Dynamically expect EOPNOTSUPP on tmpfs without xattr

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.

---
 testcases/kernel/syscalls/file_attr/file_attr01.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/file_attr/file_attr01.c +11 -2
index c9c9288a1..43e0f0503 100644
@@ -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);
 	}
 }
Signature · 5 lines
2.53.0.983.g0bb29b3bc5-goog


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw

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

In reply to Wake Liu via ltp

Hi!

testcases/kernel/syscalls/file_attr/file_attr01.c static struct tcase { · line 126

Quoted 12 lines
testcases/kernel/syscalls/file_attr/file_attr01.c +8 -0
@@ -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;
+	}

The call to tst_kconfig_check() should be done once in the test setup() and we should set a flag based on the outcome. Without that we will parse the kernel config in each iteration of the run() function (e.g. if run the test with -i 10).

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#6 lore raw

PATCH v3 1/1 syscalls/file_attr01: Dynamically expect EOPNOTSUPP on tmpfs without xattr

From: Wake Liu via ltp <[email protected]>

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.

---
 testcases/kernel/syscalls/file_attr/file_attr01.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/file_attr/file_attr01.c +13 -2
index c9c9288a1..419d54c36 100644
@@ -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)
Signature · 5 lines
2.54.0.545.g6539524ca2-goog


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#7 lore raw

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

Hi Wake,

testcases/kernel/syscalls/file_attr/file_attr01.c static struct tcase { · line 123

Quoted 4 lines · Wake Liu

syscalls/file_attr01: Dynamically expect EOPNOTSUPP on tmpfs without xattr

testcases/kernel/syscalls/file_attr/file_attr01.c +2 -0
+	if (tc->ufattr == (struct file_attr **)(&null_ptr) && missing_tmpfs_xattr)
+		exp_errno = EOPNOTSUPP;

The override is scoped only to the null-ufattr tcase. The commit message says the kernel checks xattr support "before dereferencing the user pointer", which raises the question of whether usize validation (EINVAL/E2BIG tcases) also occurs after the support check. If so, those tcases would also return EOPNOTSUPP on tmpfs without xattr and need the same treatment. Please clarify the kernel's validation order for usize relative to the xattr support check.

Quoted 1 line

Changes in v3:

[...]

Quoted 1 line

Changes in v2:

[...]

Version changelogs should be stripped from the commit message before merging; they belong in the cover letter only.

---
Note:

Our agent completed the review of the patch. The full review can be found at: https://github.com/linux-test-project/ltp-agent/actions/runs/25096139400

The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#8 lore raw

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

Regarding the validation order of usize: I have verified that usize validation (EINVAL/E2BIG) occurs before the filesystem support check in the kernel. This is confirmed by the LTP test results on a kernel with CONFIG_TMPFS_XATTR=n.

<[email protected]> 於 2026年4月29日週三 下午3:34寫道:

Quoted 36 lines

Hi Wake,

testcases/kernel/syscalls/file_attr/file_attr01.c static struct tcase { · line 123

Quoted 4 lines · Wake Liu

syscalls/file_attr01: Dynamically expect EOPNOTSUPP on tmpfs without xattr

testcases/kernel/syscalls/file_attr/file_attr01.c +2 -0
+     if (tc->ufattr == (struct file_attr **)(&null_ptr) && missing_tmpfs_xattr)
+             exp_errno = EOPNOTSUPP;

The override is scoped only to the null-ufattr tcase. The commit message says the kernel checks xattr support "before dereferencing the user pointer", which raises the question of whether usize validation (EINVAL/E2BIG tcases) also occurs after the support check. If so, those tcases would also return EOPNOTSUPP on tmpfs without xattr and need the same treatment. Please clarify the kernel's validation order for usize relative to the xattr support check.

Quoted 1 line

Changes in v3:

[...]

Quoted 1 line

Changes in v2:

[...]

Version changelogs should be stripped from the commit message before merging; they belong in the cover letter only.

---
Note:

Our agent completed the review of the patch. The full review can be found at: https://github.com/linux-test-project/ltp-agent/actions/runs/25096139400

The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

Signature · 5 lines
Best Regards,
Wake Liu

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
author Reviewed-by Andrea Cervesato on v3 1/1
#10 lore raw

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

In reply to Wake Liu via ltp

Hi Wake,

Quoted 10 lines

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.

Please place all Changes information after --- placeholder, we don't want to have versions history inside commit message.

I can remove it before submitting this patch.

Kind Regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#12 lore raw

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

Thank you!

Andrea Cervesato <[email protected]> 於 2026年5月19日週二 下午11:30寫道:

Quoted 7 lines

Merged, Thanks!

--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]

Signature · 5 lines
Best Regards,
Wake Liu

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