Skip to contentSkip to conversation

binfmt_flat cleanups and RISC-V support

PATCH In review Christoph Hellwig 5 participants 38 messages Jun 10, 2019 – Jun 11, 2019

Subsystems (9)
Arm (32-bit) VFS RISC-V SuperH +5 more subsystems
lore
Share & tools
lore
#0 lore raw

Hi Greg,

below is a larger stash of cleanups for the binfmt_misc code, preparing for the last patch that now trivially adds RISC-V support, which will be used for the RISC-V nommu series I am about to post.

#1 lore raw

PATCH 1/15 binfmt_flat: remove flat_reloc_valid

This helper is the same for all architectures, open code it in the only caller.

---
 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 -
 fs/binfmt_flat.c                   | 2 +-
 8 files changed, 1 insertion(+), 8 deletions(-)
arch/arm/include/asm/flat.h +0 -1
index f0c75ddeea23..10cce9ecf151 100644
@@ -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)
arch/c6x/include/asm/flat.h +0 -1
index 76fd0bb962a3..ecc6aea6606c 100644
@@ -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)
 {
arch/h8300/include/asm/flat.h +0 -1
index f4cdfcbdd2ba..dcc7775115dd 100644
@@ -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
 
 /*
arch/m68k/include/asm/flat.h +0 -1
index 4f1d1e373420..a631caf5e18f 100644
@@ -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)
 {
arch/microblaze/include/asm/flat.h +0 -1
index 3d2747d4c967..34be5ed011be 100644
@@ -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
 
 /*
arch/sh/include/asm/flat.h +0 -1
index 843d458b8329..8f2929b32f2e 100644
@@ -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)
 {
arch/xtensa/include/asm/flat.h +0 -1
index b8532d7877b3..6ee5a35eb0ec 100644
@@ -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)
 {
fs/binfmt_flat.c +1 -1
index 82a48e830018..afddea583999 100644
@@ -345,7 +345,7 @@ calc_reloc(unsigned long r, struct lib_info *p, int curid, int internalp)
 	start_code = p->lib_list[id].start_code;
 	text_len = p->lib_list[id].text_len;
 
-	if (!flat_reloc_valid(r, start_brk - start_data + text_len)) {
+	if (r > start_brk - start_data + text_len) {
 		pr_err("reloc outside program 0x%lx (0 - 0x%lx/0x%lx)",
 		       r, start_brk-start_data+text_len, text_len);
 		goto failed;
Signature · 1 line
2.20.1
Tested-by Reviewed-by on v1 1/15
#2 lore raw

Re: [PATCH 01/15] binfmt_flat: remove flat_reloc_valid

Quoted 4 lines · Christoph Hellwig

This helper is the same for all architectures, open code it in the only caller.

Quoted 10 lines
---
 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 -
 fs/binfmt_flat.c                   | 2 +-
 8 files changed, 1 insertion(+), 8 deletions(-)

For ARM bits:

Quoted 99 lines
arch/arm/include/asm/flat.h +0 -1
index f0c75ddeea23..10cce9ecf151 100644
@@ -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)
arch/c6x/include/asm/flat.h +0 -1
index 76fd0bb962a3..ecc6aea6606c 100644
@@ -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)
 {
arch/h8300/include/asm/flat.h +0 -1
index f4cdfcbdd2ba..dcc7775115dd 100644
@@ -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
 
 /*
arch/m68k/include/asm/flat.h +0 -1
index 4f1d1e373420..a631caf5e18f 100644
@@ -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)
 {
arch/microblaze/include/asm/flat.h +0 -1
index 3d2747d4c967..34be5ed011be 100644
@@ -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
 
 /*
arch/sh/include/asm/flat.h +0 -1
index 843d458b8329..8f2929b32f2e 100644
@@ -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)
 {
arch/xtensa/include/asm/flat.h +0 -1
index b8532d7877b3..6ee5a35eb0ec 100644
@@ -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)
 {
fs/binfmt_flat.c +1 -1
index 82a48e830018..afddea583999 100644
@@ -345,7 +345,7 @@ calc_reloc(unsigned long r, struct lib_info *p, int curid, int internalp)
 	start_code = p->lib_list[id].start_code;
 	text_len = p->lib_list[id].text_len;
 
-	if (!flat_reloc_valid(r, start_brk - start_data + text_len)) {
+	if (r > start_brk - start_data + text_len) {
 		pr_err("reloc outside program 0x%lx (0 - 0x%lx/0x%lx)",
 		       r, start_brk-start_data+text_len, text_len);
 		goto failed;
#3 lore raw

PATCH 2/15 binfmt_flat: remove flat_set_persistent

In reply to Christoph Hellwig

This helper is a no-op on all architectures, remove it.

---
 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(-)
arch/arm/include/asm/flat.h +0 -1
index 10cce9ecf151..576241d74704 100644
@@ -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__ */
arch/c6x/include/asm/flat.h +0 -1
index ecc6aea6606c..ac87368efad1 100644
@@ -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 */
arch/h8300/include/asm/flat.h +0 -1
index dcc7775115dd..7ef7eefded3d 100644
@@ -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
arch/m68k/include/asm/flat.h +0 -5
index a631caf5e18f..955617bb937b 100644
@@ -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) \
arch/microblaze/include/asm/flat.h +0 -1
index 34be5ed011be..846084fa7f04 100644
@@ -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
arch/sh/include/asm/flat.h +0 -1
index 8f2929b32f2e..6f3b18679a98 100644
@@ -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; \
arch/xtensa/include/asm/flat.h +0 -1
index 6ee5a35eb0ec..b1bc0d9a8d4e 100644
@@ -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 */
fs/binfmt_flat.c +0 -2
index afddea583999..a4c0b245ab1f 100644
@@ -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) {
Signature · 1 line
2.20.1
Tested-by Reviewed-by on v1 2/15
#4 lore raw

Re: [PATCH 02/15] binfmt_flat: remove flat_set_persistent

Quoted 14 lines · Christoph Hellwig

This helper is a no-op on all architectures, remove it.

---
 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(-)

For ARM bits:

Quoted 99 lines
arch/arm/include/asm/flat.h +0 -1
index 10cce9ecf151..576241d74704 100644
@@ -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__ */
arch/c6x/include/asm/flat.h +0 -1
index ecc6aea6606c..ac87368efad1 100644
@@ -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 */
arch/h8300/include/asm/flat.h +0 -1
index dcc7775115dd..7ef7eefded3d 100644
@@ -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
arch/m68k/include/asm/flat.h +0 -5
index a631caf5e18f..955617bb937b 100644
@@ -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) \
arch/microblaze/include/asm/flat.h +0 -1
index 34be5ed011be..846084fa7f04 100644
@@ -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
arch/sh/include/asm/flat.h +0 -1
index 8f2929b32f2e..6f3b18679a98 100644
@@ -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; \
arch/xtensa/include/asm/flat.h +0 -1
index 6ee5a35eb0ec..b1bc0d9a8d4e 100644
@@ -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 */
fs/binfmt_flat.c +0 -2
index afddea583999..a4c0b245ab1f 100644
@@ -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) {
#5 lore raw

PATCH 3/15 binfmt_flat: provide a default version of flat_get_relocate_addr

In reply to Christoph Hellwig

This way only the two architectures that do masking need to provide the helper.

---
 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(-)
arch/arm/include/asm/flat.h +0 -2
index 576241d74704..a185fe023b60 100644
@@ -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__ */
arch/c6x/include/asm/flat.h +0 -1
index ac87368efad1..c4d703b454c6 100644
@@ -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 */
arch/m68k/include/asm/flat.h +0 -1
index 955617bb937b..217fa89c8e34 100644
@@ -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 { \
arch/sh/include/asm/flat.h +0 -1
index 6f3b18679a98..0d520b4cc5ea 100644
@@ -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; \
arch/xtensa/include/asm/flat.h +0 -1
index b1bc0d9a8d4e..a1d88aa3ef8a 100644
@@ -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 */
fs/binfmt_flat.c +4 -0
index a4c0b245ab1f..c0e4535dc1ec 100644
@@ -43,6 +43,10 @@
 #include <asm/cacheflush.h>
 #include <asm/page.h>
 
+#ifndef flat_get_relocate_addr
+#define flat_get_relocate_addr(rel)	(rel)
+#endif
+
 /****************************************************************************/
 
 /*
Signature · 1 line
2.20.1
Tested-by Reviewed-by on v1 3/15
#6 lore raw

Re: [PATCH 03/15] binfmt_flat: provide a default version of flat_get_relocate_addr

Quoted 4 lines · Christoph Hellwig

This way only the two architectures that do masking need to provide the helper.

Quoted 8 lines
---
 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(-)

For ARM bits:

Quoted 74 lines
arch/arm/include/asm/flat.h +0 -2
index 576241d74704..a185fe023b60 100644
@@ -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__ */
arch/c6x/include/asm/flat.h +0 -1
index ac87368efad1..c4d703b454c6 100644
@@ -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 */
arch/m68k/include/asm/flat.h +0 -1
index 955617bb937b..217fa89c8e34 100644
@@ -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 { \
arch/sh/include/asm/flat.h +0 -1
index 6f3b18679a98..0d520b4cc5ea 100644
@@ -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; \
arch/xtensa/include/asm/flat.h +0 -1
index b1bc0d9a8d4e..a1d88aa3ef8a 100644
@@ -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 */
fs/binfmt_flat.c +4 -0
index a4c0b245ab1f..c0e4535dc1ec 100644
@@ -43,6 +43,10 @@
 #include <asm/cacheflush.h>
 #include <asm/page.h>
 
+#ifndef flat_get_relocate_addr
+#define flat_get_relocate_addr(rel)	(rel)
+#endif
+
 /****************************************************************************/
 
 /*
#7 lore raw

PATCH 4/15 binfmt_flat: remove flat_old_ram_flag

In reply to Christoph Hellwig

Instead add a Kconfig variable that only h8300 selects.

---
 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(-)
arch/arm/include/asm/flat.h +0 -1
index a185fe023b60..acf162111ee2 100644
@@ -9,7 +9,6 @@
 #include <linux/uaccess.h>
 
 #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)
arch/c6x/include/asm/flat.h +0 -1
index c4d703b454c6..353e4d06e8c0 100644
@@ -5,7 +5,6 @@
 #include <asm/unaligned.h>
 
 #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)
 {
arch/h8300/Kconfig +1 -0
index ecfc4b4b6373..d30e8727b02d 100644
@@ -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
arch/h8300/include/asm/flat.h +0 -1
index 7ef7eefded3d..14cc928d5478 100644
@@ -9,7 +9,6 @@
 #include <asm/unaligned.h>
 
 #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
arch/m68k/include/asm/flat.h +0 -1
index 217fa89c8e34..7b1fb5c2809e 100644
@@ -9,7 +9,6 @@
 #include <linux/uaccess.h>
 
 #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)
 {
arch/microblaze/include/asm/flat.h +0 -1
index 846084fa7f04..1cd8d7f4cf12 100644
@@ -14,7 +14,6 @@
 #include <asm/unaligned.h>
 
 #define	flat_argvp_envp_on_stack()	0
-#define	flat_old_ram_flag(flags)	(flags)
 
 /*
  * Microblaze works a little differently from other arches, because
arch/sh/include/asm/flat.h +0 -1
index 0d520b4cc5ea..015678d7b771 100644
@@ -12,7 +12,6 @@
 #include <asm/unaligned.h>
 
 #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)
 {
arch/xtensa/include/asm/flat.h +0 -1
index a1d88aa3ef8a..b215c1e66958 100644
@@ -5,7 +5,6 @@
 #include <asm/unaligned.h>
 
 #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)
 {
fs/Kconfig.binfmt +3 -0
index f87ddd1b6d72..5658e12ad944 100644
@@ -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
fs/binfmt_flat.c +2 -1
index c0e4535dc1ec..18d82fd5f57c 100644
@@ -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 (IS_ENABLED(CONFIG_BINFMT_FLAT_OLD_ALWAYS_RAM) &&
+	    rev = OLD_FLAT_VERSION)
 		flags = FLAT_FLAG_RAM;
 
 #ifndef CONFIG_BINFMT_ZFLAT
Signature · 1 line
2.20.1
#8 lore raw

Re: [PATCH 04/15] binfmt_flat: remove flat_old_ram_flag

Hi Christoph,

Quoted 131 lines · Christoph Hellwig

Instead add a Kconfig variable that only h8300 selects.

---
  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(-)
arch/arm/include/asm/flat.h +0 -1
index a185fe023b60..acf162111ee2 100644
@@ -9,7 +9,6 @@
  #include <linux/uaccess.h>
 
  #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)
arch/c6x/include/asm/flat.h +0 -1
index c4d703b454c6..353e4d06e8c0 100644
@@ -5,7 +5,6 @@
  #include <asm/unaligned.h>
 
  #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)
  {
arch/h8300/Kconfig +1 -0
index ecfc4b4b6373..d30e8727b02d 100644
@@ -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
arch/h8300/include/asm/flat.h +0 -1
index 7ef7eefded3d..14cc928d5478 100644
@@ -9,7 +9,6 @@
  #include <asm/unaligned.h>
 
  #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
arch/m68k/include/asm/flat.h +0 -1
index 217fa89c8e34..7b1fb5c2809e 100644
@@ -9,7 +9,6 @@
  #include <linux/uaccess.h>
 
  #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)
  {
arch/microblaze/include/asm/flat.h +0 -1
index 846084fa7f04..1cd8d7f4cf12 100644
@@ -14,7 +14,6 @@
  #include <asm/unaligned.h>
 
  #define	flat_argvp_envp_on_stack()	0
-#define	flat_old_ram_flag(flags)	(flags)
 
  /*
   * Microblaze works a little differently from other arches, because
arch/sh/include/asm/flat.h +0 -1
index 0d520b4cc5ea..015678d7b771 100644
@@ -12,7 +12,6 @@
  #include <asm/unaligned.h>
 
  #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)
  {
arch/xtensa/include/asm/flat.h +0 -1
index a1d88aa3ef8a..b215c1e66958 100644
@@ -5,7 +5,6 @@
  #include <asm/unaligned.h>
 
  #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)
  {
fs/Kconfig.binfmt +3 -0
index f87ddd1b6d72..5658e12ad944 100644
@@ -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
fs/binfmt_flat.c +0 -0
index c0e4535dc1ec..18d82fd5f57c 100644

fs/binfmt_flat.c static int load_flat_file(struct linux_binprm *bprm, · line 492

Quoted 6 lines
fs/binfmt_flat.c +2 -1
@@ -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 (IS_ENABLED(CONFIG_BINFMT_FLAT_OLD_ALWAYS_RAM) &&
+	    rev = OLD_FLAT_VERSION)

The flags are from the binary file header here, so this is going to lose that check for most platforms (except h8300 where it would always have been true).

Regards
Greg

#9 lore raw

Re: [PATCH 04/15] binfmt_flat: remove flat_old_ram_flag

Quoted 6 lines · Greg Ungerer
Quoted 6 lines

index c0e4535dc1ec..18d82fd5f57c 100644

fs/binfmt_flat.c +0 -0
@@ -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
Quoted 8 lines

fs/binfmt_flat.c static int load_flat_file(struct linux_binprm *bprm, · line 492

Quoted 4 lines
fs/binfmt_flat.c +2 -1
  	 */
-	if (rev = OLD_FLAT_VERSION && flat_old_ram_flag(flags))
+	if (IS_ENABLED(CONFIG_BINFMT_FLAT_OLD_ALWAYS_RAM) &&
+	    rev = OLD_FLAT_VERSION)

The flags are from the binary file header here, so this is going to lose that check for most platforms (except h8300 where it would always have been true).

Indeed. The old code is:

	if (rev = OLD_FLAT_VERSION && flat_old_ram_flag(flags))
		flags = FLAT_FLAG_RAM;

which for !h8300 evaluates to:

	if (rev = OLD_FLAT_VERSION && flags)
		flags = FLAT_FLAG_RAM;

so basically if any flag was set it was turned into FLAT_FLAG_RAM. Was that really intentional? I guess even if it wasn't the is no point in changing this historic behavior now.

So I guess what we could do it something like:

	if (rev = OLD_FLAT_VERSION &&
	    (flags || IS_ENABLED(CONFIG_BINFMT_FLAT_OLD_ALWAYS_RAM)))
		flags = FLAT_FLAG_RAM;
#10 lore raw

Re: [PATCH 04/15] binfmt_flat: remove flat_old_ram_flag

Quoted 21 lines · Christoph Hellwig
Quoted 6 lines · Greg Ungerer
Quoted 6 lines

index c0e4535dc1ec..18d82fd5f57c 100644

fs/binfmt_flat.c +0 -0
@@ -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
Quoted 8 lines

fs/binfmt_flat.c static int load_flat_file(struct linux_binprm *bprm, · line 492

Quoted 4 lines
fs/binfmt_flat.c +2 -1
   	 */
-	if (rev = OLD_FLAT_VERSION && flat_old_ram_flag(flags))
+	if (IS_ENABLED(CONFIG_BINFMT_FLAT_OLD_ALWAYS_RAM) &&
+	    rev = OLD_FLAT_VERSION)

The flags are from the binary file header here, so this is going to lose that check for most platforms (except h8300 where it would always have been true).

Indeed. The old code is:

	if (rev = OLD_FLAT_VERSION && flat_old_ram_flag(flags))
		flags = FLAT_FLAG_RAM;
Quoted 7 lines

which for !h8300 evaluates to:

	if (rev = OLD_FLAT_VERSION && flags)
		flags = FLAT_FLAG_RAM;

so basically if any flag was set it was turned into FLAT_FLAG_RAM. Was that really intentional?

Probably not, looking at the flags. For the compressed flag it makes some sense. But I don't think many of the others need load to RAM behavior.

Quoted 8 lines

I guess even if it wasn't the is no
point in changing this historic behavior now.

So I guess what we could do it something like:

	if (rev = OLD_FLAT_VERSION &&
	    (flags || IS_ENABLED(CONFIG_BINFMT_FLAT_OLD_ALWAYS_RAM)))
		flags = FLAT_FLAG_RAM;

Yeah, that to looks to preserve the old behavior.

Regards
Greg

Tested-by Reviewed-by on v1 4/15
#11 lore raw

Re: [PATCH 04/15] binfmt_flat: remove flat_old_ram_flag

In reply to Christoph Hellwig
Quoted 16 lines · Christoph Hellwig

Instead add a Kconfig variable that only h8300 selects.

---
 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(-)

For ARM bits:

Quoted 125 lines
arch/arm/include/asm/flat.h +0 -1
index a185fe023b60..acf162111ee2 100644
@@ -9,7 +9,6 @@
 #include <linux/uaccess.h>
 
 #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)
arch/c6x/include/asm/flat.h +0 -1
index c4d703b454c6..353e4d06e8c0 100644
@@ -5,7 +5,6 @@
 #include <asm/unaligned.h>
 
 #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)
 {
arch/h8300/Kconfig +1 -0
index ecfc4b4b6373..d30e8727b02d 100644
@@ -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
arch/h8300/include/asm/flat.h +0 -1
index 7ef7eefded3d..14cc928d5478 100644
@@ -9,7 +9,6 @@
 #include <asm/unaligned.h>
 
 #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
arch/m68k/include/asm/flat.h +0 -1
index 217fa89c8e34..7b1fb5c2809e 100644
@@ -9,7 +9,6 @@
 #include <linux/uaccess.h>
 
 #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)
 {
arch/microblaze/include/asm/flat.h +0 -1
index 846084fa7f04..1cd8d7f4cf12 100644
@@ -14,7 +14,6 @@
 #include <asm/unaligned.h>
 
 #define	flat_argvp_envp_on_stack()	0
-#define	flat_old_ram_flag(flags)	(flags)
 
 /*
  * Microblaze works a little differently from other arches, because
arch/sh/include/asm/flat.h +0 -1
index 0d520b4cc5ea..015678d7b771 100644
@@ -12,7 +12,6 @@
 #include <asm/unaligned.h>
 
 #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)
 {
arch/xtensa/include/asm/flat.h +0 -1
index a1d88aa3ef8a..b215c1e66958 100644
@@ -5,7 +5,6 @@
 #include <asm/unaligned.h>
 
 #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)
 {
fs/Kconfig.binfmt +3 -0
index f87ddd1b6d72..5658e12ad944 100644
@@ -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
fs/binfmt_flat.c +2 -1
index c0e4535dc1ec..18d82fd5f57c 100644
@@ -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 (IS_ENABLED(CONFIG_BINFMT_FLAT_OLD_ALWAYS_RAM) &&
+	    rev = OLD_FLAT_VERSION)
 		flags = FLAT_FLAG_RAM;
 
 #ifndef CONFIG_BINFMT_ZFLAT
#12 lore raw

PATCH 5/15 binfmt_flat: replace flat_argvp_envp_on_stack with a Kconfig variable

In reply to Christoph Hellwig

This will eventually allow us to kill the need for an <asm/flat.h> for many cases.

---
 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(-)
arch/arm/Kconfig +1 -0
index 8869742a85df..b1b48c0bde76 100644
@@ -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
arch/arm/include/asm/flat.h +0 -2
index acf162111ee2..bbc27901446f 100644
@@ -8,8 +8,6 @@
 
 #include <linux/uaccess.h>
 
-#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)
 {
arch/c6x/include/asm/flat.h +0 -1
index 353e4d06e8c0..2d57a9204d21 100644
@@ -4,7 +4,6 @@
 
 #include <asm/unaligned.h>
 
-#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)
 {
arch/h8300/Kconfig +1 -0
index d30e8727b02d..7457f190caaa 100644
@@ -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
arch/h8300/include/asm/flat.h +0 -2
index 14cc928d5478..4683146f0e9e 100644
@@ -8,8 +8,6 @@
 
 #include <asm/unaligned.h>
 
-#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
arch/m68k/Kconfig +1 -0
index 218e037ef901..fd69ee5ad6ab 100644
@@ -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
arch/m68k/include/asm/flat.h +0 -1
index 7b1fb5c2809e..d7102fcd43eb 100644
@@ -8,7 +8,6 @@
 
 #include <linux/uaccess.h>
 
-#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)
 {
arch/microblaze/include/asm/flat.h +0 -2
index 1cd8d7f4cf12..9e3d8e01d294 100644
@@ -13,8 +13,6 @@
 
 #include <asm/unaligned.h>
 
-#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
arch/sh/include/asm/flat.h +0 -1
index 015678d7b771..1002343dd84a 100644
@@ -11,7 +11,6 @@
 
 #include <asm/unaligned.h>
 
-#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)
 {
arch/xtensa/include/asm/flat.h +0 -1
index b215c1e66958..3d357371b28b 100644
@@ -4,7 +4,6 @@
 
 #include <asm/unaligned.h>
 
-#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)
 {
fs/Kconfig.binfmt +3 -0
index 5658e12ad944..82f7d7f234f3 100644
@@ -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
 
fs/binfmt_flat.c +3 -2
index 18d82fd5f57c..c09651087eda 100644
@@ -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);
Signature · 1 line
2.20.1
Tested-by Reviewed-by on v1 5/15
#13 lore raw

Re: [PATCH 05/15] binfmt_flat: replace flat_argvp_envp_on_stack with a Kconfig variable

T24gNi8xMC8xOSAxMDoyMCBQTSwgQ2hyaXN0b3BoIEhlbGx3aWcgd3JvdGU6DQo+IFRoaXMgd2ls bCBldmVudHVhbGx5IGFsbG93IHVzIHRvIGtpbGwgdGhlIG5lZWQgZm9yIGFuIDxhc20vZmxhdC5o PiBmb3INCj4gbWFueSBjYXNlcy4NCj4NCj4gU2lnbmVkLW9mZi1ieTogQ2hyaXN0b3BoIEhlbGx3 aWcgPGhjaEBsc3QuZGU+DQo+IC0tLQ0KPiAgYXJjaC9hcm0vS2NvbmZpZyAgICAgICAgICAgICAg ICAgICB8IDEgKw0KPiAgYXJjaC9hcm0vaW5jbHVkZS9hc20vZmxhdC5oICAgICAgICB8IDIgLS0N Cj4gIGFyY2gvYzZ4L2luY2x1ZGUvYXNtL2ZsYXQuaCAgICAgICAgfCAxIC0NCj4gIGFyY2gvaDgz MDAvS2NvbmZpZyAgICAgICAgICAgICAgICAgfCAxICsNCj4gIGFyY2gvaDgzMDAvaW5jbHVkZS9h c20vZmxhdC5oICAgICAgfCAyIC0tDQo+ICBhcmNoL202OGsvS2NvbmZpZyAgICAgICAgICAgICAg ICAgIHwgMSArDQo+ICBhcmNoL202OGsvaW5jbHVkZS9hc20vZmxhdC5oICAgICAgIHwgMSAtDQo+ ICBhcmNoL21pY3JvYmxhemUvaW5jbHVkZS9hc20vZmxhdC5oIHwgMiAtLQ0KPiAgYXJjaC9zaC9p bmNsdWRlL2FzbS9mbGF0LmggICAgICAgICB8IDEgLQ0KPiAgYXJjaC94dGVuc2EvaW5jbHVkZS9h c20vZmxhdC5oICAgICB8IDEgLQ0KPiAgZnMvS2NvbmZpZy5iaW5mbXQgICAgICAgICAgICAgICAg ICB8IDMgKysrDQo+ICBmcy9iaW5mbXRfZmxhdC5jICAgICAgICAgICAgICAgICA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GTVRfRkxBVF9BUkdWUF9FTlZQX09OX1NUQUNLKSkgew0KPiAgdW5zaWduZWQg bG9uZyBhcmd2LCBlbnZwOw0KPiAgYXJndiA9ICh1bnNpZ25lZCBsb25nKShzcCArIDIpOw0KPiAg ZW52cCA9ICh1bnNpZ25lZCBsb25nKShzcCArIDIgKyBicHJtLT5hcmdjICsgMSk7DQo+DQoNCklN UE9SVEFOVCBOT1RJQ0U6IFRoZSBjb250ZW50cyBvZiB0aGlzIGVtYWlsIGFuZCBhbnkgYXR0YWNo bWVudHMgYXJlIGNvbmZpZGVudGlhbCBhbmQgbWF5IGFsc28gYmUgcHJpdmlsZWdlZC4gSWYgeW91 IGFyZSBub3QgdGhlIGludGVuZGVkIHJlY2lwaWVudCwgcGxlYXNlIG5vdGlmeSB0aGUgc2VuZGVy IGltbWVkaWF0ZWx5IGFuZCBkbyBub3QgZGlzY2xvc2UgdGhlIGNvbnRlbnRzIHRvIGFueSBvdGhl ciBwZXJzb24sIHVzZSBpdCBmb3IgYW55IHB1cnBvc2UsIG9yIHN0b3JlIG9yIGNvcHkgdGhlIGlu Zm9ybWF0aW9uIGluIGFueSBtZWRpdW0uIFRoYW5rIHlvdS4NCg=

#14 lore raw

PATCH 6/15 binfmt_flat: remove the uapi <linux/flat.h> header

In reply to Christoph Hellwig

The split between the two flat.h files is completely arbitrary, and the uapi version even contains CONFIG_ ifdefs that can't work in userspace. The only userspace program known to use the header is elf2flt, and it ships with its own version of the combined header.

Use the chance to move the <asm/flat.h> inclusion out of this file, as it is in no way needed for the format defintion, but just for the binfmt implementation.

---
 fs/binfmt_flat.c          |  1 +
 include/linux/flat.h      | 45 ++++++++++++++++++++++++++---
 include/uapi/linux/flat.h | 59 ---------------------------------------
 3 files changed, 42 insertions(+), 63 deletions(-)
 delete mode 100644 include/uapi/linux/flat.h
fs/binfmt_flat.c +1 -0
index c09651087eda..6ae0f9af3fc9 100644
@@ -42,6 +42,7 @@
 #include <asm/unaligned.h>
 #include <asm/cacheflush.h>
 #include <asm/page.h>
+#include <asm/flat.h>
 
 #ifndef flat_get_relocate_addr
 #define flat_get_relocate_addr(rel)	(rel)
include/linux/flat.h +41 -4

57 lines not on this page · raw message

include/uapi/linux/flat.h deleted +0 -59

59 lines not on this page · raw message

Signature · 1 line
2.20.1
Reviewed-by on v1 6/15
#15 lore raw

Re: [PATCH 06/15] binfmt_flat: remove the uapi <linux/flat.h> header

Quoted 9 lines · Christoph Hellwig

The split between the two flat.h files is completely arbitrary, and the uapi version even contains CONFIG_ ifdefs that can't work in userspace. The only userspace program known to use the header is elf2flt, and it ships with its own version of the combined header.

Use the chance to move the <asm/flat.h> inclusion out of this file, as it is in no way needed for the format defintion, but just for the binfmt implementation.

Quoted 7 lines
---
 fs/binfmt_flat.c          |  1 +
 include/linux/flat.h      | 45 ++++++++++++++++++++++++++---
 include/uapi/linux/flat.h | 59 ---------------------------------------
 3 files changed, 42 insertions(+), 63 deletions(-)
 delete mode 100644 include/uapi/linux/flat.h

FWIW:

Quoted 142 lines
fs/binfmt_flat.c +1 -0
index c09651087eda..6ae0f9af3fc9 100644
@@ -42,6 +42,7 @@
 #include <asm/unaligned.h>
 #include <asm/cacheflush.h>
 #include <asm/page.h>
+#include <asm/flat.h>
 
 #ifndef flat_get_relocate_addr
 #define flat_get_relocate_addr(rel)	(rel)
include/linux/flat.h +41 -4
index 569b67d64d5c..21d901ba191b 100644
@@ -10,8 +10,47 @@
 #ifndef _LINUX_FLAT_H
 #define _LINUX_FLAT_H
 
-#include <uapi/linux/flat.h>
-#include <asm/flat.h>
+#define	FLAT_VERSION			0x00000004L
+
+#ifdef CONFIG_BINFMT_SHARED_FLAT
+#define	MAX_SHARED_LIBS			(4)
+#else
+#define	MAX_SHARED_LIBS			(1)
+#endif
+
+/*
+ * To make everything easier to port and manage cross platform
+ * development,  all fields are in network byte order.
+ */
+
+struct flat_hdr {
+	char magic[4];
+	unsigned long rev;          /* version (as above) */
+	unsigned long entry;        /* Offset of first executable instruction
+	                               with text segment from beginning of file */
+	unsigned long data_start;   /* Offset of data segment from beginning of
+	                               file */
+	unsigned long data_end;     /* Offset of end of data segment
+	                               from beginning of file */
+	unsigned long bss_end;      /* Offset of end of bss segment from beginning
+	                               of file */
+
+	/* (It is assumed that data_end through bss_end forms the bss segment.) */
+
+	unsigned long stack_size;   /* Size of stack, in bytes */
+	unsigned long reloc_start;  /* Offset of relocation records from
+	                               beginning of file */
+	unsigned long reloc_count;  /* Number of relocation records */
+	unsigned long flags;
+	unsigned long build_date;   /* When the program/library was built */
+	unsigned long filler[5];    /* Reservered, set to zero */
+};
+
+#define FLAT_FLAG_RAM    0x0001 /* load program entirely into RAM */
+#define FLAT_FLAG_GOTPIC 0x0002 /* program is PIC with GOT */
+#define FLAT_FLAG_GZIP   0x0004 /* all but the header is compressed */
+#define FLAT_FLAG_GZDATA 0x0008 /* only data/relocs are compressed (for XIP) */
+#define FLAT_FLAG_KTRACE 0x0010 /* output useful kernel trace for debugging */
 
 /*
  * While it would be nice to keep this header clean,  users of older
@@ -22,8 +61,6 @@
  *        with the format above,  except to fix bugs with old format support.
  */
 
-#include <asm/byteorder.h>
-
 #define	OLD_FLAT_VERSION			0x00000002L
 #define OLD_FLAT_RELOC_TYPE_TEXT	0
 #define OLD_FLAT_RELOC_TYPE_DATA	1
include/uapi/linux/flat.h deleted +0 -59
deleted file mode 100644
index 27e595e44fb7..000000000000
@@ -1,59 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-/*
- * Copyright (C) 2002-2003  David McCullough <[email protected]>
- * Copyright (C) 1998       Kenneth Albanowski <[email protected]>
- *                          The Silver Hammer Group, Ltd.
- *
- * This file provides the definitions and structures needed to
- * support uClinux flat-format executables.
- */
-
-#ifndef _UAPI_LINUX_FLAT_H
-#define _UAPI_LINUX_FLAT_H
-
-
-#define	FLAT_VERSION			0x00000004L
-
-#ifdef CONFIG_BINFMT_SHARED_FLAT
-#define	MAX_SHARED_LIBS			(4)
-#else
-#define	MAX_SHARED_LIBS			(1)
-#endif
-
-/*
- * To make everything easier to port and manage cross platform
- * development,  all fields are in network byte order.
- */
-
-struct flat_hdr {
-	char magic[4];
-	unsigned long rev;          /* version (as above) */
-	unsigned long entry;        /* Offset of first executable instruction
-	                               with text segment from beginning of file */
-	unsigned long data_start;   /* Offset of data segment from beginning of
-	                               file */
-	unsigned long data_end;     /* Offset of end of data segment
-	                               from beginning of file */
-	unsigned long bss_end;      /* Offset of end of bss segment from beginning
-	                               of file */
-
-	/* (It is assumed that data_end through bss_end forms the bss segment.) */
-
-	unsigned long stack_size;   /* Size of stack, in bytes */
-	unsigned long reloc_start;  /* Offset of relocation records from
-	                               beginning of file */
-	unsigned long reloc_count;  /* Number of relocation records */
-	unsigned long flags;       
-	unsigned long build_date;   /* When the program/library was built */
-	unsigned long filler[5];    /* Reservered, set to zero */
-};
-
-#define FLAT_FLAG_RAM    0x0001 /* load program entirely into RAM */
-#define FLAT_FLAG_GOTPIC 0x0002 /* program is PIC with GOT */
-#define FLAT_FLAG_GZIP   0x0004 /* all but the header is compressed */
-#define FLAT_FLAG_GZDATA 0x0008 /* only data/relocs are compressed (for XIP) */
-#define FLAT_FLAG_KTRACE 0x0010 /* output useful kernel trace for debugging */
-
-
-
-#endif /* _UAPI_LINUX_FLAT_H */
#16 lore raw

PATCH 7/15 binfmt_flat: use __be32 for the on-disk format

In reply to Christoph Hellwig

So far binfmt_flat has onl been supported on 32-bit platforms, so the variable size of the fields didn't matter. But the upcoming RISC-V nommu port supports 64-bit CPUs, and we now have a conflict between the elf2flt creation tool that always uses 32-bit fields and the kernel that uses (unsigned) long field. Switch to the userspace view as the rest of the binfmt_flat format is completely architecture neutral, and binfmt_flat isn't the right binary format for huge executables to start with.

While we're at it also ensure these fields are using __be types as they big endian and are byteswapped when loaded.

wip

---
 include/linux/flat.h | 48 ++++++++++++++++++++++----------------------
 1 file changed, 24 insertions(+), 24 deletions(-)
include/linux/flat.h +24 -24
index 21d901ba191b..59e892d5fadb 100644
@@ -24,26 +24,26 @@
  */
 
 struct flat_hdr {
-	char magic[4];
-	unsigned long rev;          /* version (as above) */
-	unsigned long entry;        /* Offset of first executable instruction
-	                               with text segment from beginning of file */
-	unsigned long data_start;   /* Offset of data segment from beginning of
-	                               file */
-	unsigned long data_end;     /* Offset of end of data segment
-	                               from beginning of file */
-	unsigned long bss_end;      /* Offset of end of bss segment from beginning
-	                               of file */
+	char	magic[4];
+	__be32	rev;          /* version (as above) */
+	__be32	entry;        /* Offset of first executable instruction
+				 with text segment from beginning of file */
+	__be32	data_start;   /* Offset of data segment from beginning of
+				 file */
+	__be32	data_end;     /* Offset of end of data segment from beginning
+				 of file */
+	__be32	bss_end;      /* Offset of end of bss segment from beginning
+				 of file */
 
 	/* (It is assumed that data_end through bss_end forms the bss segment.) */
 
-	unsigned long stack_size;   /* Size of stack, in bytes */
-	unsigned long reloc_start;  /* Offset of relocation records from
-	                               beginning of file */
-	unsigned long reloc_count;  /* Number of relocation records */
-	unsigned long flags;
-	unsigned long build_date;   /* When the program/library was built */
-	unsigned long filler[5];    /* Reservered, set to zero */
+	__be32	stack_size;   /* Size of stack, in bytes */
+	__be32	reloc_start;  /* Offset of relocation records from beginning of
+				 file */
+	__be32	reloc_count;  /* Number of relocation records */
+	__be32	flags;
+	__be32	build_date;   /* When the program/library was built */
+	__u32	filler[5];    /* Reservered, set to zero */
 };
 
 #define FLAT_FLAG_RAM    0x0001 /* load program entirely into RAM */
@@ -67,19 +67,19 @@ struct flat_hdr {
 #define OLD_FLAT_RELOC_TYPE_BSS		2
 
 typedef union {
-	unsigned long	value;
+	u32		value;
 	struct {
 # if defined(mc68000) && !defined(CONFIG_COLDFIRE)
-		signed long offset : 30;
-		unsigned long type : 2;
+		s32	offset : 30;
+		u32	type : 2;
 #   	define OLD_FLAT_FLAG_RAM    0x1 /* load program entirely into RAM */
 # elif defined(__BIG_ENDIAN_BITFIELD)
-		unsigned long type : 2;
-		signed long offset : 30;
+		u32	type : 2;
+		s32	offset : 30;
 #   	define OLD_FLAT_FLAG_RAM    0x1 /* load program entirely into RAM */
 # elif defined(__LITTLE_ENDIAN_BITFIELD)
-		signed long offset : 30;
-		unsigned long type : 2;
+		s32	offset : 30;
+		u32	type : 2;
 #   	define OLD_FLAT_FLAG_RAM    0x1 /* load program entirely into RAM */
 # else
 #   	error "Unknown bitfield order for flat files."
Signature · 1 line
2.20.1
#17 lore raw

Re: [PATCH 07/15] binfmt_flat: use __be32 for the on-disk format

Hi Christoph,

Quoted 32 lines · Christoph Hellwig

So far binfmt_flat has onl been supported on 32-bit platforms, so the variable size of the fields didn't matter. But the upcoming RISC-V nommu port supports 64-bit CPUs, and we now have a conflict between the elf2flt creation tool that always uses 32-bit fields and the kernel that uses (unsigned) long field. Switch to the userspace view as the rest of the binfmt_flat format is completely architecture neutral, and binfmt_flat isn't the right binary format for huge executables to start with.

While we're at it also ensure these fields are using __be types as they big endian and are byteswapped when loaded.

include/linux/flat.h +3 -4
@@ -67,19 +67,19 @@ struct flat_hdr {
 #define OLD_FLAT_RELOC_TYPE_BSS                2
 
 typedef union {
-       unsigned long   value;
+       u32             value;
        struct {
 # if defined(mc68000) && !defined(CONFIG_COLDFIRE)
-               signed long offset : 30;
-               unsigned long type : 2;
+               s32     offset : 30;
+               u32     type : 2;
 #      define OLD_FLAT_FLAG_RAM    0x1 /* load program entirely into RAM */
 # elif defined(__BIG_ENDIAN_BITFIELD)
-               unsigned long type : 2;

include/linux/flat.h struct flat_hdr { · line 83

Quoted 10 lines
include/linux/flat.h +4 -3
-               signed long offset : 30;
+               u32     type : 2;
+               s32     offset : 30;
 #      define OLD_FLAT_FLAG_RAM    0x1 /* load program entirely into RAM */
 # elif defined(__LITTLE_ENDIAN_BITFIELD)
-               signed long offset : 30;
-               unsigned long type : 2;
+               s32     offset : 30;
+               u32     type : 2;
 #      define OLD_FLAT_FLAG_RAM    0x1 /* load program entirely into RAM */

The definitions of OLD_FLAT_FLAG_RAM are identical, so could be factored out.
However, they appear to be unused.

include/linux/flat.h struct flat_hdr { · line 85

Quoted 2 lines
include/linux/flat.h +0 -0
 # else
 #      error "Unknown bitfield order for flat files."

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
Reviewed-by on v1 7/15
#18 lore raw

Re: [PATCH 07/15] binfmt_flat: use __be32 for the on-disk format

In reply to Christoph Hellwig
Quoted 1 line · Christoph Hellwig

So far binfmt_flat has onl been supported on 32-bit platforms, so the

			^^^^
			only
Quoted 8 lines

variable size of the fields didn't matter. But the upcoming RISC-V nommu port supports 64-bit CPUs, and we now have a conflict between the elf2flt creation tool that always uses 32-bit fields and the kernel that uses (unsigned) long field. Switch to the userspace view as the rest of the binfmt_flat format is completely architecture neutral, and binfmt_flat isn't the right binary format for huge executables to start with.

Quoted 6 lines

While we're at it also ensure these fields are using __be types as they big endian and are byteswapped when loaded.

wip

^^^
Unintended?

Quoted 3 lines
---
 include/linux/flat.h | 48 ++++++++++++++++++++++----------------------
 1 file changed, 24 insertions(+), 24 deletions(-)

With comment message fixed:

Quoted 77 lines
include/linux/flat.h +24 -24
index 21d901ba191b..59e892d5fadb 100644
@@ -24,26 +24,26 @@
  */
 
 struct flat_hdr {
-	char magic[4];
-	unsigned long rev;          /* version (as above) */
-	unsigned long entry;        /* Offset of first executable instruction
-	                               with text segment from beginning of file */
-	unsigned long data_start;   /* Offset of data segment from beginning of
-	                               file */
-	unsigned long data_end;     /* Offset of end of data segment
-	                               from beginning of file */
-	unsigned long bss_end;      /* Offset of end of bss segment from beginning
-	                               of file */
+	char	magic[4];
+	__be32	rev;          /* version (as above) */
+	__be32	entry;        /* Offset of first executable instruction
+				 with text segment from beginning of file */
+	__be32	data_start;   /* Offset of data segment from beginning of
+				 file */
+	__be32	data_end;     /* Offset of end of data segment from beginning
+				 of file */
+	__be32	bss_end;      /* Offset of end of bss segment from beginning
+				 of file */
 
 	/* (It is assumed that data_end through bss_end forms the bss segment.) */
 
-	unsigned long stack_size;   /* Size of stack, in bytes */
-	unsigned long reloc_start;  /* Offset of relocation records from
-	                               beginning of file */
-	unsigned long reloc_count;  /* Number of relocation records */
-	unsigned long flags;
-	unsigned long build_date;   /* When the program/library was built */
-	unsigned long filler[5];    /* Reservered, set to zero */
+	__be32	stack_size;   /* Size of stack, in bytes */
+	__be32	reloc_start;  /* Offset of relocation records from beginning of
+				 file */
+	__be32	reloc_count;  /* Number of relocation records */
+	__be32	flags;
+	__be32	build_date;   /* When the program/library was built */
+	__u32	filler[5];    /* Reservered, set to zero */
 };
 
 #define FLAT_FLAG_RAM    0x0001 /* load program entirely into RAM */
@@ -67,19 +67,19 @@ struct flat_hdr {
 #define OLD_FLAT_RELOC_TYPE_BSS		2
 
 typedef union {
-	unsigned long	value;
+	u32		value;
 	struct {
 # if defined(mc68000) && !defined(CONFIG_COLDFIRE)
-		signed long offset : 30;
-		unsigned long type : 2;
+		s32	offset : 30;
+		u32	type : 2;
 #   	define OLD_FLAT_FLAG_RAM    0x1 /* load program entirely into RAM */
 # elif defined(__BIG_ENDIAN_BITFIELD)
-		unsigned long type : 2;
-		signed long offset : 30;
+		u32	type : 2;
+		s32	offset : 30;
 #   	define OLD_FLAT_FLAG_RAM    0x1 /* load program entirely into RAM */
 # elif defined(__LITTLE_ENDIAN_BITFIELD)
-		signed long offset : 30;
-		unsigned long type : 2;
+		s32	offset : 30;
+		u32	type : 2;
 #   	define OLD_FLAT_FLAG_RAM    0x1 /* load program entirely into RAM */
 # else
 #   	error "Unknown bitfield order for flat files."
#19 lore raw

PATCH 8/15 binfmt_flat: add endianess annotations

In reply to Christoph Hellwig

Most binfmt_flat on-disk fields are big endian. Use the proper __be32 type where applicable.

---
 fs/binfmt_flat.c | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)
fs/binfmt_flat.c +16 -10
index 6ae0f9af3fc9..6c1848dee724 100644
@@ -421,7 +421,8 @@ static int load_flat_file(struct linux_binprm *bprm,
 	unsigned long textpos, datapos, realdatastart;
 	u32 text_len, data_len, bss_len, stack_len, full_data, flags;
 	unsigned long len, memp, memp_size, extra, rlim;
-	u32 __user *reloc, *rp;
+	__be32 __user *reloc;
+	u32 __user *rp;
 	struct inode *inode;
 	int i, rev, relocs;
 	loff_t fpos;
@@ -594,7 +595,7 @@ static int load_flat_file(struct linux_binprm *bprm,
 			goto err;
 		}
 
-		reloc = (u32 __user *)
+		reloc = (__be32 __user *)
 			(datapos + (ntohl(hdr->reloc_start) - text_len));
 		memp = realdatastart;
 		memp_size = len;
@@ -619,7 +620,7 @@ static int load_flat_file(struct linux_binprm *bprm,
 				MAX_SHARED_LIBS * sizeof(u32),
 				FLAT_DATA_ALIGN);
 
-		reloc = (u32 __user *)
+		reloc = (__be32 __user *)
 			(datapos + (ntohl(hdr->reloc_start) - text_len));
 		memp = textpos;
 		memp_size = len;
@@ -785,15 +786,16 @@ static int load_flat_file(struct linux_binprm *bprm,
 		u32 __maybe_unused persistent = 0;
 		for (i = 0; i < relocs; i++) {
 			u32 addr, relval;
+			__be32 tmp;
 
 			/*
 			 * Get the address of the pointer to be
 			 * relocated (of course, the address has to be
 			 * relocated first).
 			 */
-			if (get_user(relval, reloc + i))
+			if (get_user(tmp, reloc + i))
 				return -EFAULT;
-			relval = ntohl(relval);
+			relval = ntohl(tmp);
 			addr = flat_get_relocate_addr(relval);
 			rp = (u32 __user *)calc_reloc(addr, libinfo, id, 1);
 			if (rp = (u32 __user *)RELOC_FAILED) {
@@ -812,8 +814,13 @@ static int load_flat_file(struct linux_binprm *bprm,
 				 * Do the relocation.  PIC relocs in the data section are
 				 * already in target order
 				 */
-				if ((flags & FLAT_FLAG_GOTPIC) = 0)
-					addr = ntohl(addr);
+				if ((flags & FLAT_FLAG_GOTPIC) = 0) {
+					/*
+					 * Meh, the same value can have a different
+					 * byte order based on a flag..
+					 */
+					addr = ntohl((__force __be32)addr);
+				}
 				addr = calc_reloc(addr, libinfo, id, 0);
 				if (addr = RELOC_FAILED) {
 					ret = -ENOEXEC;
@@ -828,11 +835,10 @@ static int load_flat_file(struct linux_binprm *bprm,
 		}
 	} else {
 		for (i = 0; i < relocs; i++) {
-			u32 relval;
+			__be32 relval;
 			if (get_user(relval, reloc + i))
 				return -EFAULT;
-			relval = ntohl(relval);
-			old_reloc(relval);
+			old_reloc(ntohl(relval));
 		}
 	}
 
Signature · 1 line
2.20.1
Tested-by Reviewed-by on v1 8/15
#20 lore raw

Re: [PATCH 08/15] binfmt_flat: add endianess annotations

Quoted 7 lines · Christoph Hellwig

Most binfmt_flat on-disk fields are big endian. Use the proper __be32 type where applicable.

---
 fs/binfmt_flat.c | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)
Quoted 83 lines
fs/binfmt_flat.c +16 -10
index 6ae0f9af3fc9..6c1848dee724 100644
@@ -421,7 +421,8 @@ static int load_flat_file(struct linux_binprm *bprm,
 	unsigned long textpos, datapos, realdatastart;
 	u32 text_len, data_len, bss_len, stack_len, full_data, flags;
 	unsigned long len, memp, memp_size, extra, rlim;
-	u32 __user *reloc, *rp;
+	__be32 __user *reloc;
+	u32 __user *rp;
 	struct inode *inode;
 	int i, rev, relocs;
 	loff_t fpos;
@@ -594,7 +595,7 @@ static int load_flat_file(struct linux_binprm *bprm,
 			goto err;
 		}
 
-		reloc = (u32 __user *)
+		reloc = (__be32 __user *)
 			(datapos + (ntohl(hdr->reloc_start) - text_len));
 		memp = realdatastart;
 		memp_size = len;
@@ -619,7 +620,7 @@ static int load_flat_file(struct linux_binprm *bprm,
 				MAX_SHARED_LIBS * sizeof(u32),
 				FLAT_DATA_ALIGN);
 
-		reloc = (u32 __user *)
+		reloc = (__be32 __user *)
 			(datapos + (ntohl(hdr->reloc_start) - text_len));
 		memp = textpos;
 		memp_size = len;
@@ -785,15 +786,16 @@ static int load_flat_file(struct linux_binprm *bprm,
 		u32 __maybe_unused persistent = 0;
 		for (i = 0; i < relocs; i++) {
 			u32 addr, relval;
+			__be32 tmp;
 
 			/*
 			 * Get the address of the pointer to be
 			 * relocated (of course, the address has to be
 			 * relocated first).
 			 */
-			if (get_user(relval, reloc + i))
+			if (get_user(tmp, reloc + i))
 				return -EFAULT;
-			relval = ntohl(relval);
+			relval = ntohl(tmp);
 			addr = flat_get_relocate_addr(relval);
 			rp = (u32 __user *)calc_reloc(addr, libinfo, id, 1);
 			if (rp = (u32 __user *)RELOC_FAILED) {
@@ -812,8 +814,13 @@ static int load_flat_file(struct linux_binprm *bprm,
 				 * Do the relocation.  PIC relocs in the data section are
 				 * already in target order
 				 */
-				if ((flags & FLAT_FLAG_GOTPIC) = 0)
-					addr = ntohl(addr);
+				if ((flags & FLAT_FLAG_GOTPIC) = 0) {
+					/*
+					 * Meh, the same value can have a different
+					 * byte order based on a flag..
+					 */
+					addr = ntohl((__force __be32)addr);
+				}
 				addr = calc_reloc(addr, libinfo, id, 0);
 				if (addr = RELOC_FAILED) {
 					ret = -ENOEXEC;
@@ -828,11 +835,10 @@ static int load_flat_file(struct linux_binprm *bprm,
 		}
 	} else {
 		for (i = 0; i < relocs; i++) {
-			u32 relval;
+			__be32 relval;
 			if (get_user(relval, reloc + i))
 				return -EFAULT;
-			relval = ntohl(relval);
-			old_reloc(relval);
+			old_reloc(ntohl(relval));
 		}
 	}
 
#21 lore raw

PATCH 9/15 binfmt_flat: add a ARCH_HAS_BINFMT_FLAT option

In reply to Christoph Hellwig

Allow architectures to opt into ARCH_HAS_BINFMT_FLAT support instead of assuming that all nommu ports support the format.

---
 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(-)
arch/arm/Kconfig +1 -0
index b1b48c0bde76..695a26c68064 100644
@@ -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
arch/c6x/Kconfig +1 -0
index eeb0471268a0..78dfe186d708 100644
@@ -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
arch/h8300/Kconfig +1 -0
index 7457f190caaa..ec800e9d5aad 100644
@@ -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
arch/m68k/Kconfig +1 -0
index fd69ee5ad6ab..c0c43c624afa 100644
@@ -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
arch/microblaze/Kconfig +1 -0
index f11433daab4a..d411de05b628 100644
@@ -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
arch/sh/Kconfig +1 -0
index b77f512bb176..df3e6215b78c 100644
@@ -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
arch/xtensa/Kconfig +1 -0
index 6ec1b75eabc5..ebc135bda921 100644
@@ -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
fs/Kconfig.binfmt +4 -1
index 82f7d7f234f3..286b425b30b9 100644
@@ -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.
 
Signature · 1 line
2.20.1
Reviewed-by on v1 9/15
#22 lore raw

Re: [PATCH 09/15] binfmt_flat: add a ARCH_HAS_BINFMT_FLAT option

Quoted 4 lines · Christoph Hellwig

Allow architectures to opt into ARCH_HAS_BINFMT_FLAT support instead of assuming that all nommu ports support the format.

Quoted 10 lines
---
 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(-)

For ARM bits:

Quoted 104 lines
arch/arm/Kconfig +1 -0
index b1b48c0bde76..695a26c68064 100644
@@ -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
arch/c6x/Kconfig +1 -0
index eeb0471268a0..78dfe186d708 100644
@@ -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
arch/h8300/Kconfig +1 -0
index 7457f190caaa..ec800e9d5aad 100644
@@ -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
arch/m68k/Kconfig +1 -0
index fd69ee5ad6ab..c0c43c624afa 100644
@@ -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
arch/microblaze/Kconfig +1 -0
index f11433daab4a..d411de05b628 100644
@@ -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
arch/sh/Kconfig +1 -0
index b77f512bb176..df3e6215b78c 100644
@@ -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
arch/xtensa/Kconfig +1 -0
index 6ec1b75eabc5..ebc135bda921 100644
@@ -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
fs/Kconfig.binfmt +4 -1
index 82f7d7f234f3..286b425b30b9 100644
@@ -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.
 
#23 lore raw

PATCH 10/15 binfmt_flat: make support for old format binaries optional

In reply to Christoph Hellwig

No need to carry the extra code around, given that systems using flat binaries are generally very resource constrained.

---
 fs/Kconfig.binfmt |  7 +++++++
 fs/binfmt_flat.c  | 29 +++++++++++++++++++++--------
 2 files changed, 28 insertions(+), 8 deletions(-)
fs/Kconfig.binfmt +7 -0
index 286b425b30b9..62dc4f577ba1 100644
@@ -106,6 +106,13 @@ config BINFMT_FLAT_ARGVP_ENVP_ON_STACK
 config BINFMT_FLAT_OLD_ALWAYS_RAM
 	bool
 
+config BINFMT_FLAT_OLD
+	bool "Enable support for very old legacy flat binaries"
+	depends on BINFMT_FLAT
+	help
+	  Support decade old uClinux FLAT format binaries.  Unless you know
+	  you have some of those say N here.
+
 config BINFMT_ZFLAT
 	bool "Enable ZFLAT support"
 	depends on BINFMT_FLAT
fs/binfmt_flat.c +21 -8
index 6c1848dee724..ed7d969593d2 100644
@@ -374,6 +374,7 @@ calc_reloc(unsigned long r, struct lib_info *p, int curid, int internalp)
 
 /****************************************************************************/
 
+#ifdef CONFIG_BINFMT_FLAT_OLD
 static void old_reloc(unsigned long rl)
 {
 	static const char *segment[] = { "TEXT", "DATA", "BSS", "*UNKNOWN*" };
@@ -411,6 +412,7 @@ static void old_reloc(unsigned long rl)
 
 	pr_debug("Relocation became %lx\n", val);
 }
+#endif /* CONFIG_BINFMT_FLAT_OLD */
 
 /****************************************************************************/
 
@@ -461,6 +463,7 @@ static int load_flat_file(struct linux_binprm *bprm,
 	if (flags & FLAT_FLAG_KTRACE)
 		pr_info("Loading file: %s\n", bprm->filename);
 
+#ifdef CONFIG_BINFMT_FLAT_OLD
 	if (rev != FLAT_VERSION && rev != OLD_FLAT_VERSION) {
 		pr_err("bad flat file version 0x%x (supported 0x%lx and 0x%lx)\n",
 		       rev, FLAT_VERSION, OLD_FLAT_VERSION);
@@ -476,6 +479,22 @@ static int load_flat_file(struct linux_binprm *bprm,
 		goto err;
 	}
 
+	/*
+	 * fix up the flags for the older format,  there were all kinds
+	 * of endian hacks,  this only works for the simple cases
+	 */
+	if (IS_ENABLED(CONFIG_BINFMT_FLAT_OLD_ALWAYS_RAM) &&
+	    rev = OLD_FLAT_VERSION)
+		flags = FLAT_FLAG_RAM;
+#else /* CONFIG_BINFMT_FLAT_OLD */
+	if (rev != FLAT_VERSION) {
+		pr_err("bad flat file version 0x%x (supported 0x%lx)\n",
+		       rev, FLAT_VERSION);
+		ret = -ENOEXEC;
+		goto err;
+	}
+#endif /* !CONFIG_BINFMT_FLAT_OLD */
+
 	/*
 	 * Make sure the header params are sane.
 	 * 28 bits (256 MB) is way more than reasonable in this case.
@@ -487,14 +506,6 @@ static int load_flat_file(struct linux_binprm *bprm,
 		goto err;
 	}
 
-	/*
-	 * fix up the flags for the older format,  there were all kinds
-	 * of endian hacks,  this only works for the simple cases
-	 */
-	if (IS_ENABLED(CONFIG_BINFMT_FLAT_OLD_ALWAYS_RAM) &&
-	    rev = OLD_FLAT_VERSION)
-		flags = FLAT_FLAG_RAM;
-
 #ifndef CONFIG_BINFMT_ZFLAT
 	if (flags & (FLAT_FLAG_GZIP|FLAT_FLAG_GZDATA)) {
 		pr_err("Support for ZFLAT executables is not enabled.\n");
@@ -833,6 +844,7 @@ static int load_flat_file(struct linux_binprm *bprm,
 					goto err;
 			}
 		}
+#ifdef CONFIG_BINFMT_FLAT_OLD
 	} else {
 		for (i = 0; i < relocs; i++) {
 			__be32 relval;
@@ -840,6 +852,7 @@ static int load_flat_file(struct linux_binprm *bprm,
 				return -EFAULT;
 			old_reloc(ntohl(relval));
 		}
+#endif /* CONFIG_BINFMT_FLAT_OLD */
 	}
 
 	flush_icache_range(start_code, end_code);
Signature · 1 line
2.20.1
#24 lore raw

PATCH 11/15 binfmt_flat: provide an asm-generic/flat.h

In reply to Christoph Hellwig

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.

---
 arch/arm/include/asm/Kbuild                   |  1 +
 arch/m68k/include/asm/flat.h                  | 21 +------------------
 .../asm => include/asm-generic}/flat.h        | 12 ++++-------
 3 files changed, 6 insertions(+), 28 deletions(-)
 rename {arch/arm/include/asm => include/asm-generic}/flat.h (73%)
arch/arm/include/asm/Kbuild +1 -0
index a8f149ab45b8..6b2dc15b6dff 100644
@@ -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
arch/m68k/include/asm/flat.h +1 -20
index d7102fcd43eb..46379e08cdd6 100644
@@ -6,26 +6,7 @@
 #ifndef __M68KNOMMU_FLAT_H__
 #define __M68KNOMMU_FLAT_H__
 
-#include <linux/uaccess.h>
-
-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 <asm-generic/flat.h>
 
 #define FLAT_PLAT_INIT(regs) \
 	do { \
include/asm-generic/flat.h renamed from arch/arm/include/asm/flat.h +4 -8
similarity index 73%
rename from arch/arm/include/asm/flat.h
rename to include/asm-generic/flat.h
index bbc27901446f..fcd2b45c0735 100644
@@ -1,15 +1,11 @@
 /* SPDX-License-Identifier: GPL-2.0 */
-/*
- * arch/arm/include/asm/flat.h -- uClinux flat-format executables
- */
-
-#ifndef __ARM_FLAT_H__
-#define __ARM_FLAT_H__
+#ifndef _ASM_GENERIC_FLAT_H
+#define _ASM_GENERIC_FLAT_H
 
 #include <linux/uaccess.h>
 
 static inline int flat_get_addr_from_rp(u32 __user *rp, u32 relval, u32 flags,
-					u32 *addr, u32 *persistent)
+		u32 *addr, u32 *persistent)
 {
 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
 	return copy_from_user(addr, rp, 4) ? -EFAULT : 0;
@@ -27,4 +23,4 @@ static inline int flat_put_addr_at_rp(u32 __user *rp, u32 addr, u32 rel)
 #endif
 }
 
-#endif /* __ARM_FLAT_H__ */
+#endif /* _ASM_GENERIC_FLAT_H */
Signature · 1 line
2.20.1
Reviewed-by on v1 11/15
#25 lore raw

Re: [PATCH 11/15] binfmt_flat: provide an asm-generic/flat.h

Quoted 7 lines · Christoph Hellwig

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.

Quoted 7 lines
---
 arch/arm/include/asm/Kbuild                   |  1 +
 arch/m68k/include/asm/flat.h                  | 21 +------------------
 .../asm => include/asm-generic}/flat.h        | 12 ++++-------
 3 files changed, 6 insertions(+), 28 deletions(-)
 rename {arch/arm/include/asm => include/asm-generic}/flat.h (73%)

FWIW:

Quoted 78 lines
arch/arm/include/asm/Kbuild +1 -0
index a8f149ab45b8..6b2dc15b6dff 100644
@@ -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
arch/m68k/include/asm/flat.h +1 -20
index d7102fcd43eb..46379e08cdd6 100644
@@ -6,26 +6,7 @@
 #ifndef __M68KNOMMU_FLAT_H__
 #define __M68KNOMMU_FLAT_H__
 
-#include <linux/uaccess.h>
-
-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 <asm-generic/flat.h>
 
 #define FLAT_PLAT_INIT(regs) \
 	do { \
include/asm-generic/flat.h renamed from arch/arm/include/asm/flat.h +4 -8
similarity index 73%
rename from arch/arm/include/asm/flat.h
rename to include/asm-generic/flat.h
index bbc27901446f..fcd2b45c0735 100644
@@ -1,15 +1,11 @@
 /* SPDX-License-Identifier: GPL-2.0 */
-/*
- * arch/arm/include/asm/flat.h -- uClinux flat-format executables
- */
-
-#ifndef __ARM_FLAT_H__
-#define __ARM_FLAT_H__
+#ifndef _ASM_GENERIC_FLAT_H
+#define _ASM_GENERIC_FLAT_H
 
 #include <linux/uaccess.h>
 
 static inline int flat_get_addr_from_rp(u32 __user *rp, u32 relval, u32 flags,
-					u32 *addr, u32 *persistent)
+		u32 *addr, u32 *persistent)
 {
 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
 	return copy_from_user(addr, rp, 4) ? -EFAULT : 0;
@@ -27,4 +23,4 @@ static inline int flat_put_addr_at_rp(u32 __user *rp, u32 addr, u32 rel)
 #endif
 }
 
-#endif /* __ARM_FLAT_H__ */
+#endif /* _ASM_GENERIC_FLAT_H */
#26 lore raw

PATCH 12/15 binfmt_flat: remove the persistent argument from flat_get_addr_from_rp

In reply to Christoph Hellwig

The argument is never used.

---
 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(-)
arch/c6x/include/asm/flat.h +1 -1
index 2d57a9204d21..9e6544b51386 100644
@@ -5,7 +5,7 @@
 #include <asm/unaligned.h>
 
 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;
arch/h8300/include/asm/flat.h +1 -1
index 4683146f0e9e..78070f924177 100644
@@ -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))
arch/microblaze/include/asm/flat.h +1 -1
index 9e3d8e01d294..1ab86770eaee 100644
@@ -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;
 
arch/sh/include/asm/flat.h +1 -1
index 1002343dd84a..fee4f25555cb 100644
@@ -12,7 +12,7 @@
 #include <asm/unaligned.h>
 
 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;
arch/xtensa/include/asm/flat.h +1 -1
index 3d357371b28b..ed5870c779f9 100644
@@ -5,7 +5,7 @@
 #include <asm/unaligned.h>
 
 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;
fs/binfmt_flat.c +1 -3
index ed7d969593d2..114ea225c5a5 100644
@@ -794,7 +794,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;
@@ -815,8 +814,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;
 
include/asm-generic/flat.h +1 -1
index fcd2b45c0735..1928a3596938 100644
@@ -5,7 +5,7 @@
 #include <linux/uaccess.h>
 
 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;
Signature · 1 line
2.20.1
#27 lore raw

PATCH 13/15 binfmt_flat: move the MAX_SHARED_LIBS definition to binfmt_flat.c

In reply to Christoph Hellwig

MAX_SHARED_LIBS is an implementation detail of the kernel loader, and should be kept away from the file format definition.

---
 fs/binfmt_flat.c     | 6 ++++++
 include/linux/flat.h | 6 ------
 2 files changed, 6 insertions(+), 6 deletions(-)
fs/binfmt_flat.c +6 -0
index 114ea225c5a5..2c7f32d5435f 100644
@@ -68,6 +68,12 @@
 #define RELOC_FAILED 0xff00ff01		/* Relocation incorrect somewhere */
 #define UNLOADED_LIB 0x7ff000ff		/* Placeholder for unused library */
 
+#ifdef CONFIG_BINFMT_SHARED_FLAT
+#define	MAX_SHARED_LIBS			(4)
+#else
+#define	MAX_SHARED_LIBS			(1)
+#endif
+
 struct lib_info {
 	struct {
 		unsigned long start_code;		/* Start of text segment */
include/linux/flat.h +0 -6
index 59e892d5fadb..a2232f1bd41b 100644
@@ -12,12 +12,6 @@
 
 #define	FLAT_VERSION			0x00000004L
 
-#ifdef CONFIG_BINFMT_SHARED_FLAT
-#define	MAX_SHARED_LIBS			(4)
-#else
-#define	MAX_SHARED_LIBS			(1)
-#endif
-
 /*
  * To make everything easier to port and manage cross platform
  * development,  all fields are in network byte order.
Signature · 1 line
2.20.1
#28 lore raw

PATCH 14/15 binfmt_flat: don't offset the data start

In reply to Christoph Hellwig

Ever since the initial commit of the binfmt_flat shared library support back in the bitkeeper days we've offset the actual in-memory .data start by one field per possible shared library, or 1 in case shared library support isn't enabled. I can't find anything in the loader that actually makes use of it, nor was it present before shared library support it.

---
 fs/binfmt_flat.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)
fs/binfmt_flat.c +8 -12
index 2c7f32d5435f..e1ccc9f14150 100644
@@ -572,7 +572,7 @@ static int load_flat_file(struct linux_binprm *bprm,
 			goto err;
 		}
 
-		len = data_len + extra + MAX_SHARED_LIBS * sizeof(unsigned long);
+		len = data_len + extra;
 		len = PAGE_ALIGN(len);
 		realdatastart = vm_mmap(NULL, 0, len,
 			PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE, 0);
@@ -586,9 +586,7 @@ static int load_flat_file(struct linux_binprm *bprm,
 			vm_munmap(textpos, text_len);
 			goto err;
 		}
-		datapos = ALIGN(realdatastart +
-				MAX_SHARED_LIBS * sizeof(unsigned long),
-				FLAT_DATA_ALIGN);
+		datapos = ALIGN(realdatastart, FLAT_DATA_ALIGN);
 
 		pr_debug("Allocated data+bss+stack (%u bytes): %lx\n",
 			 data_len + bss_len + stack_len, datapos);
@@ -618,7 +616,7 @@ static int load_flat_file(struct linux_binprm *bprm,
 		memp_size = len;
 	} else {
 
-		len = text_len + data_len + extra + MAX_SHARED_LIBS * sizeof(u32);
+		len = text_len + data_len + extra;
 		len = PAGE_ALIGN(len);
 		textpos = vm_mmap(NULL, 0, len,
 			PROT_READ | PROT_EXEC | PROT_WRITE, MAP_PRIVATE, 0);
@@ -633,9 +631,7 @@ static int load_flat_file(struct linux_binprm *bprm,
 		}
 
 		realdatastart = textpos + ntohl(hdr->data_start);
-		datapos = ALIGN(realdatastart +
-				MAX_SHARED_LIBS * sizeof(u32),
-				FLAT_DATA_ALIGN);
+		datapos = ALIGN(realdatastart, FLAT_DATA_ALIGN);
 
 		reloc = (__be32 __user *)
 			(datapos + (ntohl(hdr->reloc_start) - text_len));
@@ -652,8 +648,9 @@ static int load_flat_file(struct linux_binprm *bprm,
 					 (text_len + full_data
 						  - sizeof(struct flat_hdr)),
 					 0);
-			memmove((void *) datapos, (void *) realdatastart,
-					full_data);
+			if (datapos != realdatastart)
+				memmove((void *)datapos, (void *)realdatastart,
+						full_data);
 #else
 			/*
 			 * This is used on MMU systems mainly for testing.
@@ -709,8 +706,7 @@ static int load_flat_file(struct linux_binprm *bprm,
 		if (IS_ERR_VALUE(result)) {
 			ret = result;
 			pr_err("Unable to read code+data+bss, errno %d\n", ret);
-			vm_munmap(textpos, text_len + data_len + extra +
-				MAX_SHARED_LIBS * sizeof(u32));
+			vm_munmap(textpos, text_len + data_len + extra);
 			goto err;
 		}
 	}
Signature · 1 line
2.20.1
#29 lore raw

PATCH 15/15 riscv: add binfmt_flat support

In reply to Christoph Hellwig

Use the generic support with arguments are on the stack. Same as arm and m68k.

---
 arch/riscv/Kconfig            | 2 ++
 arch/riscv/include/asm/Kbuild | 1 +
 2 files changed, 3 insertions(+)
arch/riscv/Kconfig +2 -0
index 0c4b12205632..2e3b60cdeef4 100644
@@ -17,7 +17,9 @@ config RISCV
 	select OF
 	select OF_EARLY_FLATTREE
 	select OF_IRQ
+	select ARCH_HAS_BINFMT_FLAT
 	select ARCH_WANT_FRAME_POINTERS
+	select BINFMT_FLAT_ARGVP_ENVP_ON_STACK
 	select CLONE_BACKWARDS
 	select COMMON_CLK
 	select GENERIC_CLOCKEVENTS
arch/riscv/include/asm/Kbuild +1 -0
index 5ee646619cc3..1efaeddf1e4b 100644
@@ -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
Signature · 1 line
2.20.1
#30 lore raw

Re: [PATCH 15/15] riscv: add binfmt_flat support

Quoted 2 lines · Christoph Hellwig

Use the generic support with arguments are on the stack. Same as arm and m68k.

Out of curiosity, what is reason for keeping arguments on the stack?

ARM port of uClibc has following comment around manipulating of argv/argc:

/*
* uClinux/arm stacks look a little different from normal
* MMU-full Linux/arm stacks (for no good reason) */

So I though it is kind of legacy.

Thanks
Vladimir

Quoted 34 lines
---
 arch/riscv/Kconfig            | 2 ++
 arch/riscv/include/asm/Kbuild | 1 +
 2 files changed, 3 insertions(+)
arch/riscv/Kconfig +2 -0
index 0c4b12205632..2e3b60cdeef4 100644
@@ -17,7 +17,9 @@ config RISCV
 	select OF
 	select OF_EARLY_FLATTREE
 	select OF_IRQ
+	select ARCH_HAS_BINFMT_FLAT
 	select ARCH_WANT_FRAME_POINTERS
+	select BINFMT_FLAT_ARGVP_ENVP_ON_STACK
 	select CLONE_BACKWARDS
 	select COMMON_CLK
 	select GENERIC_CLOCKEVENTS
arch/riscv/include/asm/Kbuild +1 -0
index 5ee646619cc3..1efaeddf1e4b 100644
@@ -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
#31 lore raw

Re: [PATCH 15/15] riscv: add binfmt_flat support

Quoted 6 lines · Vladimir Murzin
Quoted 2 lines · Christoph Hellwig

Use the generic support with arguments are on the stack. Same as arm and m68k.

Out of curiosity, what is reason for keeping arguments on the stack?

Quoted 8 lines

ARM port of uClibc has following comment around manipulating of argv/argc:

/*
* uClinux/arm stacks look a little different from normal
* MMU-full Linux/arm stacks (for no good reason) */

So I though it is kind of legacy.

I just copied m68k and arm. But dropping this makes the uclinux crt1 code simpler, so I'll drop the flag for the next version.

#32 lore raw
In reply to Christoph Hellwig

Hi Christoph,

Quoted 4 lines · Christoph Hellwig

below is a larger stash of cleanups for the binfmt_misc code, preparing for the last patch that now trivially adds RISC-V support, which will be used for the RISC-V nommu series I am about to post.

Whole series looks pretty good. Just the one comment I made.

I normally take these through the m68knommu git tree, if you have no problem with that I'll push it in there. It will hit linux-next from there.

Thanks
Greg

#33 lore raw
Quoted 8 lines · Greg Ungerer

Hi Christoph,

Quoted 4 lines · Christoph Hellwig

below is a larger stash of cleanups for the binfmt_misc code, preparing for the last patch that now trivially adds RISC-V support, which will be used for the RISC-V nommu series I am about to post.

Quoted 5 lines

Whole series looks pretty good. Just the one comment I made.

I normally take these through the m68knommu git tree, if you have no problem with that I'll push it in there. It will hit linux-next from there.

Yes, that's fine. We'll need it to bring up riscv nommu support, but there is no actual dependency on the patches for it to compile, just for it to actually be useful.

Btw, it seems like the uclinux-dev list is dead, is there a replacement for it?

#34 lore raw
Quoted 15 lines · Christoph Hellwig
Quoted 8 lines · Greg Ungerer

Hi Christoph,

Quoted 4 lines · Christoph Hellwig

below is a larger stash of cleanups for the binfmt_misc code, preparing for the last patch that now trivially adds RISC-V support, which will be used for the RISC-V nommu series I am about to post.

Quoted 5 lines

Whole series looks pretty good. Just the one comment I made.

I normally take these through the m68knommu git tree, if you have no problem with that I'll push it in there. It will hit linux-next from there.

Quoted 6 lines

Yes, that's fine. We'll need it to bring up riscv nommu support, but there is no actual dependency on the patches for it to compile, just for it to actually be useful.

Btw, it seems like the uclinux-dev list is dead, is there a replacement for it?

No, unfortunately no replacement. Generally I think anything that comes up goes to the architecture list that issues come up on. Probably not ideal, especially for things like this that are across all arches.

Regards
Greg

#35 lore raw
In reply to Christoph Hellwig

Hi Christoph,

Quoted 6 lines · Christoph Hellwig

Hi Greg,

below is a larger stash of cleanups for the binfmt_misc code, preparing for the last patch that now trivially adds RISC-V support, which will be used for the RISC-V nommu series I am about to post.

I'm wondering if you have a branch with these changes so I can give it a try on ARM NOMMU platforms?

Cheers
Vladimir

Quoted 6 lines

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#36 lore raw
Quoted 2 lines · Vladimir Murzin

I'm wondering if you have a branch with these changes so I can give it a try on ARM NOMMU platforms?

git://git.infradead.org/users/hch/riscv.git riscv-flat

#37 lore raw
Quoted 7 lines · Christoph Hellwig
Quoted 2 lines · Vladimir Murzin

I'm wondering if you have a branch with these changes so I can give it a try on ARM NOMMU platforms?

git://git.infradead.org/users/hch/riscv.git riscv-flat

Thanks! I gave it a go and provided my tags for relevant patches.

Cheers
Vladimir