[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <1455194215-20026-3-git-send-email-daniel.wagner@bmw-carit.de>
Date: Thu, 11 Feb 2016 13:36:55 +0100
From: Daniel Wagner <daniel.wagner@...-carit.de>
To: "Maciej W. Rozycki" <macro@...tec.com>
Cc: Ralf Baechle <ralf@...ux-mips.org>, linux-kernel@...r.kernel.org,
linux-mips@...ux-mips.org,
Daniel Wagner <daniel.wagner@...-carit.de>
Subject: [PATCH v5 2/2] mips: Differentiate between 32 and 64 bit ELF header
Depending on the configuration either the 32 or 64 bit version of
elf_check_arch() is defined. parse_crash_elf{32|64}_headers() does
some basic verification of the ELF header via
vmcore_elf{32|64}_check_arch() which happen to map to elf_check_arch().
Since the implementation 32 and 64 bit version of elf_check_arch()
differ, we use the wrong type:
In file included from include/linux/elf.h:4:0,
from fs/proc/vmcore.c:13:
fs/proc/vmcore.c: In function 'parse_crash_elf64_headers':
>> arch/mips/include/asm/elf.h:228:23: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]
struct elfhdr *__h = (hdr); \
^
include/linux/crash_dump.h:41:37: note: in expansion of macro 'elf_check_arch'
#define vmcore_elf64_check_arch(x) (elf_check_arch(x) || vmcore_elf_check_arch_cross(x))
^
fs/proc/vmcore.c:1015:4: note: in expansion of macro 'vmcore_elf64_check_arch'
!vmcore_elf64_check_arch(&ehdr) ||
^
Therefore, we rather define vmcore_elf{32|64}_check_arch() as a
basic machine check and use it also in binfm_elf?32.c as well.
Signed-off-by: Daniel Wagner <daniel.wagner@...-carit.de>
Suggested-by: Maciej W. Rozycki <macro@...tec.com>
Reviewed-by: Maciej W. Rozycki <macro@...tec.com>
Reported-by: Fengguang Wu <fengguang.wu@...el.com>
---
arch/mips/include/asm/elf.h | 13 +++++++++----
arch/mips/kernel/binfmt_elfn32.c | 4 ++--
arch/mips/kernel/binfmt_elfo32.c | 4 ++--
3 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
index cefb7a5..ac53fbd 100644
--- a/arch/mips/include/asm/elf.h
+++ b/arch/mips/include/asm/elf.h
@@ -225,9 +225,9 @@ struct mips_elf_abiflags_v0 {
#define elf_check_arch(hdr) \
({ \
int __res = 1; \
- struct elfhdr *__h = (hdr); \
+ typeof(*(hdr)) *__h = (hdr); \
\
- if (__h->e_machine != EM_MIPS) \
+ if (!mips_elf_check_machine(__h)) \
__res = 0; \
if (__h->e_ident[EI_CLASS] != ELFCLASS32) \
__res = 0; \
@@ -256,9 +256,9 @@ struct mips_elf_abiflags_v0 {
#define elf_check_arch(hdr) \
({ \
int __res = 1; \
- struct elfhdr *__h = (hdr); \
+ typeof(*(hdr)) *__h = (hdr); \
\
- if (__h->e_machine != EM_MIPS) \
+ if (!mips_elf_check_machine(__h)) \
__res = 0; \
if (__h->e_ident[EI_CLASS] != ELFCLASS64) \
__res = 0; \
@@ -285,6 +285,11 @@ struct mips_elf_abiflags_v0 {
#endif /* !defined(ELF_ARCH) */
+#define mips_elf_check_machine(x) ((x)->e_machine == EM_MIPS)
+
+#define vmcore_elf32_check_arch mips_elf_check_machine
+#define vmcore_elf64_check_arch mips_elf_check_machine
+
struct mips_abi;
extern struct mips_abi mips_abi;
diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
index 1188e00..601935c 100644
--- a/arch/mips/kernel/binfmt_elfn32.c
+++ b/arch/mips/kernel/binfmt_elfn32.c
@@ -33,9 +33,9 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
#define elf_check_arch(hdr) \
({ \
int __res = 1; \
- struct elfhdr *__h = (hdr); \
+ typeof(*(hdr)) *__h = (hdr); \
\
- if (__h->e_machine != EM_MIPS) \
+ if (!mips_elf_check_machine(__h)) \
__res = 0; \
if (__h->e_ident[EI_CLASS] != ELFCLASS32) \
__res = 0; \
diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
index 9287678..a8c3702 100644
--- a/arch/mips/kernel/binfmt_elfo32.c
+++ b/arch/mips/kernel/binfmt_elfo32.c
@@ -45,9 +45,9 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
#define elf_check_arch(hdr) \
({ \
int __res = 1; \
- struct elfhdr *__h = (hdr); \
+ typeof(*(hdr)) *__h = (hdr); \
\
- if (__h->e_machine != EM_MIPS) \
+ if (!mips_elf_check_machine(__h)) \
__res = 0; \
if (__h->e_ident[EI_CLASS] != ELFCLASS32) \
__res = 0; \
--
2.5.0
Powered by blists - more mailing lists