Commit 74641f584da8eccf30becfbb5507ab457187db22

Authored by Ivan Kokshaysky
Committed by Linus Torvalds
1 parent 77b4cf5cb0

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 preparatory work that must
be done by binfmt_loader.

Fixed by changing the registration order of the default binfmt handlers
using list_add_tail() and introducing insert_binfmt() function which
places new handler on the top of the binfmt list.  This might be generally
useful for installing arch-specific frontends for default handlers or just
for overriding them.

Signed-off-by: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: Al Viro <viro@ZenIV.linux.org.uk>
Cc: Richard Henderson <rth@twiddle.net
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 4 changed files with 23 additions and 6 deletions Side-by-side Diff

arch/alpha/kernel/Makefile
... ... @@ -8,7 +8,7 @@
8 8  
9 9 obj-y := entry.o traps.o process.o init_task.o osf_sys.o irq.o \
10 10 irq_alpha.o signal.o setup.o ptrace.o time.o \
11   - alpha_ksyms.o systbls.o err_common.o io.o binfmt_loader.o
  11 + alpha_ksyms.o systbls.o err_common.o io.o
12 12  
13 13 obj-$(CONFIG_VGA_HOSE) += console.o
14 14 obj-$(CONFIG_SMP) += smp.o
... ... @@ -42,6 +42,10 @@
42 42  
43 43 # Misc support
44 44 obj-$(CONFIG_ALPHA_SRM) += srmcons.o
  45 +
  46 +ifdef CONFIG_BINFMT_AOUT
  47 +obj-y += binfmt_loader.o
  48 +endif
45 49  
46 50 # Core logic support
47 51 obj-$(CONFIG_ALPHA_APECS) += core_apecs.o
arch/alpha/kernel/binfmt_loader.c
... ... @@ -46,7 +46,7 @@
46 46  
47 47 static int __init init_loader_binfmt(void)
48 48 {
49   - return register_binfmt(&loader_format);
  49 + return insert_binfmt(&loader_format);
50 50 }
51 51 arch_initcall(init_loader_binfmt);
... ... @@ -69,17 +69,18 @@
69 69 static LIST_HEAD(formats);
70 70 static DEFINE_RWLOCK(binfmt_lock);
71 71  
72   -int register_binfmt(struct linux_binfmt * fmt)
  72 +int __register_binfmt(struct linux_binfmt * fmt, int insert)
73 73 {
74 74 if (!fmt)
75 75 return -EINVAL;
76 76 write_lock(&binfmt_lock);
77   - list_add(&fmt->lh, &formats);
  77 + insert ? list_add(&fmt->lh, &formats) :
  78 + list_add_tail(&fmt->lh, &formats);
78 79 write_unlock(&binfmt_lock);
79 80 return 0;
80 81 }
81 82  
82   -EXPORT_SYMBOL(register_binfmt);
  83 +EXPORT_SYMBOL(__register_binfmt);
83 84  
84 85 void unregister_binfmt(struct linux_binfmt * fmt)
85 86 {
include/linux/binfmts.h
... ... @@ -82,7 +82,19 @@
82 82 int hasvdso;
83 83 };
84 84  
85   -extern int register_binfmt(struct linux_binfmt *);
  85 +extern int __register_binfmt(struct linux_binfmt *fmt, int insert);
  86 +
  87 +/* Registration of default binfmt handlers */
  88 +static inline int register_binfmt(struct linux_binfmt *fmt)
  89 +{
  90 + return __register_binfmt(fmt, 0);
  91 +}
  92 +/* Same as above, but adds a new binfmt at the top of the list */
  93 +static inline int insert_binfmt(struct linux_binfmt *fmt)
  94 +{
  95 + return __register_binfmt(fmt, 1);
  96 +}
  97 +
86 98 extern void unregister_binfmt(struct linux_binfmt *);
87 99  
88 100 extern int prepare_binprm(struct linux_binprm *);