[LTP] [PATCH] safe_open: Add missing mode from some calls

Teo Couprie Diaz teo.coupriediaz@arm.com
Thu Mar 23 17:05:07 CET 2023


safe_open expects a mode when creating or using a temporary file, which is
read via a variadic argument.
Add the mode when it is missing for a few tests.

Signed-off-by: Teo Couprie Diaz <teo.coupriediaz@arm.com>
---
This was detected on Morello[0] as the missing mode triggered an access
outside of capability bounds when processing the variadic argument.

CI Build: https://github.com/Teo-CD/ltp/actions/runs/4502201455

[0]: https://www.morello-project.org/

 .../kernel/syscalls/name_to_handle_at/name_to_handle_at01.c     | 2 +-
 .../kernel/syscalls/open_by_handle_at/open_by_handle_at01.c     | 2 +-
 testcases/kernel/syscalls/utimensat/utimensat01.c               | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/testcases/kernel/syscalls/name_to_handle_at/name_to_handle_at01.c b/testcases/kernel/syscalls/name_to_handle_at/name_to_handle_at01.c
index 9677b06719e3..6535fdf5c0ed 100644
--- a/testcases/kernel/syscalls/name_to_handle_at/name_to_handle_at01.c
+++ b/testcases/kernel/syscalls/name_to_handle_at/name_to_handle_at01.c
@@ -72,7 +72,7 @@ static void setup(void)
 	dir_fd = SAFE_OPEN(TEST_DIR, O_DIRECTORY);
 	SAFE_CHDIR(TEST_DIR);
 	SAFE_TOUCH(TEST_FILE, 0600, NULL);
-	file_fd = SAFE_OPEN("foo_file", O_RDWR | O_CREAT);
+	file_fd = SAFE_OPEN("foo_file", O_RDWR | O_CREAT, 0600);
 	fhp = allocate_file_handle(AT_FDCWD, TEST_FILE);
 }
 
diff --git a/testcases/kernel/syscalls/open_by_handle_at/open_by_handle_at01.c b/testcases/kernel/syscalls/open_by_handle_at/open_by_handle_at01.c
index 76be720cad78..6171229f0b6f 100644
--- a/testcases/kernel/syscalls/open_by_handle_at/open_by_handle_at01.c
+++ b/testcases/kernel/syscalls/open_by_handle_at/open_by_handle_at01.c
@@ -55,7 +55,7 @@ static void setup(void)
 	dir_fd = SAFE_OPEN(TEST_DIR, O_DIRECTORY);
 	SAFE_CHDIR(TEST_DIR);
 	SAFE_TOUCH(TEST_FILE, 0600, NULL);
-	file_fd = SAFE_OPEN("foo_file", O_RDWR | O_CREAT);
+	file_fd = SAFE_OPEN("foo_file", O_RDWR | O_CREAT, 0600);
 
 	f_fhp = allocate_file_handle(AT_FDCWD, TEST_FILE);
 	d_fhp = allocate_file_handle(AT_FDCWD, TEST_FILE);
diff --git a/testcases/kernel/syscalls/utimensat/utimensat01.c b/testcases/kernel/syscalls/utimensat/utimensat01.c
index ac267e7d9f84..a2897b42288d 100644
--- a/testcases/kernel/syscalls/utimensat/utimensat01.c
+++ b/testcases/kernel/syscalls/utimensat/utimensat01.c
@@ -233,7 +233,7 @@ static void run(unsigned int i)
 		dfd = SAFE_OPEN(TEST_DIR, tc->oflags);
 
 	if (tc->pathname) {
-		fd = SAFE_OPEN(tc->pathname, O_WRONLY | O_CREAT);
+		fd = SAFE_OPEN(tc->pathname, O_WRONLY | O_CREAT, 0200);
 		pathname = tc->pathname;
 		SAFE_CHMOD(tc->pathname, tc->mode);
 		reset_time(pathname, dfd, tc->flags, i);
-- 
2.34.1



More information about the ltp mailing list