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
 	DBGC ( colour, "RUNTIME found command line \"%s\" at %08x\n",
135
 	DBGC ( colour, "RUNTIME found command line \"%s\" at %08x\n",
136
 	       cmdline, cmdline_phys );
136
 	       cmdline, cmdline_phys );
137
 
137
 
138
+	/* Mark command line as consumed */
139
+	cmdline_phys = 0;
140
+
138
 	/* Strip unwanted cruft from the command line */
141
 	/* Strip unwanted cruft from the command line */
139
 	cmdline_strip ( cmdline, "BOOT_IMAGE=" );
142
 	cmdline_strip ( cmdline, "BOOT_IMAGE=" );
140
 	cmdline_strip ( cmdline, "initrd=" );
143
 	cmdline_strip ( cmdline, "initrd=" );
205
 	memcpy_user ( image->data, 0, phys_to_user ( initrd_phys ), 0,
208
 	memcpy_user ( image->data, 0, phys_to_user ( initrd_phys ), 0,
206
 		      initrd_len );
209
 		      initrd_len );
207
 
210
 
211
+	/* Mark initrd as consumed */
212
+	initrd_phys = 0;
213
+
208
 	/* Register image */
214
 	/* Register image */
209
 	if ( ( rc = register_image ( image ) ) != 0 ) {
215
 	if ( ( rc = register_image ( image ) ) != 0 ) {
210
 		DBGC ( colour, "RUNTIME could not register initrd: %s\n",
216
 		DBGC ( colour, "RUNTIME could not register initrd: %s\n",
245
 }
251
 }
246
 
252
 
247
 /** Command line and initrd initialisation function */
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