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-
9991static int load_flat_binary (struct linux_binprm * );
10092
10193static struct linux_binfmt flat_format = {
@@ -307,51 +299,18 @@ static int decompress_exec(struct linux_binprm *bprm, loff_t fpos, char *dst,
307299/****************************************************************************/
308300
309301static 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
445404static 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