Bladeren bron

[lkrnprefix] Copy command line before installing iPXE

The command line may be situated in an area of base memory that will
be overwritten by iPXE's real-mode segments, causing the command line
to be corrupted before it can be used.

Fix by creating a copy of the command line on the prefix stack (below
0x7c00) before installing the real-mode segments.

Reported-by: Dave Hansen <dave@sr71.net>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 12 jaren geleden
bovenliggende
commit
f5bbe7ec4a
2 gewijzigde bestanden met toevoegingen van 41 en 5 verwijderingen
  1. 2
    1
      src/arch/i386/core/runtime.c
  2. 39
    4
      src/arch/i386/prefix/lkrnprefix.S

+ 2
- 1
src/arch/i386/core/runtime.c Bestand weergeven

@@ -132,7 +132,8 @@ static int cmdline_init ( void ) {
132 132
 	}
133 133
 	cmdline = cmdline_copy;
134 134
 	copy_from_user ( cmdline, cmdline_user, 0, len );
135
-	DBGC ( colour, "RUNTIME found command line \"%s\"\n", cmdline );
135
+	DBGC ( colour, "RUNTIME found command line \"%s\" at %08x\n",
136
+	       cmdline, cmdline_phys );
136 137
 
137 138
 	/* Strip unwanted cruft from the command line */
138 139
 	cmdline_strip ( cmdline, "BOOT_IMAGE=" );

+ 39
- 4
src/arch/i386/prefix/lkrnprefix.S Bestand weergeven

@@ -188,17 +188,52 @@ setup_code:
188 188
 	We're now at the beginning of the kernel proper.
189 189
  */
190 190
 run_ipxe:
191
-	/* Set up stack just below 0x7c00 */
191
+	/* Set up stack just below 0x7c00 and clear direction flag */
192 192
 	xorw	%ax, %ax
193 193
 	movw	%ax, %ss
194 194
 	movw	$0x7c00, %sp
195
+	cld
195 196
 
196 197
 	/* Retrieve command-line pointer */
197
-	movl	%es:cmd_line_ptr, %edx
198
+	movl	%ds:cmd_line_ptr, %edx
199
+	testl	%edx, %edx
200
+	jz	no_cmd_line
201
+
202
+	/* Set up %es:%di to point to command line */
203
+	movl	%edx, %edi
204
+	andl	$0xf, %edi
205
+	rorl	$4, %edx
206
+	movw	%dx, %es
207
+
208
+	/* Find length of command line */
209
+	pushw	%di
210
+	movw	$0xffff, %cx
211
+	repnz scasb
212
+	notw	%cx
213
+	popw	%si
214
+
215
+	/* Make space for command line on stack */
216
+	movw	%sp, %di
217
+	subw	%cx, %di
218
+	andw	$~0xf, %di
219
+	movw	%di, %sp
220
+
221
+	/* Copy command line to stack */
222
+	pushw	%ds
223
+	pushw	%es
224
+	popw	%ds
225
+	pushw	%ss
226
+	popw	%es
227
+	rep movsb
228
+	popw	%ds
229
+
230
+	/* Store new command-line pointer */
231
+	movzwl	%sp, %edx
232
+no_cmd_line:
198 233
 
199 234
 	/* Retrieve initrd pointer and size */
200
-	movl	%es:ramdisk_image, %ebp
201
-	movl	%es:ramdisk_size, %ecx
235
+	movl	%ds:ramdisk_image, %ebp
236
+	movl	%ds:ramdisk_size, %ecx
202 237
 
203 238
 	/* Install iPXE */
204 239
 	call	alloc_basemem

Laden…
Annuleren
Opslaan