Skip to content

Commit 74641f5

Browse files
Ivan Kokshayskytorvalds
authored andcommitted
alpha: binfmt_aout fix
This fixes the problem introduced by commit 3bfacef (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>
1 parent 77b4cf5 commit 74641f5

4 files changed

Lines changed: 23 additions & 6 deletions

File tree

‎arch/alpha/kernel/Makefile‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ EXTRA_CFLAGS := -Werror -Wno-sign-compare
88

99
obj-y := entry.o traps.o process.o init_task.o osf_sys.o irq.o \
1010
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
1212

1313
obj-$(CONFIG_VGA_HOSE) += console.o
1414
obj-$(CONFIG_SMP) += smp.o
@@ -43,6 +43,10 @@ else
4343
# Misc support
4444
obj-$(CONFIG_ALPHA_SRM) += srmcons.o
4545

46+
ifdef CONFIG_BINFMT_AOUT
47+
obj-y += binfmt_loader.o
48+
endif
49+
4650
# Core logic support
4751
obj-$(CONFIG_ALPHA_APECS) += core_apecs.o
4852
obj-$(CONFIG_ALPHA_CIA) += core_cia.o

‎arch/alpha/kernel/binfmt_loader.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@ static struct linux_binfmt loader_format = {
4646

4747
static int __init init_loader_binfmt(void)
4848
{
49-
return register_binfmt(&loader_format);
49+
return insert_binfmt(&loader_format);
5050
}
5151
arch_initcall(init_loader_binfmt);

‎fs/exec.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,18 @@ int suid_dumpable = 0;
6969
static LIST_HEAD(formats);
7070
static DEFINE_RWLOCK(binfmt_lock);
7171

72-
int register_binfmt(struct linux_binfmt * fmt)
72+
int __register_binfmt(struct linux_binfmt * fmt, int insert)
7373
{
7474
if (!fmt)
7575
return -EINVAL;
7676
write_lock(&binfmt_lock);
77-
list_add(&fmt->lh, &formats);
77+
insert ? list_add(&fmt->lh, &formats) :
78+
list_add_tail(&fmt->lh, &formats);
7879
write_unlock(&binfmt_lock);
7980
return 0;
8081
}
8182

82-
EXPORT_SYMBOL(register_binfmt);
83+
EXPORT_SYMBOL(__register_binfmt);
8384

8485
void unregister_binfmt(struct linux_binfmt * fmt)
8586
{

‎include/linux/binfmts.h‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,19 @@ struct linux_binfmt {
8282
int hasvdso;
8383
};
8484

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+
8698
extern void unregister_binfmt(struct linux_binfmt *);
8799

88100
extern int prepare_binprm(struct linux_binprm *);

0 commit comments

Comments
 (0)