Skip to contentSkip to conversation

alpha: binfmt_aout fix

PATCH In review Ivan Kokshaysky 3 participants 5 messages Feb 17, 2009 – Feb 19, 2009

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 alpha: binfmt_aout fix

This fixes the problem introduced by commit 3bfacef412 (get rid of special-casing the /sbin/loader on alpha): osf/1 ecoff binary segfaults when binfmt_aout built as module. That happens because aout binary handler gets on the top of the binfmt list due to late registration, and kernel attempts to execute the binary without preparation work that must be done by binfmt_loader.

So I had to add a check for bprm->loader in load_aout_binary() which makes a search order irrelevant.

Also, do not build the binfmt_loader when CONFIG_BINFMT_AOUT is not set.

---
 arch/alpha/kernel/Makefile |    6 +++++-
 fs/binfmt_aout.c           |    6 ++++++
 2 files changed, 11 insertions(+), 1 deletions(-)
arch/alpha/kernel/Makefile +5 -1
index b469775..e203713 100644
@@ -8,7 +8,7 @@ EXTRA_CFLAGS	:= -Werror -Wno-sign-compare
 
 obj-y    := entry.o traps.o process.o init_task.o osf_sys.o irq.o \
 	    irq_alpha.o signal.o setup.o ptrace.o time.o \
-	    alpha_ksyms.o systbls.o err_common.o io.o binfmt_loader.o
+	    alpha_ksyms.o systbls.o err_common.o io.o
 
 obj-$(CONFIG_VGA_HOSE)	+= console.o
 obj-$(CONFIG_SMP)	+= smp.o
@@ -43,6 +43,10 @@ else
 # Misc support
 obj-$(CONFIG_ALPHA_SRM)		+= srmcons.o
 
+ifdef CONFIG_BINFMT_AOUT
+obj-y	+= binfmt_loader.o
+endif
+
 # Core logic support
 obj-$(CONFIG_ALPHA_APECS)	+= core_apecs.o
 obj-$(CONFIG_ALPHA_CIA)		+= core_cia.o
fs/binfmt_aout.c +6 -0
index b639dcf..c890e5f 100644
@@ -226,6 +226,12 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
 	int retval;
 
 	ex = *((struct exec *) bprm->buf);		/* exec-header */
+#ifdef __alpha__
+	/* Check whether the OSF/1 loader is required and present. */
+	if (ex.fh.f_magic == 0x183 && (ex.fh.f_flags & 0x3000) == 0x3000 &&
+	    !bprm->loader)
+		return -ENOEXEC;
+#endif
 	if ((N_MAGIC(ex) != ZMAGIC && N_MAGIC(ex) != OMAGIC &&
 	     N_MAGIC(ex) != QMAGIC && N_MAGIC(ex) != NMAGIC) ||
 	    N_TRSIZE(ex) || N_DRSIZE(ex) ||
#1 lore raw
Quoted 6 lines · Ivan Kokshaysky

This fixes the problem introduced by commit 3bfacef412 (get rid of special-casing the /sbin/loader on alpha): osf/1 ecoff binary segfaults when binfmt_aout built as module. That happens because aout binary handler gets on the top of the binfmt list due to late registration, and kernel attempts to execute the binary without preparation work that must be done by binfmt_loader.

I think the proper fix for this is to make sure newly registered binfmts are added to the tail of the list, not the front.

#2 lore raw
Quoted 2 lines · Christoph Hellwig

I think the proper fix for this is to make sure newly registered binfmts are added to the tail of the list, not the front.

Yes, I was thinking about that. But then I need to make sure that alpha binfmt_loader is registered first, which is not possible at the moment as binfmts get registered at core_initcall level.
If it's acceptable to change binfmts initcall level to, say, fs_initcall, then changing list_add() to list_add_tail() would certainly work fine here.

Ivan.

#3 lore raw
Quoted 4 lines · On Tue, 17 Feb 2009 14:40:56 +0300 Ivan Kokshaysky <[email protected]>…
Quoted 2 lines · Christoph Hellwig

I think the proper fix for this is to make sure newly registered binfmts are added to the tail of the list, not the front.

Quoted 8 lines

Yes, I was thinking about that. But then I need to make sure that alpha binfmt_loader is registered first, which is not possible at the moment as binfmts get registered at core_initcall level.
If it's acceptable to change binfmts initcall level to, say, fs_initcall, then changing list_add() to list_add_tail() would certainly work fine here.

It would make sense to register the core, default handlers first and to permit arch-specific handlers to then override (or to front-end) the core handlers.

But that sounds a bit risky for 2.6.29. Is this fix needed in 2.6.29? If so, perhaps we should merge version 1 as a temporary thing. But if so, please let's not do the temporary-thing-which-hangs-around-forever thing?

#4 lore raw
Quoted 3 lines · Andrew Morton

It would make sense to register the core, default handlers first and to permit arch-specific handlers to then override (or to front-end) the core handlers.

Yes, sounds good. I'll make a patch for 2.6.30.

Quoted 3 lines

But that sounds a bit risky for 2.6.29. Is this fix needed in 2.6.29? If so, perhaps we should merge version 1 as a temporary thing. But if so, please let's not do the temporary-thing-which-hangs-around-forever thing?

Just drop it. The bug is not so terribly critical (I don't think that a lot of people are using osf binaries these days).

Ivan.