Skip to contentSkip to conversation

fs: proc: fix error return code of proc_map_files_readdir()

PATCH In review Jia-Ju Bai 3 participants 4 messages Mar 9, 2021 – Mar 10, 2021

Subsystems (2)
lore
Share & tools
lore

Jia-Ju Bai

author
#0 lore raw

PATCH 1/1 fs: proc: fix error return code of proc_map_files_readdir()

When get_task_mm() returns NULL to mm, no error return code of proc_map_files_readdir() is assigned.
To fix this bug, ret is assigned with -ENOENT in this case.

Fixes f0c3b5093add ("[readdir] convert procfs")
---
 fs/proc/base.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/proc/base.c +3 -1
index 3851bfcdba56..254cc6ac65fb 100644
@@ -2332,8 +2332,10 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx)
 		goto out_put_task;
 
 	mm = get_task_mm(task);
-	if (!mm)
+	if (!mm) {
+		ret = -ENOENT;
 		goto out_put_task;
+	}
 
 	ret = mmap_read_lock_killable(mm);
 	if (ret) {
Signature · 1 line
2.17.1
#1 lore raw
Quoted 16 lines · Jia-Ju Bai

When get_task_mm() returns NULL to mm, no error return code of proc_map_files_readdir() is assigned.
To fix this bug, ret is assigned with -ENOENT in this case.

Fixes f0c3b5093add ("[readdir] convert procfs")
---
 fs/proc/base.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/proc/base.c +0 -0
index 3851bfcdba56..254cc6ac65fb 100644

fs/proc/base.c proc_map_files_readdir(struct file *file, struct dir_context *ctx) · line 2340

Quoted 10 lines
fs/proc/base.c +3 -1
@@ -2332,8 +2332,10 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx)
 		goto out_put_task;
 
 	mm = get_task_mm(task);
-	if (!mm)
+	if (!mm) {
+		ret = -ENOENT;
 		goto out_put_task;
+	}
 
 	ret = mmap_read_lock_killable(mm);

Is there something in particular that makes you think that returning ENOENT is the correct behavior in this case? Try 'ls /proc/$pid/map_files' where pid is a kernel thread; it's an empty directory, which is probably intentional. Your patch would change reading the directory to fail with ENOENT.

- Eric

#2 lore raw
Quoted 17 lines · Eric Biggers
Quoted 16 lines · Jia-Ju Bai

When get_task_mm() returns NULL to mm, no error return code of proc_map_files_readdir() is assigned.
To fix this bug, ret is assigned with -ENOENT in this case.

fs/proc/base.c +3 -1
@@ -2332,8 +2332,10 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx)
 		goto out_put_task;
 
 	mm = get_task_mm(task);
-	if (!mm)
+	if (!mm) {
+		ret = -ENOENT;
 		goto out_put_task;
+	}
 
Quoted 6 lines

fs/proc/base.c proc_map_files_readdir(struct file *file, struct dir_context *ctx) · line 2340

Quoted 1 line
fs/proc/base.c +0 -0
 	ret = mmap_read_lock_killable(mm);

Is there something in particular that makes you think that returning ENOENT is the correct behavior in this case? Try 'ls /proc/$pid/map_files' where pid is a kernel thread; it's an empty directory, which is probably intentional. Your patch would change reading the directory to fail with ENOENT.

Yes. 0 from readdir means "no more stuff", not an error.

author
#3 lore raw
Quoted 14 lines · Alexey Dobriyan
Quoted 12 lines · Eric Biggers
Quoted 12 lines
fs/proc/base.c +3 -1
@@ -2332,8 +2332,10 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx)
  		goto out_put_task;
 
  	mm = get_task_mm(task);
-	if (!mm)
+	if (!mm) {
+		ret = -ENOENT;
  		goto out_put_task;
+	}
 
Quoted 6 lines
Quoted 5 lines

fs/proc/base.c proc_map_files_readdir(struct file *file, struct dir_context *ctx) · line 2340

Quoted 1 line
fs/proc/base.c +0 -0
  	ret = mmap_read_lock_killable(mm);

Is there something in particular that makes you think that returning ENOENT is the correct behavior in this case? Try 'ls /proc/$pid/map_files' where pid is a kernel thread; it's an empty directory, which is probably intentional. Your patch would change reading the directory to fail with ENOENT.

Yes. 0 from readdir means "no more stuff", not an error.

Thanks for your reply and explanation.
I am sorry for the false report...

Best wishes,
Jia-Ju Bai