[LTP] [PATCH 3/3] Provide a PATH_MAX-long buffer when expecting ENAMETOOLONG

Kevin Brodsky kevin.brodsky@arm.com
Mon Oct 23 15:56:47 CEST 2023


A number of tests check that syscalls manipulating paths return
-ENAMETOOLONG when the specified path is longer than allowed. There
are actually two ways this error can be triggered:

1. If the given string is longer than PATH_MAX, i.e. 4096 as far as
   the kernel is concerned, then the getname() helper will fail and
   the kernel will return -ENAMETOOLONG right away.

2. If the string fits in PATH_MAX, but the filesystem rejects the
   path name, for instance because one of its components is longer
   than the support file name length (e.g. 255 for ext4).

At the moment, we always fail because of 2. since we set PATH_MAX to
1024 in LTP, and in fact we sometimes use NAME_MAX as buffer length
instead (which is shorter). Thus what actually happens is that the
kernel overreads the provided buffer and finds some zero before
hitting the "real" PATH_MAX limit (4096).

We should clearly avoid such overreads. Having the syscalls fail
right away by hitting 1. is the safer option. To do so, we obtain
the value of PATH_MAX directly from the appropriate kernel header,
and ensure it is used where relevant. This affects at least the
following tests:

- rename10
- symlink03

Signed-off-by: Kevin Brodsky <kevin.brodsky@arm.com>
---
 include/old/usctest.h                       | 12 ++----------
 testcases/kernel/syscalls/rename/rename10.c |  2 +-
 2 files changed, 3 insertions(+), 11 deletions(-)

diff --git a/include/old/usctest.h b/include/old/usctest.h
index 9b9446d70a1e..2d46c4045111 100644
--- a/include/old/usctest.h
+++ b/include/old/usctest.h
@@ -34,16 +34,8 @@
 #ifndef __USCTEST_H__
 #define __USCTEST_H__
 
-/*
- * Ensure that PATH_MAX is defined
- */
-#ifndef PATH_MAX
-#ifdef MAXPATHLEN
-#define PATH_MAX  MAXPATHLEN
-#else
-#define PATH_MAX  1024
-#endif
-#endif
+/* For PATH_MAX */
+#include <linux/limits.h>
 
 /***********************************************************************
  * The following globals are defined in parse_opts.c but must be
diff --git a/testcases/kernel/syscalls/rename/rename10.c b/testcases/kernel/syscalls/rename/rename10.c
index 444f65366576..3eab4be0f913 100644
--- a/testcases/kernel/syscalls/rename/rename10.c
+++ b/testcases/kernel/syscalls/rename/rename10.c
@@ -18,7 +18,7 @@
 #define MNT_POINT "mntpoint"
 #define TEMP_FILE "tmpfile"
 
-static char long_path[NAME_MAX + 1] = {[0 ... NAME_MAX] = 'a'};
+static char long_path[PATH_MAX + 1] = {[0 ... PATH_MAX] = 'a'};
 
 static void setup(void)
 {
-- 
2.38.1



More information about the ltp mailing list