Sfoglia il codice sorgente

[hdprefix] Avoid attempts to read beyond the end of the disk

When booting from a hard disk image (e.g. bin/ipxe.usb) within an
emulator such as QEMU, the disk may not exist beyond the end of the
image.  Limit all reads to the length of the image to avoid spurious
errors when loading the iPXE image.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 7 anni fa
parent
commit
84e25513b1
1 ha cambiato i file con 9 aggiunte e 5 eliminazioni
  1. 9
    5
      src/arch/x86/prefix/hdprefix.S

+ 9
- 5
src/arch/x86/prefix/hdprefix.S Vedi File

@@ -27,14 +27,18 @@ load_image:
27 27
 	popw	%es
28 28
 	popal
29 29
 	
30
-1:	/* Read to end of current track */
30
+1:	/* Read to end of current track (or end of image) */
31 31
 	movb	%cl, %al
32 32
 	negb	%al
33 33
 	addb	max_sector, %al
34 34
 	incb	%al
35 35
 	andb	$0x3f, %al
36 36
 	movzbl	%al, %eax
37
-	call	*read_sectors
37
+	movl	load_length, %ebx
38
+	cmpl	%eax, %ebx
39
+	ja	2f
40
+	movl	%ebx, %eax
41
+2:	call	*read_sectors
38 42
 	jc	load_failed
39 43
 	
40 44
 	/* Update %es */
@@ -53,12 +57,12 @@ load_image:
53 57
 	orb	$0x01, %cl
54 58
 	incb	%dh
55 59
 	cmpb	max_head, %dh
56
-	jbe	2f
60
+	jbe	3f
57 61
 	xorb	%dh, %dh
58 62
 	incb	%ch
59
-	jnc	2f
63
+	jnc	3f
60 64
 	addb	$0xc0, %cl
61
-2:
65
+3:
62 66
 	/* Loop until whole image is read */
63 67
 	subl	%eax, load_length
64 68
 	ja	1b

Loading…
Annulla
Salva