Skip to content

RFC coredump: mitigate privilege escalation of process coredump

Wander Lairson Costa linux-fsdevel lkml 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 RFC Latest4 patches 2 repliesIn review
  2. v1 RFC4 patches 0 repliesSuperseded

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4exec: add a flag indicating if an exec file is a suid/sgidfs/exec.c include/linux/binfmts.h+7 -10 replies
2/4process: add the PF_SUID flagfs/exec.c include/linux/sched.h kernel/fork.c+7 -00 replies
3/4coredump: mitigate privilege escalation of process coredumpfs/coredump.c+15 -00 replies
4/4exec: only set the suid flag if the current proc isn't rootfs/exec.c+5 -10 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH RFC v2 0/4] coredump: mitigate privilege escalation of process coredump

v2
==

Patch 02 conflicted with commit 92307383082d("coredump: Don't perform any cleanups before dumping core") which I didn't have in my tree. V2 just changes the hunk

+#define PF_SUID 0x00000008

To

+#define PF_SUID 0x01000000

To merge cleanly. Other than that, it is the same patch as v1.

v1
==

A set-uid executable might be a vector to privilege escalation if the system configures the coredump file name pattern as a relative directory destiny. The full description of the vulnerability and a demonstration of how we can exploit it can be found at [1].

This patch series adds a PF_SUID flag to the process in execve if it is set-[ug]id binary and elevates the new image's privileges.

In the do_coredump function, we check if:

1) We have the SUID_FLAG set
2) We have CAP_SYS_ADMIN (the process might have decreased its privileges)
3) The current directory is owned by root (the current code already checks for core_pattern being a relative path).
4) non-privileged users don't have permission to write to the current directory.

If all four conditions match, we set the need_suid_safe flag.

An alternative implementation (and more elegant IMO) would be saving the fsuid and fsgid of the process in the task_struct before loading the new image to the memory. But this approach would add eight bytes to all task_struct instances where only a tiny fraction of the processes need it and under a configuration that not all (most?) distributions don't adopt by default.

Wander Lairson Costa (4):
exec: add a flag indicating if an exec file is a suid/sgid
process: add the PF_SUID flag
coredump: mitigate privilege escalation of process coredump
exec: only set the suid flag if the current proc isn't root

 fs/coredump.c           | 15 +++++++++++++++
 fs/exec.c               | 10 ++++++++++
 include/linux/binfmts.h |  6 +++++-
 include/linux/sched.h   |  1 +
 kernel/fork.c           |  2 ++
 5 files changed, 33 insertions(+), 1 deletion(-)
Signature · 1 line
2.27.0