Description of problem: I trace a process using ptrace and the PTRACE_O_TRACEEXIT option. When I get the PTRACE_EVENT_EXIT notification for the process I examine its memory mappings by reading /proc/<pid>/maps. This works on vanilla Linux kernels. On the Fedora kernel this works if the process exited normally, but if it was killed by a signal I get EACCES when trying to open /proc/<pid>/maps. I guess this is undocumented behaviour, but it would be good to know if I should expect a fix or work around the problem somehow. I am running the x86_64 version of the kernel on a Core 2 T7200. Version-Release number of selected component (if applicable): kernel-2.6.22.4-65.fc7 How reproducible: Every time. Steps to Reproduce: 1. Compile and run the attached test case. Actual results: Test case fails to open /proc/<pid>/maps. Expected results: Test case prints the contents of /proc/<pid>/maps.
Created attachment 192401 [details] Test case.
Verified on: kernel-2.6.23-0.195.rc7.git3.fc8.x86_64
(It was a verification it is still buggy there in Comment 2.) You must not be root to make the test fail on the Fedora kernel. (The test really works even for non-root on the upstream kernels.)
This problem is not really related to ptrace. It's a Fedora difference that AFAICT is more or less intentional, but at any rate I am not the sole person to ask about it. The issue is that Fedora makes maps et al not world-readable. In all kernels, the core dump code (even with ulimit -c 0) clears the process's (mm's) "dumpable" flag. Once this flag is clear, the /proc/pid file access all acts with the files owned by root rather than by the euid. Since maps has mode 400 in Fedora (444 upstream), you can't read it when it belongs to root, so you can no longer open your own child's /proc files for reading. This is probably an unintended confluence of factors motivated by different things. The 400 vs 444 is an intended security change in Fedora. The permission meaning of dumpable=0 is intended for keeping secure things that changed uids or something like that--a privileged daemon that switches to your uid does not dump a core file owned by you. The core dump code clearing dumpable is probably part of some necessary synchronization plan or something. All added together, they have the effect of denying a permission noone ever intended to deny (/proc files of a task that is in the process of dying by a core signal)--but this can only be seen in non-racy conditions when you are either looking at a zombie (which has no such info as e.g. maps left to show anyway) or are looking at a PTRACE_EVENT_EXIT stop.
linux-2.6-execshield.patch is what changes the fs/proc/base.c permissions to cause this.
Created attachment 223861 [details] enhanced test case This version of the test case displays the uid/mode of the proc file, which demonstrates what's going on in different kernels clearly.
http://lkml.org/lkml/2007/10/11/16
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=00ec99da43a7c2aed46c6595aa271b84bb1b1462 A variant of my fix went in upstream today. This should hit rawhide in the fullness of time. It would be trivial to backport to 2.6.23 if this is worth bothering with fixing early for Fedora [678].
Both cases: event-exit-proc-environ event-exit-proc-maps verified as fixed on Fedora 8: kernel-2.6.24.3-12.fc8.x86_64 (F8) kernel-2.6.25-0.101.rc4.git3.fc9.x86_64 (Rawhide)