fs: proc: Clarify warnings for invalid proc dir names
Subsystems (2)
PATCH 1/1 fs: proc: Clarify warnings for invalid proc dir names
When one attempts to create a directory in /proc with an invalid name, such as one in a subdirectory that doesn't exist, one with a name beyond 256 characters, or a reserved name such as '.' or '..', the kernel throws a warning message that looks like this:
[ 7913.252558] name 'invalid_name'
This warning message is nearly the same for all invalid cases, including the removal of a nonexistent directory. This patch clarifies the warning message and differentiates the invalid creation/removal cases so as to allow the user to more quickly understand their mistake.
--- fs/proc/generic.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
fs/proc/generic.c +6 -6
@@ -173,7 +173,7 @@ static int __xlate_proc_name(const char *name, struct proc_dir_entry **ret, len = next - cp; de =pde_subdir_find (de, cp, len);if (!de) { -WARN (1 ,"name '%s'\n" , name); +WARN (1 ,"invalid proc dir name '%s'\n" , name);return -ENOENT ; } cp += len +1 ;
@@ -386,15 +386,15 @@ static struct proc_dir_entry *__proc_create(struct proc_dir_entry **parent, qstr.name = fn; qstr.len =strlen (fn);if (qstr.len ==0 || qstr.len >=256 ) { -WARN (1 ,"name len %u\n" , qstr.len); +WARN (1 ,"invalid proc dir name len %u\n" , qstr.len);return NULL ; }if (qstr.len ==1 && fn[0 ] =='.' ) { -WARN (1 ,"name '.'\n" ); +WARN (1 ,"invalid proc dir name '.'\n" );return NULL ; }if (qstr.len ==2 && fn[0 ] =='.' && fn[1 ] =='.' ) { -WARN (1 ,"name '..'\n" ); +WARN (1 ,"invalid proc dir name '..'\n" );return NULL ; }if (*parent == &proc_root &&name_to_int (&qstr) != ~0U ) {
@@ -402,7 +402,7 @@ static struct proc_dir_entry *__proc_create(struct proc_dir_entry **parent,return NULL ; }if (is_empty_pde (*parent)) { -WARN (1 ,"attempt to add to permanently empty directory" ); +WARN (1 ,"attempt to add to permanently empty directory in proc" );return NULL ; }
@@ -670,7 +670,7 @@ void remove_proc_entry(const char *name, struct proc_dir_entry *parent)rb_erase (&de->subdir_node, &parent->subdir);write_unlock (&proc_subdir_lock);if (!de) { -WARN (1 ,"name '%s'\n" , name); +WARN (1 ,"unable to remove nonexistent proc dir '%s'\n" , name);return ; }
Signature · 1 line
2.23.0
Quoted 6 lines · Joel Savitz
When one attempts to create a directory in /proc with an invalid name, such as one in a subdirectory that doesn't exist, one with a name beyond 256 characters, or a reserved name such as '.' or '..', the kernel throws a warning message that looks like this:
[ 7913.252558] name 'invalid_name'
Yes, the important part is filename:line which uniquely identifies the issue.
fs/proc/generic.c static int __xlate_proc_name(const char *name, struct proc_dir_entry **ret, · line 176
Quoted 13 lines
This warning message is nearly the same for all invalid cases, including the removal of a nonexistent directory. This patch clarifies the warning message and differentiates the invalid creation/removal cases so as to allow the user to more quickly understand their mistake.
fs/proc/generic.c +1
-1@@ -173,7 +173,7 @@ static int __xlate_proc_name(const char *name, struct proc_dir_entry **ret, len = next - cp; de =pde_subdir_find (de, cp, len);if (!de) { -WARN (1 ,"name '%s'\n" , name); +WARN (1 ,"invalid proc dir name '%s'\n" , name);
Wrong string anyway, this is nonexistent name, directory or not.
Quoted 16 lines
fs/proc/generic.c +1
-1-WARN (1 ,"name len %u\n" , qstr.len); +WARN (1 ,"invalid proc dir name len %u\n" , qstr.len);return NULL ; }fs/proc/generic.c +2
-2if (qstr.len ==1 && fn[0 ] =='.' ) { -WARN (1 ,"name '.'\n" ); +WARN (1 ,"invalid proc dir name '.'\n" );return NULL ; }if (qstr.len ==2 && fn[0 ] =='.' && fn[1 ] =='.' ) { -WARN (1 ,"name '..'\n" ); +WARN (1 ,"invalid proc dir name '..'\n" );return NULL ; }if (*parent == &proc_root &&name_to_int (&qstr) != ~0U ) {
fs/proc/generic.c static struct proc_dir_entry *__proc_create(struct proc_dir_entry **parent, · line 405
Quoted 5 lines
fs/proc/generic.c +1
-1@@ -402,7 +402,7 @@ static struct proc_dir_entry *__proc_create(struct proc_dir_entry **parent,return NULL ; }if (is_empty_pde (*parent)) { -WARN (1 ,"attempt to add to permanently empty directory" ); +WARN (1 ,"attempt to add to permanently empty directory in proc" );
"proc" will be spilled over all backtrace.
fs/proc/generic.c void remove_proc_entry(const char *name, struct proc_dir_entry *parent) · line 673
Quoted 6 lines
fs/proc/generic.c +1
-1@@ -670,7 +670,7 @@ void remove_proc_entry(const char *name, struct proc_dir_entry *parent)rb_erase (&de->subdir_node, &parent->subdir);write_unlock (&proc_subdir_lock);if (!de) { -WARN (1 ,"name '%s'\n" , name); +WARN (1 ,"unable to remove nonexistent proc dir '%s'\n" , name);
I'm not sure if such chatty strings are necessary.