Skip to content

Commit

Permalink
syscalls/rename10: Test long file name too
Browse files Browse the repository at this point in the history
Commit 5b706c4 ("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
5b706c4), 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 <[email protected]>
Signed-off-by: Kevin Brodsky <[email protected]>
Reviewed-by: Cyril Hrubis <[email protected]>
Reviewed-by: Petr Vorel <[email protected]>
  • Loading branch information
kevin-brodsky-arm authored and metan-ucw committed Oct 26, 2023
1 parent 584b87a commit 3967218
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions testcases/kernel/syscalls/rename/rename10.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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 = {
Expand Down

0 comments on commit 3967218

Please sign in to comment.