2.5: PATH_MAX length fix
PATCH 1/1 2.5: PATH_MAX length fix
Linus, please apply. Kernel usage currently is confused about PATH_MAX.
D: From Andrew Josey <[email protected]> (via Chris Yeoh):
D:
D: POSIX has long had an ambiguity in the area about whether the null D: byte is included in the PATH_MAX (it basically said both ways in D: the 1990 text). The POSIX.1a draft (the amendment to POSIX.1-1990) D: and XPG4 went with including the null byte in PATH_MAX, and the D: POSIX 1003.1-200x revision (Austin Group) and Single UNIX D: Specification Version 3 also continue this way.
include/linux/limits.h +1 -1
@@ -11,7 +11,7 @@#define MAX_CANON 255/* size of the canonical input queue */ #define MAX_INPUT 255/* size of the type-ahead buffer */ #define NAME_MAX 255/* # chars in a file name */ -#define PATH_MAX 4095/* # chars in a path name */ +#define PATH_MAX 4096/* # chars in a path name including nul */ #define PIPE_BUF 4096/* # bytes in atomic write to a pipe */ #define RTSIG_MAX 32
fs/dcache.c +1 -1
@@ -1262,7 +1262,7 @@panic ("Cannot create buffer head SLAB cache" ); names_cachep =kmem_cache_create ("names_cache" , -PATH_MAX +1 ,0 , +PATH_MAX ,0 ,SLAB_HWCACHE_ALIGN ,NULL ,NULL );if (!names_cachep)panic ("Cannot create names SLAB cache" );
fs/namei.c +3 -2
@@ -99,16 +99,17 @@* kernel data space before using them.. * * POSIX.1 2.4: an empty pathname is invalid (ENOENT). +* PATH_MAX includes the nul terminator --RR. */ static inline int do_getname (const char *filename,char *page) {int retval; -unsigned long len =PATH_MAX +1 ; +unsigned long len =PATH_MAX ;if ((unsigned long ) filename >=TASK_SIZE ) {if (!segment_eq (get_fs (),KERNEL_DS ))return -EFAULT ; - }else if (TASK_SIZE - (unsigned long ) filename <PATH_MAX +1 ) + }else if (TASK_SIZE - (unsigned long ) filename <PATH_MAX ) len =TASK_SIZE - (unsigned long ) filename; retval =strncpy_from_user ((char *)page, filename, len);
scripts/mkdep.c +1 -1
@@ -218,7 +218,7 @@void add_path (const char * name) {struct path_struct *path; -char resolved_path[PATH_MAX +1 ]; +char resolved_path[PATH_MAX ];const char *name2;if (strcmp (name,"." )) {
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.
scripts/mkdep.c line 222
Quoted 8 lines
+++
working-2.4.14-pathmax/scripts/mkdep.cWed Nov 21 12:01:44 2001scripts/mkdep.c +1
-1@@ -218,7 +218,7 @@void add_path (const char * name) {struct path_struct *path; -char resolved_path[PATH_MAX +1 ]; +char resolved_path[PATH_MAX ];const char *name2;
This is a user mode application running on an unknown host. Its most definitely correct and only safe before the change
In message <[email protected]> you write:
Quoted 11 lines
Review line 222
Quoted 8 lines
+++
working-2.4.14-pathmax/scripts/mkdep.cWed Nov 21 12:01:44 2001(quoted diff) +1
-1@@ -218,7 +218,7 @@ void add_path(const char * name) { struct path_struct *path; - char resolved_path[PATH_MAX+1]; + char resolved_path[PATH_MAX]; const char *name2;This is a user mode application running on an unknown host. Its most definitely correct and only safe before the change
Ack. Thanks. Regretfully, userspace must still be careful while current (non-compliant) OSes like Linux still exist.
Thanks,
Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.
include/linux/limits.h +1 -1
@@ -11,7 +11,7 @@#define MAX_CANON 255/* size of the canonical input queue */ #define MAX_INPUT 255/* size of the type-ahead buffer */ #define NAME_MAX 255/* # chars in a file name */ -#define PATH_MAX 4095/* # chars in a path name */ +#define PATH_MAX 4096/* # chars in a path name including nul */ #define PIPE_BUF 4096/* # bytes in atomic write to a pipe */ #define RTSIG_MAX 32
fs/dcache.c +1 -1
@@ -1262,7 +1262,7 @@panic ("Cannot create buffer head SLAB cache" ); names_cachep =kmem_cache_create ("names_cache" , -PATH_MAX +1 ,0 , +PATH_MAX ,0 ,SLAB_HWCACHE_ALIGN ,NULL ,NULL );if (!names_cachep)panic ("Cannot create names SLAB cache" );
fs/namei.c +3 -2
@@ -99,16 +99,17 @@* kernel data space before using them.. * * POSIX.1 2.4: an empty pathname is invalid (ENOENT). +* PATH_MAX includes the nul terminator --RR. */ static inline int do_getname (const char *filename,char *page) {int retval; -unsigned long len =PATH_MAX +1 ; +unsigned long len =PATH_MAX ;if ((unsigned long ) filename >=TASK_SIZE ) {if (!segment_eq (get_fs (),KERNEL_DS ))return -EFAULT ; - }else if (TASK_SIZE - (unsigned long ) filename <PATH_MAX +1 ) + }else if (TASK_SIZE - (unsigned long ) filename <PATH_MAX ) len =TASK_SIZE - (unsigned long ) filename; retval =strncpy_from_user ((char *)page, filename, len);