[LTP] [PATCH 3/3] open13: Verify that dup() will preserve O_PATH flag

Martin Doucha mdoucha@suse.cz
Tue Jun 24 17:19:16 CEST 2025


Verify that calling dup() on a file descriptor opened with O_PATH
will return another file descriptor that is not usable for standard
I/O operations.

Signed-off-by: Martin Doucha <mdoucha@suse.cz>
---
 testcases/kernel/syscalls/open/open13.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/testcases/kernel/syscalls/open/open13.c b/testcases/kernel/syscalls/open/open13.c
index e30e99ec3..0ac501913 100644
--- a/testcases/kernel/syscalls/open/open13.c
+++ b/testcases/kernel/syscalls/open/open13.c
@@ -31,7 +31,7 @@
 
 #define TESTFILE	"testfile"
 
-static int path_fd = -1;
+static int path_fd = -1, dup_fd = -1;
 
 static int verify_read(int fd);
 static int verify_write(int fd);
@@ -64,6 +64,7 @@ static void setup(void)
 	path_fd = SAFE_OPEN(TESTFILE, O_RDWR | O_CREAT, 0644);
 	SAFE_CLOSE(path_fd);
 	path_fd = SAFE_OPEN(TESTFILE, O_PATH);
+	dup_fd = SAFE_DUP(path_fd);
 }
 
 static void run(void)
@@ -71,8 +72,10 @@ static void run(void)
 	int i;
 
 	for (i = 0; testcases[i].func; i++) {
-		TST_EXP_FAIL(testcases[i].func(path_fd), EBADF, "%s()",
-			testcases[i].name);
+		TST_EXP_FAIL(testcases[i].func(path_fd), EBADF,
+			"%s() on original FD", testcases[i].name);
+		TST_EXP_FAIL(testcases[i].func(dup_fd), EBADF,
+			"%s() on duplicated FD", testcases[i].name);
 	}
 }
 
@@ -129,6 +132,9 @@ static void cleanup(void)
 {
 	if (path_fd >= 0)
 		SAFE_CLOSE(path_fd);
+
+	if (dup_fd >= 0)
+		SAFE_CLOSE(dup_fd);
 }
 
 static struct tst_test test = {
-- 
2.49.0



More information about the ltp mailing list