Skip to content

Commit 3eb3cd5

Browse files
committed
binfmt_flat: Fix corruption when not offsetting data start
Commit 04d82a6 ("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: 04d82a6 ("binfmt_flat: allow not offsetting data start") Co-developed-by: Stefan O'Rear <[email protected]> Signed-off-by: Stefan O'Rear <[email protected]> Reviewed-by: Damien Le Moal <[email protected]> Acked-by: Greg Ungerer <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Kees Cook <[email protected]>
1 parent de9c2c6 commit 3eb3cd5

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

fs/binfmt_flat.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,10 @@
7272

7373
#ifdef CONFIG_BINFMT_FLAT_NO_DATA_START_OFFSET
7474
#define DATA_START_OFFSET_WORDS (0)
75+
#define MAX_SHARED_LIBS_UPDATE (0)
7576
#else
7677
#define DATA_START_OFFSET_WORDS (MAX_SHARED_LIBS)
78+
#define MAX_SHARED_LIBS_UPDATE (MAX_SHARED_LIBS)
7779
#endif
7880

7981
struct lib_info {
@@ -880,7 +882,7 @@ static int load_flat_binary(struct linux_binprm *bprm)
880882
return res;
881883

882884
/* Update data segment pointers for all libraries */
883-
for (i = 0; i < MAX_SHARED_LIBS; i++) {
885+
for (i = 0; i < MAX_SHARED_LIBS_UPDATE; i++) {
884886
if (!libinfo.lib_list[i].loaded)
885887
continue;
886888
for (j = 0; j < MAX_SHARED_LIBS; j++) {

0 commit comments

Comments
 (0)