Browse Source

[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 years ago
parent
commit
84e25513b1
1 changed files with 9 additions and 5 deletions
  1. 9
    5
      src/arch/x86/prefix/hdprefix.S

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

27
 	popw	%es
27
 	popw	%es
28
 	popal
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
 	movb	%cl, %al
31
 	movb	%cl, %al
32
 	negb	%al
32
 	negb	%al
33
 	addb	max_sector, %al
33
 	addb	max_sector, %al
34
 	incb	%al
34
 	incb	%al
35
 	andb	$0x3f, %al
35
 	andb	$0x3f, %al
36
 	movzbl	%al, %eax
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
 	jc	load_failed
42
 	jc	load_failed
39
 	
43
 	
40
 	/* Update %es */
44
 	/* Update %es */
53
 	orb	$0x01, %cl
57
 	orb	$0x01, %cl
54
 	incb	%dh
58
 	incb	%dh
55
 	cmpb	max_head, %dh
59
 	cmpb	max_head, %dh
56
-	jbe	2f
60
+	jbe	3f
57
 	xorb	%dh, %dh
61
 	xorb	%dh, %dh
58
 	incb	%ch
62
 	incb	%ch
59
-	jnc	2f
63
+	jnc	3f
60
 	addb	$0xc0, %cl
64
 	addb	$0xc0, %cl
61
-2:
65
+3:
62
 	/* Loop until whole image is read */
66
 	/* Loop until whole image is read */
63
 	subl	%eax, load_length
67
 	subl	%eax, load_length
64
 	ja	1b
68
 	ja	1b

Loading…
Cancel
Save