public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] init: use KERNEL_DS when trying to start init process
@ 2011-05-30 16:17 Mathias Krause
  2011-06-06 23:12 ` Andrew Morton
  0 siblings, 1 reply; 59+ messages in thread
From: Mathias Krause @ 2011-05-30 16:17 UTC (permalink / raw)
  To: linux-kernel; +Cc: Mathias Krause, stable

We use kernel_execve() to transfer control of the init procces from
kernel to userland. If the program to start as init process isn't given
on the kernel command line or fails to start we use a few hardcoded
fallbacks. This fallback mechanism does not work when we encounter a
file that is executable but fails to start, e.g. due to a missing
library dependency or by having an unsupported file format.

The bug is, that search_binary_handler() sets the address limit to
USER_DS but doesn't reset it on error which will make all further
attempts fail with -EFAULT because argv[0] is a pointer to kernel
memory, not userland.

The bug can easily be reproduced by starting a 32 bit kernel with a 64
bit executable as /init and a 32 bit version as /sbin/init within an
initramfs. The hardcoded defaults should make /init fail because of the
unsupported file format but should make /sbin/init succeed. This doesn't
happen because the string "/sbin/init" lives in kernel memory and is no
longer allowed because of the modified address limit to USER_DS after
the failed execution attempt of /init.

Fixing the only user of kernel_execve that needs this tweaking was far
more easy than changing the implementation for all architectures. This
also makes backporting far more easy as this bug is in there from the
very beginning -- at least it's in v2.6.12, too.

Signed-off-by: Mathias Krause <minipli@googlemail.com>
CC: stable@kernel.org
---
 init/main.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/init/main.c b/init/main.c
index cafba67..4ee893a 100644
--- a/init/main.c
+++ b/init/main.c
@@ -731,6 +731,9 @@ static void __init do_pre_smp_initcalls(void)
 
 static void run_init_process(const char *init_filename)
 {
+	/* Ensure we can access in-kernel filenames -- previous exec attempts
+	 * might have set the address limit to USER_DS */
+	set_fs(KERNEL_DS);
 	argv_init[0] = init_filename;
 	kernel_execve(init_filename, argv_init, envp_init);
 }
-- 
1.5.6.5


^ permalink raw reply related	[flat|nested] 59+ messages in thread

end of thread, other threads:[~2011-07-05 11:45 UTC | newest]

Thread overview: 59+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-30 16:17 [PATCH] init: use KERNEL_DS when trying to start init process Mathias Krause
2011-06-06 23:12 ` Andrew Morton
2011-06-07  6:49   ` Mathias Krause
2011-06-08  2:00   ` Linus Torvalds
2011-06-08  8:23     ` Mathias Krause
2011-06-08 10:47     ` Al Viro
2011-06-08 12:14       ` Mathias Krause
2011-06-08 14:03         ` Al Viro
2011-06-08 20:20         ` Chris Metcalf
2011-06-09  8:14           ` Mathias Krause
2011-06-09 10:40             ` Al Viro
2011-06-09 12:06               ` Mathias Krause
2011-06-09 15:56                 ` Linus Torvalds
2011-06-09 16:40                   ` Mathias Krause
2011-06-09 17:03                     ` Linus Torvalds
2011-06-09 18:05                       ` Mathias Krause
2011-06-09 22:56                         ` [PATCH] init: use KERNEL_DS when trying to start init process Andrew Morton
2011-06-10  8:11                           ` Mathias Krause
2011-06-10 13:08                             ` [PATCH] alpha, exec: remove redundant set_fs(USER_DS) Mathias Krause
2011-06-10 13:08                             ` [PATCH] arm, " Mathias Krause
2011-06-10 13:48                               ` Russell King - ARM Linux
2011-06-10 13:53                                 ` Mathias Krause
2011-06-27  4:29                                   ` Mathias Krause
2011-06-10 13:09                             ` [PATCH] avr32, " Mathias Krause
2011-06-14 11:28                               ` Hans-Christian Egtvedt
2011-06-10 13:09                             ` [PATCH] blackfin, " Mathias Krause
2011-06-10 14:17                               ` Mike Frysinger
2011-06-10 13:09                             ` [PATCH] cris, " Mathias Krause
2011-06-10 13:09                             ` [PATCH] frv, " Mathias Krause
2011-06-10 13:09                             ` [PATCH] h8300, " Mathias Krause
2011-06-10 13:09                             ` [PATCH] ia64, " Mathias Krause
2011-06-10 13:09                             ` [PATCH] m32r, " Mathias Krause
2011-06-10 13:09                             ` [PATCH] m68k, " Mathias Krause
2011-06-15 14:40                               ` Geert Uytterhoeven
2011-06-15 15:49                                 ` Mathias Krause
2011-06-10 13:09                             ` [PATCH] microblaze, " Mathias Krause
2011-07-05 11:45                               ` Michal Simek
2011-06-10 13:10                             ` [PATCH] mips, exec: remove redundant addr_limit assignment Mathias Krause
2011-06-10 13:10                             ` [PATCH] mn10300, exec: remove redundant set_fs(USER_DS) Mathias Krause
2011-06-10 13:10                             ` [PATCH] parisc, " Mathias Krause
2011-06-10 13:10                             ` [PATCH] ppc, " Mathias Krause
2011-06-10 13:10                             ` [PATCH] s390, " Mathias Krause
2011-06-10 13:10                             ` [PATCH] sh, " Mathias Krause
2011-06-14  6:33                               ` Paul Mundt
2011-06-10 13:10                             ` [PATCH] sparc, exec: remove redundant addr_limit assignment Mathias Krause
2011-06-11 23:08                               ` David Miller
2011-06-11 23:44                                 ` Al Viro
2011-06-12  0:58                                   ` David Miller
2011-06-12  1:01                                     ` Linus Torvalds
2011-06-12  1:04                                       ` David Miller
2011-06-13 20:28                                 ` Mathias Krause
2011-06-17 18:45                                 ` Mathias Krause
2011-06-10 13:10                             ` [PATCH] um, exec: remove redundant set_fs(USER_DS) Mathias Krause
2011-06-10 20:00                               ` Richard Weinberger
2011-06-10 13:11                             ` [PATCH] unicore32, " Mathias Krause
2011-06-13  9:19                               ` Guan Xuetao
2011-06-13 16:02                                 ` Mathias Krause
2011-06-14  7:03                                   ` Guan Xuetao
2011-06-10 15:52                             ` [PATCH] init: use KERNEL_DS when trying to start init process Randy Dunlap

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox