[LTP] [PATCH] syscalls/rename10: Test long file name too

Kevin Brodsky kevin.brodsky@arm.com
Wed Oct 25 17:33:17 CEST 2023


Commit 5b706c4ee104 ("Provide a PATH_MAX-long buffer when expecting
ENAMETOOLONG") modified rename10 in order to prevent out-of-bound
uaccess. However, in so doing, it changed the failure mode of the
rename() syscall: instead of the path being rejected by the
filesystem, due to the file name being too long, it is now rejected
directly by the syscall handler as the path itself is too long.

This patch adds a new long_name string that triggers the "file name
too long" failure mode, while preserving the "path too long" failure
mode for long_path. Unlike the original buffer (before commit
5b706c4ee104), no out-of-bound uaccess occurs when passing long_name
to rename(), as long_name is a null-terminated string that is short
enough to be interpreted as a valid path.

Suggested-by: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Kevin Brodsky <kevin.brodsky@arm.com>
---

CI run: https://github.com/kevin-brodsky-arm/ltp/actions/runs/6642693217

See also: https://lore.kernel.org/ltp/20231023135647.2157030-1-kevin.brodsky@arm.com/T/#m3d1649d695faa4426f141bb1beeb3b4762ca5876

 testcases/kernel/syscalls/rename/rename10.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/testcases/kernel/syscalls/rename/rename10.c b/testcases/kernel/syscalls/rename/rename10.c
index 3eab4be0f913..5b5f79073e6b 100644
--- a/testcases/kernel/syscalls/rename/rename10.c
+++ b/testcases/kernel/syscalls/rename/rename10.c
@@ -18,7 +18,13 @@
 #define MNT_POINT "mntpoint"
 #define TEMP_FILE "tmpfile"
 
+/* Path longer than PATH_MAX: fails the syscall right away (getname() fails) */
 static char long_path[PATH_MAX + 1] = {[0 ... PATH_MAX] = 'a'};
+/*
+ * Path fitting in PATH_MAX, but with an excessively long file name: rejected
+ * by the underlying filesystem
+ */
+static char long_name[PATH_MAX] = {[0 ... PATH_MAX - 2] = 'a', [PATH_MAX - 1] = '\0'};
 
 static void setup(void)
 {
@@ -30,6 +36,8 @@ static void run(void)
 {
 	TST_EXP_FAIL(rename(TEMP_FILE, long_path),
 				ENAMETOOLONG);
+	TST_EXP_FAIL(rename(TEMP_FILE, long_name),
+				ENAMETOOLONG);
 }
 
 static struct tst_test test = {
-- 
2.38.1



More information about the ltp mailing list