[LTP] [PATCH] syscalls/file_attr01: Allow EOPNOTSUPP when attributes is NULL

Wake Liu wakel@google.com
Fri Mar 20 08:57:33 CET 2026


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.

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

diff --git a/testcases/kernel/syscalls/file_attr/file_attr01.c b/testcases/kernel/syscalls/file_attr/file_attr01.c
index c9c9288a1..02aea66a6 100644
--- a/testcases/kernel/syscalls/file_attr/file_attr01.c
+++ b/testcases/kernel/syscalls/file_attr/file_attr01.c
@@ -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);
 	}
 }
-- 
2.53.0.983.g0bb29b3bc5-goog



More information about the ltp mailing list