Question: I setup my environment to create a core dump of everything that crashes, however when I run an program with SUID set on a different user than the executing user it doesn't create a core dump. Any idea's why this might be? I couldn't find it anywhere on the web, I think it's some sort of security feature but I would like to have it disabled...

Problem:

```
$ cd /tmp
$ cat /etc/security/limits.conf | grep core
*     -     core     unlimited
root  -     core     unlimited

$ ls -l ohai
-rwsr-sr-x 1 root root 578988 2011-06-23 23:29 ohai

$ ./ohai
...
Floating point exception

$ sudo -i
# ./ohai
...
Floating point exception (core dumped)
# chmod -s ohai
# exit
$ ./ohai
...
Floating point exception (core dumped)

```

**Edit:**
To make it work as secure as possible I now have the following script to setup the environment:

```
mkdir -p /var/coredumps/
chown root:adm /var/coredumps/
chmod 772 /var/coredumps/

echo "kernel.core_pattern = /var/coredumps/core.%u.%e.%p" >> /etc/sysctrl.conf
echo "fs.suid_dumpable = 2" >> /etc/sysctl.conf

echo -e "*\t-\tcore\tunlimited" >> /etc/security/limits.conf
echo -e "root\t-\tcore\tunlimited" >> /etc/security/limits.conf

```

Now all that's left to do is add ACL to /var/coredumps so users can only add files and don't modify nor read them ever again. The only downsize is that I would still have a problem with chroot'ed applications which would need a `bind mount` or something like that.

Answer: 
The memory of a setuid program might (is likely to, even) contain confidential data. So the core dump would have to be readable by root only.

If the core dump is owned by root, I don't see an obvious security hole, though the kernel would have to be careful not to overwrite an existing file.

Linux disables core dumps for setxid programs. To enable them, you need to do at least the following (I haven't checked that this is sufficient):

* Enable setuid core dumps in general by setting the [`fs.suid_dumpable` sysctl](http://www.kernel.org/doc/Documentation/sysctl/fs.txt) to 2, e.g. with `echo 2 >/proc/sys/fs/suid_dumpable`. (Note: 2, not 1; 1 means “I'm debugging the system as a whole and want to remove all security”.)
* Call [`prctl(PR_SET_DUMPABLE, 1)`](http://kernel.org/doc/man-pages/online/pages/man2/prctl.2.html) from the program.
The core dump contains a copy of everything which was in memory at the time of the fault. If the program is running suid, that means it needs access to something which you, as a user, do not have access to. If the program gets that information then dumps core, you'll be able to read that privileged information.

From your example above, it appears that you're able to get a core dump when running as root or if you remove the privilege escalation.

While it might be handy (for developers only methinks) to have easy access to a coredump from a setuid program, it is a security hole, and should be left in place.