From 9ee24b2a38358acbe004640776520a093ac34642 Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Thu, 13 Jun 2019 09:08:47 +0200 Subject: binfmt_flat: remove flat_reloc_valid This helper is the same for all architectures, open code it in the only caller. Signed-off-by: Christoph Hellwig Tested-by: Vladimir Murzin Reviewed-by: Vladimir Murzin Signed-off-by: Greg Ungerer --- arch/arm/include/asm/flat.h | 1 - arch/c6x/include/asm/flat.h | 1 - arch/h8300/include/asm/flat.h | 1 - arch/m68k/include/asm/flat.h | 1 - arch/microblaze/include/asm/flat.h | 1 - arch/sh/include/asm/flat.h | 1 - arch/xtensa/include/asm/flat.h | 1 - 7 files changed, 7 deletions(-) (limited to 'arch') diff --git a/arch/arm/include/asm/flat.h b/arch/arm/include/asm/flat.h index f0c75ddeea23..10cce9ecf151 100644 --- a/arch/arm/include/asm/flat.h +++ b/arch/arm/include/asm/flat.h @@ -10,7 +10,6 @@ #define flat_argvp_envp_on_stack() 1 #define flat_old_ram_flag(flags) (flags) -#define flat_reloc_valid(reloc, size) ((reloc) <= (size)) static inline int flat_get_addr_from_rp(u32 __user *rp, u32 relval, u32 flags, u32 *addr, u32 *persistent) diff --git a/arch/c6x/include/asm/flat.h b/arch/c6x/include/asm/flat.h index 76fd0bb962a3..ecc6aea6606c 100644 --- a/arch/c6x/include/asm/flat.h +++ b/arch/c6x/include/asm/flat.h @@ -6,7 +6,6 @@ #define flat_argvp_envp_on_stack() 0 #define flat_old_ram_flag(flags) (flags) -#define flat_reloc_valid(reloc, size) ((reloc) <= (size)) static inline int flat_get_addr_from_rp(u32 __user *rp, u32 relval, u32 flags, u32 *addr, u32 *persistent) { diff --git a/arch/h8300/include/asm/flat.h b/arch/h8300/include/asm/flat.h index f4cdfcbdd2ba..dcc7775115dd 100644 --- a/arch/h8300/include/asm/flat.h +++ b/arch/h8300/include/asm/flat.h @@ -10,7 +10,6 @@ #define flat_argvp_envp_on_stack() 1 #define flat_old_ram_flag(flags) 1 -#define flat_reloc_valid(reloc, size) ((reloc) <= (size)) #define flat_set_persistent(relval, p) 0 /* diff --git a/arch/m68k/include/asm/flat.h b/arch/m68k/include/asm/flat.h index 4f1d1e373420..a631caf5e18f 100644 --- a/arch/m68k/include/asm/flat.h +++ b/arch/m68k/include/asm/flat.h @@ -10,7 +10,6 @@ #define flat_argvp_envp_on_stack() 1 #define flat_old_ram_flag(flags) (flags) -#define flat_reloc_valid(reloc, size) ((reloc) <= (size)) static inline int flat_get_addr_from_rp(u32 __user *rp, u32 relval, u32 flags, u32 *addr, u32 *persistent) { diff --git a/arch/microblaze/include/asm/flat.h b/arch/microblaze/include/asm/flat.h index 3d2747d4c967..34be5ed011be 100644 --- a/arch/microblaze/include/asm/flat.h +++ b/arch/microblaze/include/asm/flat.h @@ -15,7 +15,6 @@ #define flat_argvp_envp_on_stack() 0 #define flat_old_ram_flag(flags) (flags) -#define flat_reloc_valid(reloc, size) ((reloc) <= (size)) #define flat_set_persistent(relval, p) 0 /* diff --git a/arch/sh/include/asm/flat.h b/arch/sh/include/asm/flat.h index 843d458b8329..8f2929b32f2e 100644 --- a/arch/sh/include/asm/flat.h +++ b/arch/sh/include/asm/flat.h @@ -13,7 +13,6 @@ #define flat_argvp_envp_on_stack() 0 #define flat_old_ram_flag(flags) (flags) -#define flat_reloc_valid(reloc, size) ((reloc) <= (size)) static inline int flat_get_addr_from_rp(u32 __user *rp, u32 relval, u32 flags, u32 *addr, u32 *persistent) { diff --git a/arch/xtensa/include/asm/flat.h b/arch/xtensa/include/asm/flat.h index b8532d7877b3..6ee5a35eb0ec 100644 --- a/arch/xtensa/include/asm/flat.h +++ b/arch/xtensa/include/asm/flat.h @@ -6,7 +6,6 @@ #define flat_argvp_envp_on_stack() 0 #define flat_old_ram_flag(flags) (flags) -#define flat_reloc_valid(reloc, size) ((reloc) <= (size)) static inline int flat_get_addr_from_rp(u32 __user *rp, u32 relval, u32 flags, u32 *addr, u32 *persistent) { -- cgit v1.2.3-59-g8ed1b From 2f3196d49b1e10f1d4bc64cce00dc95fde2b0ce1 Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Thu, 13 Jun 2019 09:08:48 +0200 Subject: binfmt_flat: remove flat_set_persistent This helper is a no-op on all architectures, remove it. Signed-off-by: Christoph Hellwig Tested-by: Vladimir Murzin Reviewed-by: Vladimir Murzin Signed-off-by: Greg Ungerer --- arch/arm/include/asm/flat.h | 1 - arch/c6x/include/asm/flat.h | 1 - arch/h8300/include/asm/flat.h | 1 - arch/m68k/include/asm/flat.h | 5 ----- arch/microblaze/include/asm/flat.h | 1 - arch/sh/include/asm/flat.h | 1 - arch/xtensa/include/asm/flat.h | 1 - fs/binfmt_flat.c | 2 -- 8 files changed, 13 deletions(-) (limited to 'arch') diff --git a/arch/arm/include/asm/flat.h b/arch/arm/include/asm/flat.h index 10cce9ecf151..576241d74704 100644 --- a/arch/arm/include/asm/flat.h +++ b/arch/arm/include/asm/flat.h @@ -31,6 +31,5 @@ static inline int flat_put_addr_at_rp(u32 __user *rp, u32 addr, u32 rel) } #define flat_get_relocate_addr(rel) (rel) -#define flat_set_persistent(relval, p) 0 #endif /* __ARM_FLAT_H__ */ diff --git a/arch/c6x/include/asm/flat.h b/arch/c6x/include/asm/flat.h index ecc6aea6606c..ac87368efad1 100644 --- a/arch/c6x/include/asm/flat.h +++ b/arch/c6x/include/asm/flat.h @@ -18,6 +18,5 @@ static inline int flat_put_addr_at_rp(u32 __user *rp, u32 addr, u32 rel) return 0; } #define flat_get_relocate_addr(rel) (rel) -#define flat_set_persistent(relval, p) 0 #endif /* __ASM_C6X_FLAT_H */ diff --git a/arch/h8300/include/asm/flat.h b/arch/h8300/include/asm/flat.h index dcc7775115dd..7ef7eefded3d 100644 --- a/arch/h8300/include/asm/flat.h +++ b/arch/h8300/include/asm/flat.h @@ -10,7 +10,6 @@ #define flat_argvp_envp_on_stack() 1 #define flat_old_ram_flag(flags) 1 -#define flat_set_persistent(relval, p) 0 /* * on the H8 a couple of the relocations have an instruction in the diff --git a/arch/m68k/include/asm/flat.h b/arch/m68k/include/asm/flat.h index a631caf5e18f..955617bb937b 100644 --- a/arch/m68k/include/asm/flat.h +++ b/arch/m68k/include/asm/flat.h @@ -30,11 +30,6 @@ static inline int flat_put_addr_at_rp(u32 __user *rp, u32 addr, u32 rel) } #define flat_get_relocate_addr(rel) (rel) -static inline int flat_set_persistent(u32 relval, u32 *persistent) -{ - return 0; -} - #define FLAT_PLAT_INIT(regs) \ do { \ if (current->mm) \ diff --git a/arch/microblaze/include/asm/flat.h b/arch/microblaze/include/asm/flat.h index 34be5ed011be..846084fa7f04 100644 --- a/arch/microblaze/include/asm/flat.h +++ b/arch/microblaze/include/asm/flat.h @@ -15,7 +15,6 @@ #define flat_argvp_envp_on_stack() 0 #define flat_old_ram_flag(flags) (flags) -#define flat_set_persistent(relval, p) 0 /* * Microblaze works a little differently from other arches, because diff --git a/arch/sh/include/asm/flat.h b/arch/sh/include/asm/flat.h index 8f2929b32f2e..6f3b18679a98 100644 --- a/arch/sh/include/asm/flat.h +++ b/arch/sh/include/asm/flat.h @@ -25,7 +25,6 @@ static inline int flat_put_addr_at_rp(u32 __user *rp, u32 addr, u32 rel) return 0; } #define flat_get_relocate_addr(rel) (rel) -#define flat_set_persistent(relval, p) ({ (void)p; 0; }) #define FLAT_PLAT_INIT(_r) \ do { _r->regs[0]=0; _r->regs[1]=0; _r->regs[2]=0; _r->regs[3]=0; \ diff --git a/arch/xtensa/include/asm/flat.h b/arch/xtensa/include/asm/flat.h index 6ee5a35eb0ec..b1bc0d9a8d4e 100644 --- a/arch/xtensa/include/asm/flat.h +++ b/arch/xtensa/include/asm/flat.h @@ -18,6 +18,5 @@ static inline int flat_put_addr_at_rp(u32 __user *rp, u32 addr, u32 rel) return 0; } #define flat_get_relocate_addr(rel) (rel) -#define flat_set_persistent(relval, p) 0 #endif /* __ASM_XTENSA_FLAT_H */ diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c index afddea583999..a4c0b245ab1f 100644 --- a/fs/binfmt_flat.c +++ b/fs/binfmt_flat.c @@ -787,8 +787,6 @@ static int load_flat_file(struct linux_binprm *bprm, if (get_user(relval, reloc + i)) return -EFAULT; relval = ntohl(relval); - if (flat_set_persistent(relval, &persistent)) - continue; addr = flat_get_relocate_addr(relval); rp = (u32 __user *)calc_reloc(addr, libinfo, id, 1); if (rp == (u32 __user *)RELOC_FAILED) { -- cgit v1.2.3-59-g8ed1b From 02da283302f7e723a6cef3ea296fbb2313dde992 Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Thu, 13 Jun 2019 09:08:49 +0200 Subject: binfmt_flat: provide a default version of flat_get_relocate_addr This way only the two architectures that do masking need to provide the helper. Signed-off-by: Christoph Hellwig Tested-by: Vladimir Murzin Reviewed-by: Vladimir Murzin Signed-off-by: Greg Ungerer --- arch/arm/include/asm/flat.h | 2 -- arch/c6x/include/asm/flat.h | 1 - arch/m68k/include/asm/flat.h | 1 - arch/sh/include/asm/flat.h | 1 - arch/xtensa/include/asm/flat.h | 1 - fs/binfmt_flat.c | 4 ++++ 6 files changed, 4 insertions(+), 6 deletions(-) (limited to 'arch') diff --git a/arch/arm/include/asm/flat.h b/arch/arm/include/asm/flat.h index 576241d74704..a185fe023b60 100644 --- a/arch/arm/include/asm/flat.h +++ b/arch/arm/include/asm/flat.h @@ -30,6 +30,4 @@ static inline int flat_put_addr_at_rp(u32 __user *rp, u32 addr, u32 rel) #endif } -#define flat_get_relocate_addr(rel) (rel) - #endif /* __ARM_FLAT_H__ */ diff --git a/arch/c6x/include/asm/flat.h b/arch/c6x/include/asm/flat.h index ac87368efad1..c4d703b454c6 100644 --- a/arch/c6x/include/asm/flat.h +++ b/arch/c6x/include/asm/flat.h @@ -17,6 +17,5 @@ static inline int flat_put_addr_at_rp(u32 __user *rp, u32 addr, u32 rel) put_unaligned(addr, (__force u32 *)rp); return 0; } -#define flat_get_relocate_addr(rel) (rel) #endif /* __ASM_C6X_FLAT_H */ diff --git a/arch/m68k/include/asm/flat.h b/arch/m68k/include/asm/flat.h index 955617bb937b..217fa89c8e34 100644 --- a/arch/m68k/include/asm/flat.h +++ b/arch/m68k/include/asm/flat.h @@ -28,7 +28,6 @@ static inline int flat_put_addr_at_rp(u32 __user *rp, u32 addr, u32 rel) return put_user(addr, rp); #endif } -#define flat_get_relocate_addr(rel) (rel) #define FLAT_PLAT_INIT(regs) \ do { \ diff --git a/arch/sh/include/asm/flat.h b/arch/sh/include/asm/flat.h index 6f3b18679a98..0d520b4cc5ea 100644 --- a/arch/sh/include/asm/flat.h +++ b/arch/sh/include/asm/flat.h @@ -24,7 +24,6 @@ static inline int flat_put_addr_at_rp(u32 __user *rp, u32 addr, u32 rel) put_unaligned(addr, (__force u32 *)rp); return 0; } -#define flat_get_relocate_addr(rel) (rel) #define FLAT_PLAT_INIT(_r) \ do { _r->regs[0]=0; _r->regs[1]=0; _r->regs[2]=0; _r->regs[3]=0; \ diff --git a/arch/xtensa/include/asm/flat.h b/arch/xtensa/include/asm/flat.h index b1bc0d9a8d4e..a1d88aa3ef8a 100644 --- a/arch/xtensa/include/asm/flat.h +++ b/arch/xtensa/include/asm/flat.h @@ -17,6 +17,5 @@ static inline int flat_put_addr_at_rp(u32 __user *rp, u32 addr, u32 rel) put_unaligned(addr, (__force u32 *)rp); return 0; } -#define flat_get_relocate_addr(rel) (rel) #endif /* __ASM_XTENSA_FLAT_H */ diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c index a4c0b245ab1f..c0e4535dc1ec 100644 --- a/fs/binfmt_flat.c +++ b/fs/binfmt_flat.c @@ -43,6 +43,10 @@ #include #include +#ifndef flat_get_relocate_addr +#define flat_get_relocate_addr(rel) (rel) +#endif + /****************************************************************************/ /* -- cgit v1.2.3-59-g8ed1b From 1d52dca117434eca9c6efc9c22d24e7a341ad903 Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Thu, 13 Jun 2019 09:08:50 +0200 Subject: binfmt_flat: remove flat_old_ram_flag Instead add a Kconfig variable that only h8300 selects. Signed-off-by: Christoph Hellwig Signed-off-by: Greg Ungerer --- arch/arm/include/asm/flat.h | 1 - arch/c6x/include/asm/flat.h | 1 - arch/h8300/Kconfig | 1 + arch/h8300/include/asm/flat.h | 1 - arch/m68k/include/asm/flat.h | 1 - arch/microblaze/include/asm/flat.h | 1 - arch/sh/include/asm/flat.h | 1 - arch/xtensa/include/asm/flat.h | 1 - fs/Kconfig.binfmt | 3 +++ fs/binfmt_flat.c | 3 ++- 10 files changed, 6 insertions(+), 8 deletions(-) (limited to 'arch') diff --git a/arch/arm/include/asm/flat.h b/arch/arm/include/asm/flat.h index a185fe023b60..acf162111ee2 100644 --- a/arch/arm/include/asm/flat.h +++ b/arch/arm/include/asm/flat.h @@ -9,7 +9,6 @@ #include #define flat_argvp_envp_on_stack() 1 -#define flat_old_ram_flag(flags) (flags) static inline int flat_get_addr_from_rp(u32 __user *rp, u32 relval, u32 flags, u32 *addr, u32 *persistent) diff --git a/arch/c6x/include/asm/flat.h b/arch/c6x/include/asm/flat.h index c4d703b454c6..353e4d06e8c0 100644 --- a/arch/c6x/include/asm/flat.h +++ b/arch/c6x/include/asm/flat.h @@ -5,7 +5,6 @@ #include #define flat_argvp_envp_on_stack() 0 -#define flat_old_ram_flag(flags) (flags) static inline int flat_get_addr_from_rp(u32 __user *rp, u32 relval, u32 flags, u32 *addr, u32 *persistent) { diff --git a/arch/h8300/Kconfig b/arch/h8300/Kconfig index ecfc4b4b6373..d30e8727b02d 100644 --- a/arch/h8300/Kconfig +++ b/arch/h8300/Kconfig @@ -2,6 +2,7 @@ config H8300 def_bool y select ARCH_32BIT_OFF_T + select BINFMT_FLAT_OLD_ALWAYS_RAM select GENERIC_ATOMIC64 select HAVE_UID16 select VIRT_TO_BUS diff --git a/arch/h8300/include/asm/flat.h b/arch/h8300/include/asm/flat.h index 7ef7eefded3d..14cc928d5478 100644 --- a/arch/h8300/include/asm/flat.h +++ b/arch/h8300/include/asm/flat.h @@ -9,7 +9,6 @@ #include #define flat_argvp_envp_on_stack() 1 -#define flat_old_ram_flag(flags) 1 /* * on the H8 a couple of the relocations have an instruction in the diff --git a/arch/m68k/include/asm/flat.h b/arch/m68k/include/asm/flat.h index 217fa89c8e34..7b1fb5c2809e 100644 --- a/arch/m68k/include/asm/flat.h +++ b/arch/m68k/include/asm/flat.h @@ -9,7 +9,6 @@ #include #define flat_argvp_envp_on_stack() 1 -#define flat_old_ram_flag(flags) (flags) static inline int flat_get_addr_from_rp(u32 __user *rp, u32 relval, u32 flags, u32 *addr, u32 *persistent) { diff --git a/arch/microblaze/include/asm/flat.h b/arch/microblaze/include/asm/flat.h index 846084fa7f04..1cd8d7f4cf12 100644 --- a/arch/microblaze/include/asm/flat.h +++ b/arch/microblaze/include/asm/flat.h @@ -14,7 +14,6 @@ #include #define flat_argvp_envp_on_stack() 0 -#define flat_old_ram_flag(flags) (flags) /* * Microblaze works a little differently from other arches, because diff --git a/arch/sh/include/asm/flat.h b/arch/sh/include/asm/flat.h index 0d520b4cc5ea..015678d7b771 100644 --- a/arch/sh/include/asm/flat.h +++ b/arch/sh/include/asm/flat.h @@ -12,7 +12,6 @@ #include #define flat_argvp_envp_on_stack() 0 -#define flat_old_ram_flag(flags) (flags) static inline int flat_get_addr_from_rp(u32 __user *rp, u32 relval, u32 flags, u32 *addr, u32 *persistent) { diff --git a/arch/xtensa/include/asm/flat.h b/arch/xtensa/include/asm/flat.h index a1d88aa3ef8a..b215c1e66958 100644 --- a/arch/xtensa/include/asm/flat.h +++ b/arch/xtensa/include/asm/flat.h @@ -5,7 +5,6 @@ #include #define flat_argvp_envp_on_stack() 0 -#define flat_old_ram_flag(flags) (flags) static inline int flat_get_addr_from_rp(u32 __user *rp, u32 relval, u32 flags, u32 *addr, u32 *persistent) { diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt index f87ddd1b6d72..5658e12ad944 100644 --- a/fs/Kconfig.binfmt +++ b/fs/Kconfig.binfmt @@ -97,6 +97,9 @@ config BINFMT_FLAT help Support uClinux FLAT format binaries. +config BINFMT_FLAT_OLD_ALWAYS_RAM + bool + config BINFMT_ZFLAT bool "Enable ZFLAT support" depends on BINFMT_FLAT diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c index c0e4535dc1ec..3e7f4a6cffa2 100644 --- a/fs/binfmt_flat.c +++ b/fs/binfmt_flat.c @@ -488,7 +488,8 @@ static int load_flat_file(struct linux_binprm *bprm, * fix up the flags for the older format, there were all kinds * of endian hacks, this only works for the simple cases */ - if (rev == OLD_FLAT_VERSION && flat_old_ram_flag(flags)) + if (rev == OLD_FLAT_VERSION && + (flags || IS_ENABLED(CONFIG_BINFMT_FLAT_OLD_ALWAYS_RAM))) flags = FLAT_FLAG_RAM; #ifndef CONFIG_BINFMT_ZFLAT -- cgit v1.2.3-59-g8ed1b From bdd15a288492f2f496a904c69c4b332057ae2ef6 Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Thu, 13 Jun 2019 09:08:51 +0200 Subject: binfmt_flat: replace flat_argvp_envp_on_stack with a Kconfig variable This will eventually allow us to kill the need for an for many cases. Signed-off-by: Christoph Hellwig Tested-by: Vladimir Murzin Reviewed-by: Vladimir Murzin Signed-off-by: Greg Ungerer --- arch/arm/Kconfig | 1 + arch/arm/include/asm/flat.h | 2 -- arch/c6x/include/asm/flat.h | 1 - arch/h8300/Kconfig | 1 + arch/h8300/include/asm/flat.h | 2 -- arch/m68k/Kconfig | 1 + arch/m68k/include/asm/flat.h | 1 - arch/microblaze/include/asm/flat.h | 2 -- arch/sh/include/asm/flat.h | 1 - arch/xtensa/include/asm/flat.h | 1 - fs/Kconfig.binfmt | 3 +++ fs/binfmt_flat.c | 5 +++-- 12 files changed, 9 insertions(+), 12 deletions(-) (limited to 'arch') diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 8869742a85df..b1b48c0bde76 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -30,6 +30,7 @@ config ARM select ARCH_USE_BUILTIN_BSWAP select ARCH_USE_CMPXCHG_LOCKREF select ARCH_WANT_IPC_PARSE_VERSION + select BINFMT_FLAT_ARGVP_ENVP_ON_STACK select BUILDTIME_EXTABLE_SORT if MMU select CLONE_BACKWARDS select CPU_PM if SUSPEND || CPU_IDLE diff --git a/arch/arm/include/asm/flat.h b/arch/arm/include/asm/flat.h index acf162111ee2..bbc27901446f 100644 --- a/arch/arm/include/asm/flat.h +++ b/arch/arm/include/asm/flat.h @@ -8,8 +8,6 @@ #include -#define flat_argvp_envp_on_stack() 1 - static inline int flat_get_addr_from_rp(u32 __user *rp, u32 relval, u32 flags, u32 *addr, u32 *persistent) { diff --git a/arch/c6x/include/asm/flat.h b/arch/c6x/include/asm/flat.h index 353e4d06e8c0..2d57a9204d21 100644 --- a/arch/c6x/include/asm/flat.h +++ b/arch/c6x/include/asm/flat.h @@ -4,7 +4,6 @@ #include -#define flat_argvp_envp_on_stack() 0 static inline int flat_get_addr_from_rp(u32 __user *rp, u32 relval, u32 flags, u32 *addr, u32 *persistent) { diff --git a/arch/h8300/Kconfig b/arch/h8300/Kconfig index d30e8727b02d..7457f190caaa 100644 --- a/arch/h8300/Kconfig +++ b/arch/h8300/Kconfig @@ -2,6 +2,7 @@ config H8300 def_bool y select ARCH_32BIT_OFF_T + select BINFMT_FLAT_ARGVP_ENVP_ON_STACK select BINFMT_FLAT_OLD_ALWAYS_RAM select GENERIC_ATOMIC64 select HAVE_UID16 diff --git a/arch/h8300/include/asm/flat.h b/arch/h8300/include/asm/flat.h index 14cc928d5478..4683146f0e9e 100644 --- a/arch/h8300/include/asm/flat.h +++ b/arch/h8300/include/asm/flat.h @@ -8,8 +8,6 @@ #include -#define flat_argvp_envp_on_stack() 1 - /* * on the H8 a couple of the relocations have an instruction in the * top byte. As there can only be 24bits of address space, we just diff --git a/arch/m68k/Kconfig b/arch/m68k/Kconfig index 218e037ef901..fd69ee5ad6ab 100644 --- a/arch/m68k/Kconfig +++ b/arch/m68k/Kconfig @@ -7,6 +7,7 @@ config M68K select ARCH_MIGHT_HAVE_PC_PARPORT if ISA select ARCH_NO_COHERENT_DMA_MMAP if !MMU select ARCH_NO_PREEMPT if !COLDFIRE + select BINFMT_FLAT_ARGVP_ENVP_ON_STACK select HAVE_IDE select HAVE_AOUT if MMU select HAVE_DEBUG_BUGVERBOSE diff --git a/arch/m68k/include/asm/flat.h b/arch/m68k/include/asm/flat.h index 7b1fb5c2809e..d7102fcd43eb 100644 --- a/arch/m68k/include/asm/flat.h +++ b/arch/m68k/include/asm/flat.h @@ -8,7 +8,6 @@ #include -#define flat_argvp_envp_on_stack() 1 static inline int flat_get_addr_from_rp(u32 __user *rp, u32 relval, u32 flags, u32 *addr, u32 *persistent) { diff --git a/arch/microblaze/include/asm/flat.h b/arch/microblaze/include/asm/flat.h index 1cd8d7f4cf12..9e3d8e01d294 100644 --- a/arch/microblaze/include/asm/flat.h +++ b/arch/microblaze/include/asm/flat.h @@ -13,8 +13,6 @@ #include -#define flat_argvp_envp_on_stack() 0 - /* * Microblaze works a little differently from other arches, because * of the MICROBLAZE_64 reloc type. Here, a 32 bit address is split diff --git a/arch/sh/include/asm/flat.h b/arch/sh/include/asm/flat.h index 015678d7b771..1002343dd84a 100644 --- a/arch/sh/include/asm/flat.h +++ b/arch/sh/include/asm/flat.h @@ -11,7 +11,6 @@ #include -#define flat_argvp_envp_on_stack() 0 static inline int flat_get_addr_from_rp(u32 __user *rp, u32 relval, u32 flags, u32 *addr, u32 *persistent) { diff --git a/arch/xtensa/include/asm/flat.h b/arch/xtensa/include/asm/flat.h index b215c1e66958..3d357371b28b 100644 --- a/arch/xtensa/include/asm/flat.h +++ b/arch/xtensa/include/asm/flat.h @@ -4,7 +4,6 @@ #include -#define flat_argvp_envp_on_stack() 0 static inline int flat_get_addr_from_rp(u32 __user *rp, u32 relval, u32 flags, u32 *addr, u32 *persistent) { diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt index 5658e12ad944..82f7d7f234f3 100644 --- a/fs/Kconfig.binfmt +++ b/fs/Kconfig.binfmt @@ -97,6 +97,9 @@ config BINFMT_FLAT help Support uClinux FLAT format binaries. +config BINFMT_FLAT_ARGVP_ENVP_ON_STACK + bool + config BINFMT_FLAT_OLD_ALWAYS_RAM bool diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c index 3e7f4a6cffa2..a15fdd5d95ed 100644 --- a/fs/binfmt_flat.c +++ b/fs/binfmt_flat.c @@ -124,14 +124,15 @@ static int create_flat_tables(struct linux_binprm *bprm, unsigned long arg_start sp -= bprm->envc + 1; sp -= bprm->argc + 1; - sp -= flat_argvp_envp_on_stack() ? 2 : 0; + if (IS_ENABLED(CONFIG_BINFMT_FLAT_ARGVP_ENVP_ON_STACK)) + sp -= 2; /* argvp + envp */ sp -= 1; /* &argc */ current->mm->start_stack = (unsigned long)sp & -FLAT_STACK_ALIGN; sp = (unsigned long __user *)current->mm->start_stack; __put_user(bprm->argc, sp++); - if (flat_argvp_envp_on_stack()) { + if (IS_ENABLED(CONFIG_BINFMT_FLAT_ARGVP_ENVP_ON_STACK)) { unsigned long argv, envp; argv = (unsigned long)(sp + 2); envp = (unsigned long)(sp + 2 + bprm->argc + 1); -- cgit v1.2.3-59-g8ed1b From aef0f78e7460cd2889fe5359b26f7ad3c9555630 Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Thu, 13 Jun 2019 09:08:57 +0200 Subject: binfmt_flat: add a ARCH_HAS_BINFMT_FLAT option Allow architectures to opt into ARCH_HAS_BINFMT_FLAT support instead of assuming that all nommu ports support the format. Signed-off-by: Christoph Hellwig Reviewed-by: Vladimir Murzin Signed-off-by: Greg Ungerer --- arch/arm/Kconfig | 1 + arch/c6x/Kconfig | 1 + arch/h8300/Kconfig | 1 + arch/m68k/Kconfig | 1 + arch/microblaze/Kconfig | 1 + arch/sh/Kconfig | 1 + arch/xtensa/Kconfig | 1 + fs/Kconfig.binfmt | 5 ++++- 8 files changed, 11 insertions(+), 1 deletion(-) (limited to 'arch') diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index b1b48c0bde76..695a26c68064 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -4,6 +4,7 @@ config ARM default y select ARCH_32BIT_OFF_T select ARCH_CLOCKSOURCE_DATA + select ARCH_HAS_BINFMT_FLAT select ARCH_HAS_DEBUG_VIRTUAL if MMU select ARCH_HAS_DEVMEM_IS_ALLOWED select ARCH_HAS_ELF_RANDOMIZE diff --git a/arch/c6x/Kconfig b/arch/c6x/Kconfig index eeb0471268a0..78dfe186d708 100644 --- a/arch/c6x/Kconfig +++ b/arch/c6x/Kconfig @@ -7,6 +7,7 @@ config C6X def_bool y select ARCH_32BIT_OFF_T + select ARCH_HAS_BINFMT_FLAT select ARCH_HAS_SYNC_DMA_FOR_CPU select ARCH_HAS_SYNC_DMA_FOR_DEVICE select CLKDEV_LOOKUP diff --git a/arch/h8300/Kconfig b/arch/h8300/Kconfig index 7457f190caaa..ec800e9d5aad 100644 --- a/arch/h8300/Kconfig +++ b/arch/h8300/Kconfig @@ -2,6 +2,7 @@ config H8300 def_bool y select ARCH_32BIT_OFF_T + select ARCH_HAS_BINFMT_FLAT select BINFMT_FLAT_ARGVP_ENVP_ON_STACK select BINFMT_FLAT_OLD_ALWAYS_RAM select GENERIC_ATOMIC64 diff --git a/arch/m68k/Kconfig b/arch/m68k/Kconfig index fd69ee5ad6ab..c0c43c624afa 100644 --- a/arch/m68k/Kconfig +++ b/arch/m68k/Kconfig @@ -3,6 +3,7 @@ config M68K bool default y select ARCH_32BIT_OFF_T + select ARCH_HAS_BINFMT_FLAT select ARCH_HAS_SYNC_DMA_FOR_DEVICE if HAS_DMA select ARCH_MIGHT_HAVE_PC_PARPORT if ISA select ARCH_NO_COHERENT_DMA_MMAP if !MMU diff --git a/arch/microblaze/Kconfig b/arch/microblaze/Kconfig index f11433daab4a..d411de05b628 100644 --- a/arch/microblaze/Kconfig +++ b/arch/microblaze/Kconfig @@ -3,6 +3,7 @@ config MICROBLAZE def_bool y select ARCH_32BIT_OFF_T select ARCH_NO_SWAP + select ARCH_HAS_BINFMT_FLAT if !MMU select ARCH_HAS_DMA_COHERENT_TO_PFN if MMU select ARCH_HAS_GCOV_PROFILE_ALL select ARCH_HAS_SYNC_DMA_FOR_CPU diff --git a/arch/sh/Kconfig b/arch/sh/Kconfig index b77f512bb176..df3e6215b78c 100644 --- a/arch/sh/Kconfig +++ b/arch/sh/Kconfig @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 config SUPERH def_bool y + select ARCH_HAS_BINFMT_FLAT if !MMU select ARCH_HAS_PTE_SPECIAL select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST select ARCH_MIGHT_HAVE_PC_PARPORT diff --git a/arch/xtensa/Kconfig b/arch/xtensa/Kconfig index 6ec1b75eabc5..ebc135bda921 100644 --- a/arch/xtensa/Kconfig +++ b/arch/xtensa/Kconfig @@ -2,6 +2,7 @@ config XTENSA def_bool y select ARCH_32BIT_OFF_T + select ARCH_HAS_BINFMT_FLAT if !MMU select ARCH_HAS_SYNC_DMA_FOR_CPU select ARCH_HAS_SYNC_DMA_FOR_DEVICE select ARCH_NO_COHERENT_DMA_MMAP if !MMU diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt index 82f7d7f234f3..286b425b30b9 100644 --- a/fs/Kconfig.binfmt +++ b/fs/Kconfig.binfmt @@ -91,9 +91,12 @@ config BINFMT_SCRIPT Most systems will not boot if you say M or N here. If unsure, say Y. +config ARCH_HAS_BINFMT_FLAT + bool + config BINFMT_FLAT bool "Kernel support for flat binaries" - depends on !MMU || ARM || M68K + depends on ARCH_HAS_BINFMT_FLAT help Support uClinux FLAT format binaries. -- cgit v1.2.3-59-g8ed1b From 7a8998c9d830b59626e049a827678ba444fcf8e2 Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Thu, 13 Jun 2019 09:08:59 +0200 Subject: binfmt_flat: provide an asm-generic/flat.h This file implements the flat get/put reloc helpers for architectures that do not need to overload the relocs by simply using get_user/put_user. Note that many nommu architectures currently use {get,put}_unaligned, which looks a little bogus and should probably later be switched over to this version as well. Signed-off-by: Christoph Hellwig Reviewed-by: Vladimir Murzin Signed-off-by: Greg Ungerer --- arch/arm/include/asm/Kbuild | 1 + arch/arm/include/asm/flat.h | 30 ------------------------------ arch/m68k/include/asm/flat.h | 21 +-------------------- include/asm-generic/flat.h | 26 ++++++++++++++++++++++++++ 4 files changed, 28 insertions(+), 50 deletions(-) delete mode 100644 arch/arm/include/asm/flat.h create mode 100644 include/asm-generic/flat.h (limited to 'arch') diff --git a/arch/arm/include/asm/Kbuild b/arch/arm/include/asm/Kbuild index a8f149ab45b8..6b2dc15b6dff 100644 --- a/arch/arm/include/asm/Kbuild +++ b/arch/arm/include/asm/Kbuild @@ -5,6 +5,7 @@ generic-y += early_ioremap.h generic-y += emergency-restart.h generic-y += exec.h generic-y += extable.h +generic-y += flat.h generic-y += irq_regs.h generic-y += kdebug.h generic-y += local.h diff --git a/arch/arm/include/asm/flat.h b/arch/arm/include/asm/flat.h deleted file mode 100644 index bbc27901446f..000000000000 --- a/arch/arm/include/asm/flat.h +++ /dev/null @@ -1,30 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * arch/arm/include/asm/flat.h -- uClinux flat-format executables - */ - -#ifndef __ARM_FLAT_H__ -#define __ARM_FLAT_H__ - -#include - -static inline int flat_get_addr_from_rp(u32 __user *rp, u32 relval, u32 flags, - u32 *addr, u32 *persistent) -{ -#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS - return copy_from_user(addr, rp, 4) ? -EFAULT : 0; -#else - return get_user(*addr, rp); -#endif -} - -static inline int flat_put_addr_at_rp(u32 __user *rp, u32 addr, u32 rel) -{ -#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS - return copy_to_user(rp, &addr, 4) ? -EFAULT : 0; -#else - return put_user(addr, rp); -#endif -} - -#endif /* __ARM_FLAT_H__ */ diff --git a/arch/m68k/include/asm/flat.h b/arch/m68k/include/asm/flat.h index d7102fcd43eb..46379e08cdd6 100644 --- a/arch/m68k/include/asm/flat.h +++ b/arch/m68k/include/asm/flat.h @@ -6,26 +6,7 @@ #ifndef __M68KNOMMU_FLAT_H__ #define __M68KNOMMU_FLAT_H__ -#include - -static inline int flat_get_addr_from_rp(u32 __user *rp, u32 relval, u32 flags, - u32 *addr, u32 *persistent) -{ -#ifdef CONFIG_CPU_HAS_NO_UNALIGNED - return copy_from_user(addr, rp, 4) ? -EFAULT : 0; -#else - return get_user(*addr, rp); -#endif -} - -static inline int flat_put_addr_at_rp(u32 __user *rp, u32 addr, u32 rel) -{ -#ifdef CONFIG_CPU_HAS_NO_UNALIGNED - return copy_to_user(rp, &addr, 4) ? -EFAULT : 0; -#else - return put_user(addr, rp); -#endif -} +#include #define FLAT_PLAT_INIT(regs) \ do { \ diff --git a/include/asm-generic/flat.h b/include/asm-generic/flat.h new file mode 100644 index 000000000000..fcd2b45c0735 --- /dev/null +++ b/include/asm-generic/flat.h @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_FLAT_H +#define _ASM_GENERIC_FLAT_H + +#include + +static inline int flat_get_addr_from_rp(u32 __user *rp, u32 relval, u32 flags, + u32 *addr, u32 *persistent) +{ +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS + return copy_from_user(addr, rp, 4) ? -EFAULT : 0; +#else + return get_user(*addr, rp); +#endif +} + +static inline int flat_put_addr_at_rp(u32 __user *rp, u32 addr, u32 rel) +{ +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS + return copy_to_user(rp, &addr, 4) ? -EFAULT : 0; +#else + return put_user(addr, rp); +#endif +} + +#endif /* _ASM_GENERIC_FLAT_H */ -- cgit v1.2.3-59-g8ed1b From 6843d8aa5b9bc61df8787801f19f538123724bfa Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Thu, 13 Jun 2019 09:09:00 +0200 Subject: binfmt_flat: remove the persistent argument from flat_get_addr_from_rp The argument is never used. Signed-off-by: Christoph Hellwig Signed-off-by: Greg Ungerer --- arch/c6x/include/asm/flat.h | 2 +- arch/h8300/include/asm/flat.h | 2 +- arch/microblaze/include/asm/flat.h | 2 +- arch/sh/include/asm/flat.h | 2 +- arch/xtensa/include/asm/flat.h | 2 +- fs/binfmt_flat.c | 4 +--- include/asm-generic/flat.h | 2 +- 7 files changed, 7 insertions(+), 9 deletions(-) (limited to 'arch') diff --git a/arch/c6x/include/asm/flat.h b/arch/c6x/include/asm/flat.h index 2d57a9204d21..9e6544b51386 100644 --- a/arch/c6x/include/asm/flat.h +++ b/arch/c6x/include/asm/flat.h @@ -5,7 +5,7 @@ #include static inline int flat_get_addr_from_rp(u32 __user *rp, u32 relval, u32 flags, - u32 *addr, u32 *persistent) + u32 *addr) { *addr = get_unaligned((__force u32 *)rp); return 0; diff --git a/arch/h8300/include/asm/flat.h b/arch/h8300/include/asm/flat.h index 4683146f0e9e..78070f924177 100644 --- a/arch/h8300/include/asm/flat.h +++ b/arch/h8300/include/asm/flat.h @@ -17,7 +17,7 @@ #define flat_get_relocate_addr(rel) (rel & ~0x00000001) static inline int flat_get_addr_from_rp(u32 __user *rp, u32 relval, u32 flags, - u32 *addr, u32 *persistent) + u32 *addr) { u32 val = get_unaligned((__force u32 *)rp); if (!(flags & FLAT_FLAG_GOTPIC)) diff --git a/arch/microblaze/include/asm/flat.h b/arch/microblaze/include/asm/flat.h index 9e3d8e01d294..1ab86770eaee 100644 --- a/arch/microblaze/include/asm/flat.h +++ b/arch/microblaze/include/asm/flat.h @@ -28,7 +28,7 @@ */ static inline int flat_get_addr_from_rp(u32 __user *rp, u32 relval, u32 flags, - u32 *addr, u32 *persistent) + u32 *addr) { u32 *p = (__force u32 *)rp; diff --git a/arch/sh/include/asm/flat.h b/arch/sh/include/asm/flat.h index 1002343dd84a..fee4f25555cb 100644 --- a/arch/sh/include/asm/flat.h +++ b/arch/sh/include/asm/flat.h @@ -12,7 +12,7 @@ #include static inline int flat_get_addr_from_rp(u32 __user *rp, u32 relval, u32 flags, - u32 *addr, u32 *persistent) + u32 *addr) { *addr = get_unaligned((__force u32 *)rp); return 0; diff --git a/arch/xtensa/include/asm/flat.h b/arch/xtensa/include/asm/flat.h index 3d357371b28b..ed5870c779f9 100644 --- a/arch/xtensa/include/asm/flat.h +++ b/arch/xtensa/include/asm/flat.h @@ -5,7 +5,7 @@ #include static inline int flat_get_addr_from_rp(u32 __user *rp, u32 relval, u32 flags, - u32 *addr, u32 *persistent) + u32 *addr) { *addr = get_unaligned((__force u32 *)rp); return 0; diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c index 1e88f4e62e65..0ca65d51bb01 100644 --- a/fs/binfmt_flat.c +++ b/fs/binfmt_flat.c @@ -795,7 +795,6 @@ static int load_flat_file(struct linux_binprm *bprm, * __start to address 4 so that is okay). */ if (rev > OLD_FLAT_VERSION) { - u32 __maybe_unused persistent = 0; for (i = 0; i < relocs; i++) { u32 addr, relval; __be32 tmp; @@ -816,8 +815,7 @@ static int load_flat_file(struct linux_binprm *bprm, } /* Get the pointer's value. */ - ret = flat_get_addr_from_rp(rp, relval, flags, - &addr, &persistent); + ret = flat_get_addr_from_rp(rp, relval, flags, &addr); if (unlikely(ret)) goto err; diff --git a/include/asm-generic/flat.h b/include/asm-generic/flat.h index fcd2b45c0735..1928a3596938 100644 --- a/include/asm-generic/flat.h +++ b/include/asm-generic/flat.h @@ -5,7 +5,7 @@ #include static inline int flat_get_addr_from_rp(u32 __user *rp, u32 relval, u32 flags, - u32 *addr, u32 *persistent) + u32 *addr) { #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS return copy_from_user(addr, rp, 4) ? -EFAULT : 0; -- cgit v1.2.3-59-g8ed1b From ad97f9df0fee4ddc9ef056dda4dcbc6630d9f972 Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Thu, 13 Jun 2019 09:09:03 +0200 Subject: riscv: add binfmt_flat support Just use the generic definitions. Signed-off-by: Christoph Hellwig Signed-off-by: Greg Ungerer --- arch/riscv/Kconfig | 1 + arch/riscv/include/asm/Kbuild | 1 + 2 files changed, 2 insertions(+) (limited to 'arch') diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 0c4b12205632..2c19baa8d6c3 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -17,6 +17,7 @@ config RISCV select OF select OF_EARLY_FLATTREE select OF_IRQ + select ARCH_HAS_BINFMT_FLAT select ARCH_WANT_FRAME_POINTERS select CLONE_BACKWARDS select COMMON_CLK diff --git a/arch/riscv/include/asm/Kbuild b/arch/riscv/include/asm/Kbuild index 5ee646619cc3..1efaeddf1e4b 100644 --- a/arch/riscv/include/asm/Kbuild +++ b/arch/riscv/include/asm/Kbuild @@ -5,6 +5,7 @@ generic-y += compat.h generic-y += device.h generic-y += div64.h generic-y += extable.h +generic-y += flat.h generic-y += dma.h generic-y += dma-contiguous.h generic-y += dma-mapping.h -- cgit v1.2.3-59-g8ed1b