binfmt_flat: Fix corruption when not offsetting data start
authorKees Cook <kees@kernel.org>
Wed, 7 Aug 2024 19:51:23 +0000 (12:51 -0700)
committerKees Cook <kees@kernel.org>
Sat, 10 Aug 2024 03:19:00 +0000 (20:19 -0700)
commit3eb3cd5992f7a0c37edc8d05b4c38c98758d8671
tree3a6abe5c5811606ceb283c9bbe14d0c9a7cb1654
parentde9c2c66ad8e787abec7c9d7eff4f8c3cdd28aed
binfmt_flat: Fix corruption when not offsetting data start

Commit 04d82a6d0881 ("binfmt_flat: allow not offsetting data start")
introduced a RISC-V specific variant of the FLAT format which does
not allocate any space for the (obsolete) array of shared library
pointers. However, it did not disable the code which initializes the
array, resulting in the corruption of sizeof(long) bytes before the DATA
segment, generally the end of the TEXT segment.

Introduce MAX_SHARED_LIBS_UPDATE which depends on the state of
CONFIG_BINFMT_FLAT_NO_DATA_START_OFFSET to guard the initialization of
the shared library pointer region so that it will only be initialized
if space is reserved for it.

Fixes: 04d82a6d0881 ("binfmt_flat: allow not offsetting data start")
Co-developed-by: Stefan O'Rear <sorear@fastmail.com>
Signed-off-by: Stefan O'Rear <sorear@fastmail.com>
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Acked-by: Greg Ungerer <gerg@linux-m68k.org>
Link: https://lore.kernel.org/r/20240807195119.it.782-kees@kernel.org
Signed-off-by: Kees Cook <kees@kernel.org>
fs/binfmt_flat.c