Browse Source

[prefix] Delay initrd image copy until memory map is ready

initrd_init() calls umalloc() to allocate space for the initrd image,
but does so before hide_etherboot() has been called.  It is therefore
possible for the initrd to end up overwriting iPXE itself.

Fix by converting initrd_init() from an init_fn to a startup_fn.

Originally-fixed-by: Till Straumann <strauman@slac.stanford.edu>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 12 years ago
parent
commit
3a4253868c
1 changed files with 8 additions and 2 deletions
  1. 8
    2
      src/arch/i386/core/runtime.c

+ 8
- 2
src/arch/i386/core/runtime.c View File

@@ -135,6 +135,9 @@ static int cmdline_init ( void ) {
135 135
 	DBGC ( colour, "RUNTIME found command line \"%s\" at %08x\n",
136 136
 	       cmdline, cmdline_phys );
137 137
 
138
+	/* Mark command line as consumed */
139
+	cmdline_phys = 0;
140
+
138 141
 	/* Strip unwanted cruft from the command line */
139 142
 	cmdline_strip ( cmdline, "BOOT_IMAGE=" );
140 143
 	cmdline_strip ( cmdline, "initrd=" );
@@ -205,6 +208,9 @@ static int initrd_init ( void ) {
205 208
 	memcpy_user ( image->data, 0, phys_to_user ( initrd_phys ), 0,
206 209
 		      initrd_len );
207 210
 
211
+	/* Mark initrd as consumed */
212
+	initrd_phys = 0;
213
+
208 214
 	/* Register image */
209 215
 	if ( ( rc = register_image ( image ) ) != 0 ) {
210 216
 		DBGC ( colour, "RUNTIME could not register initrd: %s\n",
@@ -245,6 +251,6 @@ static void runtime_init ( void ) {
245 251
 }
246 252
 
247 253
 /** Command line and initrd initialisation function */
248
-struct init_fn runtime_init_fn __init_fn ( INIT_NORMAL ) = {
249
-	.initialise = runtime_init,
254
+struct startup_fn runtime_startup_fn __startup_fn ( STARTUP_NORMAL ) = {
255
+	.startup = runtime_init,
250 256
 };

Loading…
Cancel
Save