mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] fixup! proc: protect ptrace_may_access() with exec_update_lock (part 1)
@ 2026-06-04 15:58 Jann Horn
  2026-06-05  8:00 ` Christian Brauner
  0 siblings, 1 reply; 2+ messages in thread
From: Jann Horn @ 2026-06-04 15:58 UTC (permalink / raw)
  To: Alexander Viro, Christian Brauner; +Cc: Jan Kara, linux-fsdevel, linux-kernel

fix two test breakages in tools/testing/selftests/proc/read.c:

 - The test requires that readdir() on directories in procfs does not fail
   when running as root.
   Restore the previous behavior where /proc/$pid/map_files/ simply returns
   an empty directory if the process has no MM.
 - The test requires that any directory in procfs has "." and ".." entries.
   Restore the previous behavior where, even if a task has no MM,
   /proc/$pid/map_files/ still has "." and ".." entries.
   (This now differs from previous behavior in that even if the caller does
   not have permission, they still see "." and ".." entries; recreating
   the old behavior exactly would make this code unnecessarily complex.)

Reported-by: kernel test robot <oliver.sang@intel.com>
Closes: https://lore.kernel.org/oe-lkp/202606021924.b6d8a0c2-lkp@intel.com
Signed-off-by: Jann Horn <jannh@google.com>
---
 fs/proc/base.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/fs/proc/base.c b/fs/proc/base.c
index ef2f59461374..5042f14d24f3 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -2399,16 +2399,19 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx)
 	if (!task)
 		goto out;
 
+	ret = 0;
+	if (!dir_emit_dots(file, ctx))
+		goto out_put_task;
+
 	mm = mm_access(task, PTRACE_MODE_READ_FSCREDS);
 	if (IS_ERR(mm)) {
 		ret = PTR_ERR(mm);
+		/* if the task has no mm, the directory should just be empty */
+		if (ret == -ESRCH)
+			ret = 0;
 		goto out_put_task;
 	}
 
-	ret = 0;
-	if (!dir_emit_dots(file, ctx))
-		goto out_put_mm;
-
 	ret = mmap_read_lock_killable(mm);
 	if (ret)
 		goto out_put_mm;

base-commit: 5200f5f493f79f14bbdc349e402a40dfb32f23c8
prerequisite-patch-id: 0000000000000000000000000000000000000000
prerequisite-patch-id: 7c4ef33778ceb9b6e644d78c5be66b99c0c77d51
prerequisite-patch-id: bd555aff354c96a946f72e56d5d55eecc33a7b47
-- 
2.54.0.1032.g2f8565e1d1-goog


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-06-05  8:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-04 15:58 [PATCH] fixup! proc: protect ptrace_may_access() with exec_update_lock (part 1) Jann Horn
2026-06-05  8:00 ` Christian Brauner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®