Skip to content

Commit 70578ff

Browse files
ebiedermkees
authored andcommitted
binfmt_flat: Remove shared library support
In a recent discussion[1] it was reported that the binfmt_flat library support was only ever used on m68k and even on m68k has not been used in a very long time. The structure of binfmt_flat is different from all of the other binfmt implementations because of this shared library support and it made life and code review more effort when I refactored the code in fs/exec.c. Since in practice the code is dead remove the binfmt_flat shared library support and make maintenance of the code easier. [1] https://lkml.kernel.org/r/81788b56-5b15-7308-38c7-c7f2502c4e15@linux-m68k.org Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com> Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com> Acked-by: Vladimir Murzin <vladimir.murzin@arm.com> # ARM Tested-by: Patrice Chotard <patrice.chotard@foss.st.com> Signed-off-by: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/r/87levzzts4.fsf_-_@email.froward.int.ebiederm.org
1 parent 8d00526 commit 70578ff

File tree

9 files changed

+40
-163
lines changed

9 files changed

+40
-163
lines changed

arch/arm/configs/lpc18xx_defconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ CONFIG_ARM_APPENDED_DTB=y
3030
# CONFIG_BLK_DEV_BSG is not set
3131
CONFIG_BINFMT_FLAT=y
3232
CONFIG_BINFMT_ZFLAT=y
33-
CONFIG_BINFMT_SHARED_FLAT=y
3433
# CONFIG_COREDUMP is not set
3534
CONFIG_NET=y
3635
CONFIG_PACKET=y

arch/arm/configs/mps2_defconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ CONFIG_PREEMPT_VOLUNTARY=y
2323
CONFIG_ZBOOT_ROM_TEXT=0x0
2424
CONFIG_ZBOOT_ROM_BSS=0x0
2525
CONFIG_BINFMT_FLAT=y
26-
CONFIG_BINFMT_SHARED_FLAT=y
2726
# CONFIG_COREDUMP is not set
2827
# CONFIG_SUSPEND is not set
2928
CONFIG_NET=y

arch/arm/configs/stm32_defconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ CONFIG_ZBOOT_ROM_BSS=0x0
2828
CONFIG_XIP_KERNEL=y
2929
CONFIG_XIP_PHYS_ADDR=0x08008000
3030
CONFIG_BINFMT_FLAT=y
31-
CONFIG_BINFMT_SHARED_FLAT=y
3231
# CONFIG_COREDUMP is not set
3332
CONFIG_DEVTMPFS=y
3433
CONFIG_DEVTMPFS_MOUNT=y

arch/arm/configs/vf610m4_defconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ CONFIG_XIP_KERNEL=y
1818
CONFIG_XIP_PHYS_ADDR=0x0f000080
1919
CONFIG_BINFMT_FLAT=y
2020
CONFIG_BINFMT_ZFLAT=y
21-
CONFIG_BINFMT_SHARED_FLAT=y
2221
# CONFIG_SUSPEND is not set
2322
# CONFIG_UEVENT_HELPER is not set
2423
# CONFIG_STANDALONE is not set

arch/sh/configs/rsk7201_defconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ CONFIG_CMDLINE_OVERWRITE=y
2525
CONFIG_CMDLINE="console=ttySC0,115200 earlyprintk=serial ignore_loglevel"
2626
CONFIG_BINFMT_FLAT=y
2727
CONFIG_BINFMT_ZFLAT=y
28-
CONFIG_BINFMT_SHARED_FLAT=y
2928
CONFIG_PM=y
3029
CONFIG_CPU_IDLE=y
3130
# CONFIG_STANDALONE is not set

arch/sh/configs/rsk7203_defconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ CONFIG_CMDLINE_OVERWRITE=y
3030
CONFIG_CMDLINE="console=ttySC0,115200 earlyprintk=serial ignore_loglevel"
3131
CONFIG_BINFMT_FLAT=y
3232
CONFIG_BINFMT_ZFLAT=y
33-
CONFIG_BINFMT_SHARED_FLAT=y
3433
CONFIG_PM=y
3534
CONFIG_CPU_IDLE=y
3635
CONFIG_NET=y

arch/sh/configs/se7206_defconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ CONFIG_CMDLINE_OVERWRITE=y
4040
CONFIG_CMDLINE="console=ttySC3,115200 ignore_loglevel earlyprintk=serial"
4141
CONFIG_BINFMT_FLAT=y
4242
CONFIG_BINFMT_ZFLAT=y
43-
CONFIG_BINFMT_SHARED_FLAT=y
4443
CONFIG_BINFMT_MISC=y
4544
CONFIG_NET=y
4645
CONFIG_PACKET=y

fs/Kconfig.binfmt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,6 @@ config BINFMT_ZFLAT
142142
help
143143
Support FLAT format compressed binaries
144144

145-
config BINFMT_SHARED_FLAT
146-
bool "Enable shared FLAT support"
147-
depends on BINFMT_FLAT
148-
help
149-
Support FLAT shared libraries
150-
151145
config HAVE_AOUT
152146
def_bool n
153147

fs/binfmt_flat.c

Lines changed: 40 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,7 @@
6868
#define RELOC_FAILED 0xff00ff01 /* Relocation incorrect somewhere */
6969
#define UNLOADED_LIB 0x7ff000ff /* Placeholder for unused library */
7070

71-
#ifdef CONFIG_BINFMT_SHARED_FLAT
72-
#define MAX_SHARED_LIBS (4)
73-
#else
74-
#define MAX_SHARED_LIBS (1)
75-
#endif
71+
#define MAX_SHARED_LIBS (1)
7672

7773
#ifdef CONFIG_BINFMT_FLAT_NO_DATA_START_OFFSET
7874
#define DATA_START_OFFSET_WORDS (0)
@@ -92,10 +88,6 @@ struct lib_info {
9288
} lib_list[MAX_SHARED_LIBS];
9389
};
9490

95-
#ifdef CONFIG_BINFMT_SHARED_FLAT
96-
static int load_flat_shared_library(int id, struct lib_info *p);
97-
#endif
98-
9991
static int load_flat_binary(struct linux_binprm *);
10092

10193
static struct linux_binfmt flat_format = {
@@ -307,51 +299,18 @@ static int decompress_exec(struct linux_binprm *bprm, loff_t fpos, char *dst,
307299
/****************************************************************************/
308300

309301
static unsigned long
310-
calc_reloc(unsigned long r, struct lib_info *p, int curid, int internalp)
302+
calc_reloc(unsigned long r, struct lib_info *p)
311303
{
312304
unsigned long addr;
313-
int id;
314305
unsigned long start_brk;
315306
unsigned long start_data;
316307
unsigned long text_len;
317308
unsigned long start_code;
318309

319-
#ifdef CONFIG_BINFMT_SHARED_FLAT
320-
if (r == 0)
321-
id = curid; /* Relocs of 0 are always self referring */
322-
else {
323-
id = (r >> 24) & 0xff; /* Find ID for this reloc */
324-
r &= 0x00ffffff; /* Trim ID off here */
325-
}
326-
if (id >= MAX_SHARED_LIBS) {
327-
pr_err("reference 0x%lx to shared library %d", r, id);
328-
goto failed;
329-
}
330-
if (curid != id) {
331-
if (internalp) {
332-
pr_err("reloc address 0x%lx not in same module "
333-
"(%d != %d)", r, curid, id);
334-
goto failed;
335-
} else if (!p->lib_list[id].loaded &&
336-
load_flat_shared_library(id, p) < 0) {
337-
pr_err("failed to load library %d", id);
338-
goto failed;
339-
}
340-
/* Check versioning information (i.e. time stamps) */
341-
if (p->lib_list[id].build_date && p->lib_list[curid].build_date &&
342-
p->lib_list[curid].build_date < p->lib_list[id].build_date) {
343-
pr_err("library %d is younger than %d", id, curid);
344-
goto failed;
345-
}
346-
}
347-
#else
348-
id = 0;
349-
#endif
350-
351-
start_brk = p->lib_list[id].start_brk;
352-
start_data = p->lib_list[id].start_data;
353-
start_code = p->lib_list[id].start_code;
354-
text_len = p->lib_list[id].text_len;
310+
start_brk = p->lib_list[0].start_brk;
311+
start_data = p->lib_list[0].start_data;
312+
start_code = p->lib_list[0].start_code;
313+
text_len = p->lib_list[0].text_len;
355314

356315
if (r > start_brk - start_data + text_len) {
357316
pr_err("reloc outside program 0x%lx (0 - 0x%lx/0x%lx)",
@@ -443,7 +402,7 @@ static inline u32 __user *skip_got_header(u32 __user *rp)
443402
}
444403

445404
static int load_flat_file(struct linux_binprm *bprm,
446-
struct lib_info *libinfo, int id, unsigned long *extra_stack)
405+
struct lib_info *libinfo, unsigned long *extra_stack)
447406
{
448407
struct flat_hdr *hdr;
449408
unsigned long textpos, datapos, realdatastart;
@@ -495,14 +454,6 @@ static int load_flat_file(struct linux_binprm *bprm,
495454
goto err;
496455
}
497456

498-
/* Don't allow old format executables to use shared libraries */
499-
if (rev == OLD_FLAT_VERSION && id != 0) {
500-
pr_err("shared libraries are not available before rev 0x%lx\n",
501-
FLAT_VERSION);
502-
ret = -ENOEXEC;
503-
goto err;
504-
}
505-
506457
/*
507458
* fix up the flags for the older format, there were all kinds
508459
* of endian hacks, this only works for the simple cases
@@ -553,15 +504,13 @@ static int load_flat_file(struct linux_binprm *bprm,
553504
}
554505

555506
/* Flush all traces of the currently running executable */
556-
if (id == 0) {
557-
ret = begin_new_exec(bprm);
558-
if (ret)
559-
goto err;
507+
ret = begin_new_exec(bprm);
508+
if (ret)
509+
goto err;
560510

561-
/* OK, This is the point of no return */
562-
set_personality(PER_LINUX_32BIT);
563-
setup_new_exec(bprm);
564-
}
511+
/* OK, This is the point of no return */
512+
set_personality(PER_LINUX_32BIT);
513+
setup_new_exec(bprm);
565514

566515
/*
567516
* calculate the extra space we need to map in
@@ -741,42 +690,40 @@ static int load_flat_file(struct linux_binprm *bprm,
741690
text_len -= sizeof(struct flat_hdr); /* the real code len */
742691

743692
/* The main program needs a little extra setup in the task structure */
744-
if (id == 0) {
745-
current->mm->start_code = start_code;
746-
current->mm->end_code = end_code;
747-
current->mm->start_data = datapos;
748-
current->mm->end_data = datapos + data_len;
749-
/*
750-
* set up the brk stuff, uses any slack left in data/bss/stack
751-
* allocation. We put the brk after the bss (between the bss
752-
* and stack) like other platforms.
753-
* Userspace code relies on the stack pointer starting out at
754-
* an address right at the end of a page.
755-
*/
756-
current->mm->start_brk = datapos + data_len + bss_len;
757-
current->mm->brk = (current->mm->start_brk + 3) & ~3;
693+
current->mm->start_code = start_code;
694+
current->mm->end_code = end_code;
695+
current->mm->start_data = datapos;
696+
current->mm->end_data = datapos + data_len;
697+
/*
698+
* set up the brk stuff, uses any slack left in data/bss/stack
699+
* allocation. We put the brk after the bss (between the bss
700+
* and stack) like other platforms.
701+
* Userspace code relies on the stack pointer starting out at
702+
* an address right at the end of a page.
703+
*/
704+
current->mm->start_brk = datapos + data_len + bss_len;
705+
current->mm->brk = (current->mm->start_brk + 3) & ~3;
758706
#ifndef CONFIG_MMU
759-
current->mm->context.end_brk = memp + memp_size - stack_len;
707+
current->mm->context.end_brk = memp + memp_size - stack_len;
760708
#endif
761-
}
762709

763710
if (flags & FLAT_FLAG_KTRACE) {
764711
pr_info("Mapping is %lx, Entry point is %x, data_start is %x\n",
765712
textpos, 0x00ffffff&ntohl(hdr->entry), ntohl(hdr->data_start));
766713
pr_info("%s %s: TEXT=%lx-%lx DATA=%lx-%lx BSS=%lx-%lx\n",
767-
id ? "Lib" : "Load", bprm->filename,
714+
"Load", bprm->filename,
768715
start_code, end_code, datapos, datapos + data_len,
769716
datapos + data_len, (datapos + data_len + bss_len + 3) & ~3);
770717
}
771718

772719
/* Store the current module values into the global library structure */
773-
libinfo->lib_list[id].start_code = start_code;
774-
libinfo->lib_list[id].start_data = datapos;
775-
libinfo->lib_list[id].start_brk = datapos + data_len + bss_len;
776-
libinfo->lib_list[id].text_len = text_len;
777-
libinfo->lib_list[id].loaded = 1;
778-
libinfo->lib_list[id].entry = (0x00ffffff & ntohl(hdr->entry)) + textpos;
779-
libinfo->lib_list[id].build_date = ntohl(hdr->build_date);
720+
libinfo->lib_list[0].start_code = start_code;
721+
libinfo->lib_list[0].start_data = datapos;
722+
libinfo->lib_list[0].start_brk = datapos + data_len + bss_len;
723+
libinfo->lib_list[0].text_len = text_len;
724+
libinfo->lib_list[0].loaded = 1;
725+
libinfo->lib_list[0].entry = (0x00ffffff & ntohl(hdr->entry)) + textpos;
726+
libinfo->lib_list[0].build_date = ntohl(hdr->build_date);
780727

781728
/*
782729
* We just load the allocations into some temporary memory to
@@ -799,7 +746,7 @@ static int load_flat_file(struct linux_binprm *bprm,
799746
if (rp_val == 0xffffffff)
800747
break;
801748
if (rp_val) {
802-
addr = calc_reloc(rp_val, libinfo, id, 0);
749+
addr = calc_reloc(rp_val, libinfo);
803750
if (addr == RELOC_FAILED) {
804751
ret = -ENOEXEC;
805752
goto err;
@@ -835,7 +782,7 @@ static int load_flat_file(struct linux_binprm *bprm,
835782
return -EFAULT;
836783
relval = ntohl(tmp);
837784
addr = flat_get_relocate_addr(relval);
838-
rp = (u32 __user *)calc_reloc(addr, libinfo, id, 1);
785+
rp = (u32 __user *)calc_reloc(addr, libinfo);
839786
if (rp == (u32 __user *)RELOC_FAILED) {
840787
ret = -ENOEXEC;
841788
goto err;
@@ -858,7 +805,7 @@ static int load_flat_file(struct linux_binprm *bprm,
858805
*/
859806
addr = ntohl((__force __be32)addr);
860807
}
861-
addr = calc_reloc(addr, libinfo, id, 0);
808+
addr = calc_reloc(addr, libinfo);
862809
if (addr == RELOC_FAILED) {
863810
ret = -ENOEXEC;
864811
goto err;
@@ -886,7 +833,7 @@ static int load_flat_file(struct linux_binprm *bprm,
886833
/* zero the BSS, BRK and stack areas */
887834
if (clear_user((void __user *)(datapos + data_len), bss_len +
888835
(memp + memp_size - stack_len - /* end brk */
889-
libinfo->lib_list[id].start_brk) + /* start brk */
836+
libinfo->lib_list[0].start_brk) + /* start brk */
890837
stack_len))
891838
return -EFAULT;
892839

@@ -896,49 +843,6 @@ static int load_flat_file(struct linux_binprm *bprm,
896843
}
897844

898845

899-
/****************************************************************************/
900-
#ifdef CONFIG_BINFMT_SHARED_FLAT
901-
902-
/*
903-
* Load a shared library into memory. The library gets its own data
904-
* segment (including bss) but not argv/argc/environ.
905-
*/
906-
907-
static int load_flat_shared_library(int id, struct lib_info *libs)
908-
{
909-
/*
910-
* This is a fake bprm struct; only the members "buf", "file" and
911-
* "filename" are actually used.
912-
*/
913-
struct linux_binprm bprm;
914-
int res;
915-
char buf[16];
916-
loff_t pos = 0;
917-
918-
memset(&bprm, 0, sizeof(bprm));
919-
920-
/* Create the file name */
921-
sprintf(buf, "/lib/lib%d.so", id);
922-
923-
/* Open the file up */
924-
bprm.filename = buf;
925-
bprm.file = open_exec(bprm.filename);
926-
res = PTR_ERR(bprm.file);
927-
if (IS_ERR(bprm.file))
928-
return res;
929-
930-
res = kernel_read(bprm.file, bprm.buf, BINPRM_BUF_SIZE, &pos);
931-
932-
if (res >= 0)
933-
res = load_flat_file(&bprm, libs, id, NULL);
934-
935-
allow_write_access(bprm.file);
936-
fput(bprm.file);
937-
938-
return res;
939-
}
940-
941-
#endif /* CONFIG_BINFMT_SHARED_FLAT */
942846
/****************************************************************************/
943847

944848
/*
@@ -971,7 +875,7 @@ static int load_flat_binary(struct linux_binprm *bprm)
971875
stack_len += (bprm->envc + 1) * sizeof(char *); /* the envp array */
972876
stack_len = ALIGN(stack_len, FLAT_STACK_ALIGN);
973877

974-
res = load_flat_file(bprm, &libinfo, 0, &stack_len);
878+
res = load_flat_file(bprm, &libinfo, &stack_len);
975879
if (res < 0)
976880
return res;
977881

@@ -1016,20 +920,6 @@ static int load_flat_binary(struct linux_binprm *bprm)
1016920
*/
1017921
start_addr = libinfo.lib_list[0].entry;
1018922

1019-
#ifdef CONFIG_BINFMT_SHARED_FLAT
1020-
for (i = MAX_SHARED_LIBS-1; i > 0; i--) {
1021-
if (libinfo.lib_list[i].loaded) {
1022-
/* Push previos first to call address */
1023-
unsigned long __user *sp;
1024-
current->mm->start_stack -= sizeof(unsigned long);
1025-
sp = (unsigned long __user *)current->mm->start_stack;
1026-
if (put_user(start_addr, sp))
1027-
return -EFAULT;
1028-
start_addr = libinfo.lib_list[i].entry;
1029-
}
1030-
}
1031-
#endif
1032-
1033923
#ifdef FLAT_PLAT_INIT
1034924
FLAT_PLAT_INIT(regs);
1035925
#endif

0 commit comments

Comments
 (0)