@@ -421,7 +421,8 @@ static int load_flat_file(struct linux_binprm *bprm,
421421 unsigned long textpos , datapos , realdatastart ;
422422 u32 text_len , data_len , bss_len , stack_len , full_data , flags ;
423423 unsigned long len , memp , memp_size , extra , rlim ;
424- u32 __user * reloc , * rp ;
424+ __be32 __user * reloc ;
425+ u32 __user * rp ;
425426 struct inode * inode ;
426427 int i , rev , relocs ;
427428 loff_t fpos ;
@@ -594,7 +595,7 @@ static int load_flat_file(struct linux_binprm *bprm,
594595 goto err ;
595596 }
596597
597- reloc = (u32 __user * )
598+ reloc = (__be32 __user * )
598599 (datapos + (ntohl (hdr -> reloc_start ) - text_len ));
599600 memp = realdatastart ;
600601 memp_size = len ;
@@ -619,7 +620,7 @@ static int load_flat_file(struct linux_binprm *bprm,
619620 MAX_SHARED_LIBS * sizeof (u32 ),
620621 FLAT_DATA_ALIGN );
621622
622- reloc = (u32 __user * )
623+ reloc = (__be32 __user * )
623624 (datapos + (ntohl (hdr -> reloc_start ) - text_len ));
624625 memp = textpos ;
625626 memp_size = len ;
@@ -785,15 +786,16 @@ static int load_flat_file(struct linux_binprm *bprm,
785786 u32 __maybe_unused persistent = 0 ;
786787 for (i = 0 ; i < relocs ; i ++ ) {
787788 u32 addr , relval ;
789+ __be32 tmp ;
788790
789791 /*
790792 * Get the address of the pointer to be
791793 * relocated (of course, the address has to be
792794 * relocated first).
793795 */
794- if (get_user (relval , reloc + i ))
796+ if (get_user (tmp , reloc + i ))
795797 return - EFAULT ;
796- relval = ntohl (relval );
798+ relval = ntohl (tmp );
797799 addr = flat_get_relocate_addr (relval );
798800 rp = (u32 __user * )calc_reloc (addr , libinfo , id , 1 );
799801 if (rp == (u32 __user * )RELOC_FAILED ) {
@@ -812,8 +814,13 @@ static int load_flat_file(struct linux_binprm *bprm,
812814 * Do the relocation. PIC relocs in the data section are
813815 * already in target order
814816 */
815- if ((flags & FLAT_FLAG_GOTPIC ) == 0 )
816- addr = ntohl (addr );
817+ if ((flags & FLAT_FLAG_GOTPIC ) == 0 ) {
818+ /*
819+ * Meh, the same value can have a different
820+ * byte order based on a flag..
821+ */
822+ addr = ntohl ((__force __be32 )addr );
823+ }
817824 addr = calc_reloc (addr , libinfo , id , 0 );
818825 if (addr == RELOC_FAILED ) {
819826 ret = - ENOEXEC ;
@@ -828,11 +835,10 @@ static int load_flat_file(struct linux_binprm *bprm,
828835 }
829836 } else {
830837 for (i = 0 ; i < relocs ; i ++ ) {
831- u32 relval ;
838+ __be32 relval ;
832839 if (get_user (relval , reloc + i ))
833840 return - EFAULT ;
834- relval = ntohl (relval );
835- old_reloc (relval );
841+ old_reloc (ntohl (relval ));
836842 }
837843 }
838844
0 commit comments