coredump: do not allow user to access coredumps with changed uid/gid/capabilities
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 28 Nov 2022 11:12:55 +0000 (12:12 +0100)
committerLuca Boccassi <bluca@debian.org>
Mon, 27 May 2024 13:02:03 +0000 (14:02 +0100)
commitc6d6c9fb52ed4c0b49a2ef306ded03bf6d467fce
tree5a099dbb492b4121f53e138ae754c350bca91343
parentb8b683d1709611d07f3bfb9813cc6d9686f99b56
coredump: do not allow user to access coredumps with changed uid/gid/capabilities

When the user starts a program which elevates its permissions via setuid,
setgid, or capabilities set on the file, it may access additional information
which would then be visible in the coredump. We shouldn't make the the coredump
visible to the user in such cases.

Reported-by: Matthias Gerstner <mgerstner@suse.de>
This reads the /proc/<pid>/auxv file and attaches it to the process metadata as
PROC_AUXV. Before the coredump is submitted, it is parsed and if either
at_secure was set (which the kernel will do for processes that are setuid,
setgid, or setcap), or if the effective uid/gid don't match uid/gid, the file
is not made accessible to the user. If we can't access this data, we assume the
file should not be made accessible either. In principle we could also access
the auxv data from a note in the core file, but that is much more complex and
it seems better to use the stand-alone file that is provided by the kernel.

Attaching auxv is both convient for this patch (because this way it's passed
between the stages along with other fields), but I think it makes sense to save
it in general.

We use the information early in the core file to figure out if the program was
32-bit or 64-bit and its endianness. This way we don't need heuristics to guess
whether the format of the auxv structure. This test might reject some cases on
fringe architecutes. But the impact would be limited: we just won't grant the
user permissions to view the coredump file. If people report that we're missing
some cases, we can always enhance this to support more architectures.

I tested auxv parsing on amd64, 32-bit program on amd64, arm64, arm32, and
ppc64el, but not the whole coredump handling.

(cherry picked from commit 3e4d0f6cf99f8677edd6a237382a65bfe758de03)
(cherry picked from commit 9b75a3d0502d6741c8ecb7175794345f8eb3827c)
(cherry picked from commit efca5283dc791a07171f80eef84e14fdb58fad57)
(cherry picked from commit 1d5e0e9910500f3c3584485f77bfc35e601036e3)
(cherry picked from commit 8215e1527d859e77dd1378fd7e42bbd32130edb3)
(cherry picked from commit 786df410b1cb3a2294c9a5d118c958525e7439e6)

Gbp-Pq: Name coredump-do-not-allow-user-to-access-coredumps-with-chang.patch
src/basic/io-util.h
src/coredump/coredump.c