Skip to content

Commit a235722

Browse files
Christoph HellwigGreg Ungerer
authored andcommitted
binfmt_flat: don't offset the data start
Ever since the initial commit of the binfmt_flat shared library support back in the bitkeeper days we've offset the actual in-memory .data start by one field per possible shared library, or 1 in case shared library support isn't enabled. I can't find anything in the loader that actually makes use of it, nor was it present before shared library support it. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Greg Ungerer <gerg@linux-m68k.org>
1 parent a445d98 commit a235722

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

fs/binfmt_flat.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ static int load_flat_file(struct linux_binprm *bprm,
573573
goto err;
574574
}
575575

576-
len = data_len + extra + MAX_SHARED_LIBS * sizeof(unsigned long);
576+
len = data_len + extra;
577577
len = PAGE_ALIGN(len);
578578
realdatastart = vm_mmap(NULL, 0, len,
579579
PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE, 0);
@@ -587,9 +587,7 @@ static int load_flat_file(struct linux_binprm *bprm,
587587
vm_munmap(textpos, text_len);
588588
goto err;
589589
}
590-
datapos = ALIGN(realdatastart +
591-
MAX_SHARED_LIBS * sizeof(unsigned long),
592-
FLAT_DATA_ALIGN);
590+
datapos = ALIGN(realdatastart, FLAT_DATA_ALIGN);
593591

594592
pr_debug("Allocated data+bss+stack (%u bytes): %lx\n",
595593
data_len + bss_len + stack_len, datapos);
@@ -619,7 +617,7 @@ static int load_flat_file(struct linux_binprm *bprm,
619617
memp_size = len;
620618
} else {
621619

622-
len = text_len + data_len + extra + MAX_SHARED_LIBS * sizeof(u32);
620+
len = text_len + data_len + extra;
623621
len = PAGE_ALIGN(len);
624622
textpos = vm_mmap(NULL, 0, len,
625623
PROT_READ | PROT_EXEC | PROT_WRITE, MAP_PRIVATE, 0);
@@ -634,9 +632,7 @@ static int load_flat_file(struct linux_binprm *bprm,
634632
}
635633

636634
realdatastart = textpos + ntohl(hdr->data_start);
637-
datapos = ALIGN(realdatastart +
638-
MAX_SHARED_LIBS * sizeof(u32),
639-
FLAT_DATA_ALIGN);
635+
datapos = ALIGN(realdatastart, FLAT_DATA_ALIGN);
640636

641637
reloc = (__be32 __user *)
642638
(datapos + (ntohl(hdr->reloc_start) - text_len));
@@ -653,8 +649,9 @@ static int load_flat_file(struct linux_binprm *bprm,
653649
(text_len + full_data
654650
- sizeof(struct flat_hdr)),
655651
0);
656-
memmove((void *) datapos, (void *) realdatastart,
657-
full_data);
652+
if (datapos != realdatastart)
653+
memmove((void *)datapos, (void *)realdatastart,
654+
full_data);
658655
#else
659656
/*
660657
* This is used on MMU systems mainly for testing.
@@ -710,8 +707,7 @@ static int load_flat_file(struct linux_binprm *bprm,
710707
if (IS_ERR_VALUE(result)) {
711708
ret = result;
712709
pr_err("Unable to read code+data+bss, errno %d\n", ret);
713-
vm_munmap(textpos, text_len + data_len + extra +
714-
MAX_SHARED_LIBS * sizeof(u32));
710+
vm_munmap(textpos, text_len + data_len + extra);
715711
goto err;
716712
}
717713
}

0 commit comments

Comments
 (0)