Re: RFC: binfmt_elf.c recent changes (esp fao MIPS people)

From: Ralf Baechle (ralf@uni-koblenz.de)
Date: Tue Jul 11 2000 - 18:39:33 EST


On Wed, Jul 12, 2000 at 12:25:58AM +0100, Russell King wrote:

> Ralf Baechle writes:
> > I've cooked up a patch based on your suggestion which also accounts for the
> > use of elf_check_arch() in irixelf.c, and fixes the use by other
> > architectures and removes the MIPS bits again from binfmt_elf.c, it's
> > appended below.
>
> Appears fine from my perspective (the binfmt_elf changes are exactly as
> I had hoped). Linus - please apply!

In that case Linus please apply the updated version below which fixes the
glitch in the ppc header, too.

  Ralf

diff -ur linux-sgi/arch/mips/kernel/irixelf.c lw/arch/mips/kernel/irixelf.c
--- linux-sgi/arch/mips/kernel/irixelf.c Tue Jul 11 04:39:50 2000
+++ lw/arch/mips/kernel/irixelf.c Tue Jul 11 16:29:34 2000
@@ -255,7 +255,7 @@
         /* First of all, some simple consistency checks */
         if ((interp_elf_ex->e_type != ET_EXEC &&
              interp_elf_ex->e_type != ET_DYN) ||
- !elf_check_arch(interp_elf_ex->e_machine) ||
+ !irix_elf_check_arch(interp_elf_ex) ||
              !interpreter->f_op->mmap) {
                 printk("IRIX interp has bad e_type %d\n", interp_elf_ex->e_type);
                 return 0xffffffff;
@@ -395,7 +395,7 @@
 
         /* First of all, some simple consistency checks */
         if((ehp->e_type != ET_EXEC && ehp->e_type != ET_DYN) ||
- !elf_check_arch(ehp->e_machine) || !bprm->file->f_op->mmap) {
+ !irix_elf_check_arch(ehp) || !bprm->file->f_op->mmap) {
                 return -ENOEXEC;
         }
 
@@ -810,7 +810,7 @@
 
         /* First of all, some simple consistency checks. */
         if(elf_ex.e_type != ET_EXEC || elf_ex.e_phnum > 2 ||
- !elf_check_arch(elf_ex.e_machine) || !file->f_op->mmap)
+ !irix_elf_check_arch(&elf_ex) || !file->f_op->mmap)
                 return -ENOEXEC;
         
         /* Now read in all of the header information. */
diff -ur linux-sgi/fs/binfmt_elf.c lw/fs/binfmt_elf.c
--- linux-sgi/fs/binfmt_elf.c Tue Jul 11 04:40:12 2000
+++ lw/fs/binfmt_elf.c Tue Jul 11 16:25:00 2000
@@ -220,7 +220,7 @@
         if (interp_elf_ex->e_type != ET_EXEC &&
             interp_elf_ex->e_type != ET_DYN)
                 goto out;
- if (!elf_check_arch(interp_elf_ex->e_machine))
+ if (!elf_check_arch(interp_elf_ex))
                 goto out;
         if (!interpreter->f_op->mmap)
                 goto out;
@@ -405,23 +405,8 @@
 
         if (elf_ex.e_type != ET_EXEC && elf_ex.e_type != ET_DYN)
                 goto out;
- if (!elf_check_arch(elf_ex.e_machine))
+ if (!elf_check_arch(&elf_ex))
                 goto out;
-#if defined(__mips__) && !defined(__mips64)
- /* IRIX5 binaries handled elsewhere. */
- if (elf_ex.e_flags & EF_MIPS_ARCH) {
- retval = -ENOEXEC;
- goto out;
- }
-#endif
-#if defined(__mips__) && defined(__mips64)
- /* Linux/MIPS 32-bit binaries handled elsewhere. */
- if (sizeof(elf_caddr_t) == 8 &&
- elf_ex.e_ident[EI_CLASS] == ELFCLASS32) {
- retval = -ENOEXEC;
- goto out;
- }
-#endif
         if (!bprm->file->f_op||!bprm->file->f_op->mmap)
                 goto out;
 
@@ -794,7 +779,7 @@
 
         /* First of all, some simple consistency checks */
         if (elf_ex.e_type != ET_EXEC || elf_ex.e_phnum > 2 ||
- !elf_check_arch(elf_ex.e_machine) || !file->f_op->mmap)
+ !elf_check_arch(&elf_ex) || !file->f_op->mmap)
                 goto out;
 
         /* Now read in all of the header information */
diff -ur linux-sgi/include/asm-alpha/elf.h lw/include/asm-alpha/elf.h
--- linux-sgi/include/asm-alpha/elf.h Fri Apr 28 03:18:33 2000
+++ lw/include/asm-alpha/elf.h Tue Jul 11 16:06:38 2000
@@ -22,7 +22,7 @@
 /*
  * This is used to ensure we don't load something for the wrong architecture.
  */
-#define elf_check_arch(x) ((x) == EM_ALPHA)
+#define elf_check_arch(x) ((x)->e_machine == EM_ALPHA)
 
 /*
  * These are used to set parameters in the core dumps.
diff -ur linux-sgi/include/asm-i386/elf.h lw/include/asm-i386/elf.h
--- linux-sgi/include/asm-i386/elf.h Sun Jun 25 02:45:04 2000
+++ lw/include/asm-i386/elf.h Tue Jul 11 16:08:38 2000
@@ -19,7 +19,8 @@
 /*
  * This is used to ensure we don't load something for the wrong architecture.
  */
-#define elf_check_arch(x) ( ((x) == EM_386) || ((x) == EM_486) )
+#define elf_check_arch(x) \
+ (((x)->e_machine == EM_386) || ((x)->e_machine == EM_486))
 
 /*
  * These are used to set parameters in the core dumps.
diff -ur linux-sgi/include/asm-ia64/elf.h lw/include/asm-ia64/elf.h
--- linux-sgi/include/asm-ia64/elf.h Fri Apr 28 03:18:34 2000
+++ lw/include/asm-ia64/elf.h Tue Jul 11 16:09:01 2000
@@ -14,7 +14,7 @@
 /*
  * This is used to ensure we don't load something for the wrong architecture.
  */
-#define elf_check_arch(x) ((x) == EM_IA_64)
+#define elf_check_arch(x) ((x)->e_machine == EM_IA_64)
 
 /*
  * These are used to set parameters in the core dumps.
diff -ur linux-sgi/include/asm-m68k/elf.h lw/include/asm-m68k/elf.h
--- linux-sgi/include/asm-m68k/elf.h Fri Apr 28 03:18:35 2000
+++ lw/include/asm-m68k/elf.h Tue Jul 11 16:09:21 2000
@@ -19,7 +19,7 @@
 /*
  * This is used to ensure we don't load something for the wrong architecture.
  */
-#define elf_check_arch(x) ((x) == EM_68K)
+#define elf_check_arch(x) ((x)->e_machine == EM_68K)
 
 /*
  * These are used to set parameters in the core dumps.
diff -ur linux-sgi/include/asm-mips/elf.h lw/include/asm-mips/elf.h
--- linux-sgi/include/asm-mips/elf.h Fri Apr 28 03:18:35 2000
+++ lw/include/asm-mips/elf.h Tue Jul 11 16:30:16 2000
@@ -15,9 +15,33 @@
 typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
 
 /*
- * This is used to ensure we don't load something for the wrong architecture.
+ * This is used to ensure we don't load something for the wrong architecture
+ * and also rejects IRIX binaries.
  */
-#define elf_check_arch(x) ((x) == EM_MIPS || (x) == EM_MIPS_RS4_BE)
+#define elf_check_arch(hdr) \
+({ \
+ int __res = 0; \
+ struct elfhdr *__h = (hdr); \
+ \
+ if ((__h->e_machine != EM_MIPS) && (__h->e_machine != EM_MIPS)) \
+ __res = -ENOEXEC; \
+ if (__h->e_flags & EF_MIPS_ARCH) \
+ __res = -ENOEXEC; \
+ \
+ __res; \
+})
+
+/* This one accepts IRIX binaries. */
+#define irix_elf_check_arch(hdr) \
+({ \
+ int __res = 0; \
+ struct elfhdr *__h = (hdr); \
+ \
+ if ((__h->e_machine != EM_MIPS) && (__h->e_machine != EM_MIPS)) \
+ __res = -ENOEXEC; \
+ \
+ __res; \
+})
 
 /*
  * These are used to set parameters in the core dumps.
diff -ur linux-sgi/include/asm-mips64/elf.h lw/include/asm-mips64/elf.h
--- linux-sgi/include/asm-mips64/elf.h Wed Jun 21 04:32:11 2000
+++ lw/include/asm-mips64/elf.h Tue Jul 11 16:21:05 2000
@@ -1,5 +1,4 @@
-/* $Id: elf.h,v 1.3 2000/01/17 23:32:47 ralf Exp $
- *
+/*
  * This file is subject to the terms and conditions of the GNU General Public
  * License. See the file "COPYING" in the main directory of this archive
  * for more details.
@@ -22,9 +21,22 @@
 typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
 
 /*
- * This is used to ensure we don't load something for the wrong architecture.
+ * This is used to ensure we don't load something for the wrong
+ * architecture or OS.
  */
-#define elf_check_arch(x) ((x) == EM_MIPS || (x) == EM_MIPS_RS4_BE)
+#define elf_check_arch(hdr) \
+({ \
+ int __res = 0; \
+ struct elfhdr *__h = (hdr); \
+ \
+ if ((__h->e_machine != EM_MIPS) && (__h->e_machine != EM_MIPS)) \
+ __res = -ENOEXEC; \
+ if (sizeof(elf_caddr_t) == 8 && \
+ __h->e_ident[EI_CLASS] == ELFCLASS32) \
+ __res = -ENOEXEC; \
+ \
+ __res; \
+})
 
 /*
  * These are used to set parameters in the core dumps.
diff -ur linux-sgi/include/asm-ppc/elf.h lw/include/asm-ppc/elf.h
--- linux-sgi/include/asm-ppc/elf.h Fri Apr 28 03:18:35 2000
+++ lw/include/asm-ppc/elf.h Tue Jul 11 16:09:41 2000
@@ -13,7 +13,7 @@
 /*
  * This is used to ensure we don't load something for the wrong architecture.
  */
-#define elf_check_arch(x) ((x) == EM_PPC)
+#define elf_check_arch(x) ((x)->e_machine == EM_PPC)
 
 /*
  * These are used to set parameters in the core dumps.
diff -ur linux-sgi/include/asm-s390/elf.h lw/include/asm-s390/elf.h
--- linux-sgi/include/asm-s390/elf.h Sat May 13 00:55:54 2000
+++ lw/include/asm-s390/elf.h Tue Jul 11 16:09:57 2000
@@ -22,7 +22,7 @@
 /*
  * This is used to ensure we don't load something for the wrong architecture.
  */
-#define elf_check_arch(x) ((x) == EM_S390)
+#define elf_check_arch(x) ((x)->elf_machine == EM_S390)
 
 /*
  * These are used to set parameters in the core dumps.
diff -ur linux-sgi/include/asm-sh/elf.h lw/include/asm-sh/elf.h
--- linux-sgi/include/asm-sh/elf.h Fri Apr 28 03:18:35 2000
+++ lw/include/asm-sh/elf.h Tue Jul 11 16:10:12 2000
@@ -19,7 +19,7 @@
 /*
  * This is used to ensure we don't load something for the wrong architecture.
  */
-#define elf_check_arch(x) ( (x) == EM_SH )
+#define elf_check_arch(x) ( (x)->e_machine == EM_SH )
 
 /*
  * These are used to set parameters in the core dumps.
diff -ur linux-sgi/include/asm-sparc/elf.h lw/include/asm-sparc/elf.h
--- linux-sgi/include/asm-sparc/elf.h Fri Apr 28 03:18:35 2000
+++ lw/include/asm-sparc/elf.h Tue Jul 11 16:10:32 2000
@@ -59,7 +59,7 @@
 /*
  * This is used to ensure we don't load something for the wrong architecture.
  */
-#define elf_check_arch(x) ((x) == EM_SPARC)
+#define elf_check_arch(x) ((x)->e_machine == EM_SPARC)
 
 /*
  * These are used to set parameters in the core dumps.
diff -ur linux-sgi/include/asm-sparc64/elf.h lw/include/asm-sparc64/elf.h
--- linux-sgi/include/asm-sparc64/elf.h Fri Apr 28 03:18:36 2000
+++ lw/include/asm-sparc64/elf.h Tue Jul 11 16:10:56 2000
@@ -36,7 +36,7 @@
  * This is used to ensure we don't load something for the wrong architecture.
  */
 #ifndef elf_check_arch
-#define elf_check_arch(x) ((x) == ELF_ARCH) /* Might be EM_SPARCV9 or EM_SPARC */
+#define elf_check_arch(x) ((x)->e_machine == ELF_ARCH) /* Might be EM_SPARCV9 or EM_SPARC */
 #endif
 
 #define USE_ELF_CORE_DUMP

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Sat Jul 15 2000 - 21:00:13 EST