Skip to contentSkip to conversation

fixup! proc: protect ptrace_may_access() with exec_update_lock (part 1)

PATCH Applied Jann Horn 2 participants 2 messages Jun 4 – Jun 5

Subsystems (2)
lore
Share & tools
lore

Jann Horn

author
#0 lore raw

PATCH 1/1 fixup! proc: protect ptrace_may_access() with exec_update_lock (part 1)

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.)

---
 fs/proc/base.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
fs/proc/base.c +7 -4
index ef2f59461374..5042f14d24f3 100644
@@ -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

Signature · 1 line
2.54.0.1032.g2f8565e1d1-goog
maintainer Applied
#1 lore raw
Quoted 13 lines · Jann Horn

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.)

Quoted 1 line

[...]

Applied to the vfs-7.2.procfs branch of the vfs/vfs.git tree. Patches in the vfs-7.2.procfs branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs-7.2.procfs

[1/1] fixup! proc: protect ptrace_may_access() with exec_update_lock (part 1)

      https://git.kernel.org/vfs/vfs/c/883d2f3ec72d