git: 0ca9f1d4a3b7 - main - Fix pmbr issues > 2TB

Warner Losh imp at FreeBSD.org
Tue Jul 13 21:41:56 UTC 2021


The branch main has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=0ca9f1d4a3b772036309fb1c14262ec77c674c5d

commit 0ca9f1d4a3b772036309fb1c14262ec77c674c5d
Author:     Emrion <kmachine at free.fr>
AuthorDate: 2021-07-13 20:37:59 +0000
Commit:     Warner Losh <imp at FreeBSD.org>
CommitDate: 2021-07-13 21:40:44 +0000

    Fix pmbr issues > 2TB
    
    These issues have low impact because they require precise circumstances
    to trigger one of them. The disk must be > 2 TiB in size and either:
    - The primary GPT header is dammaged.
    - The freebsd-boot partiton is located farther than the first 2 TiB of
      the disc and one of its sectors takes place at a lba value that makes
      the higher 32 bits of this very value change.
    Errors and corrections folow:
    - decl and incl don't affect CF, so replace with subl/addl $1
    - repe uses %cx, so move size to it with movw
    - moving a 64-bit value with %cx of 2 (should be 4) so addresses
      > 2TB will work.
    
    PR:                     233180
    Reviewed by:            imp@ (applied patch using description in bug)
    Differential Revision:  https://reviews.freebsd.org/D31100
---
 stand/i386/pmbr/pmbr.S | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/stand/i386/pmbr/pmbr.S b/stand/i386/pmbr/pmbr.S
index 1a758812edd3..c394835757af 100644
--- a/stand/i386/pmbr/pmbr.S
+++ b/stand/i386/pmbr/pmbr.S
@@ -114,8 +114,9 @@ main.2b:	cmpb $1,%dh			# Reading primary?
 main.3:		movb $0,%dh			# %dh := 0 (reading backup)
 		movw $DPBUF+DPBUF_SEC,%si	# %si = last sector + 1
 		movw $lba,%di			# %di = $lba
-main.3a:	decl (%si)			# 0x0(%si) = last sec (0-31)
-		movw $2,%cx
+main.3a:	subl $1, (%si)			# 0x0(%si) = last sec (0-31)
+		sbbl $0, 4(%si)
+		movw $4,%cx
 		rep
 		movsw				# $lastsec--, copy it to $lba
 		jmp main.2a			# Read the next sector
@@ -128,7 +129,7 @@ load_part:	movw $GPT_ADDR+GPT_PART_LBA,%si
 		call read
 scan:		movw %bx,%si			# Compare partition UUID
 		movw $boot_uuid,%di		#  with FreeBSD boot UUID 
-		movb $0x10,%cl
+		movw $0x10,%cx
 		repe cmpsb
 		jnz next_part			# Didn't match, next partition
 #
@@ -150,7 +151,7 @@ load_boot:	push %si			# Save %si
 		jnz next_boot
 		mov %bx,%es			# Reset %es to zero 
 		jmp LOAD			# Jump to boot code
-next_boot:	incl (%si)			# Next LBA
+next_boot:	addl $1,(%si)			# Next LBA
 		adcl $0,4(%si)
 		mov %es,%ax			# Adjust segment for next
 		addw $SECSIZE/16,%ax		#  sector
@@ -171,7 +172,7 @@ next_part:	decl GPT_ADDR+GPT_NPART		# Was this the last partition?
 		addw %ax,%bx			# Next partition
 		cmpw $PART_ADDR+0x200,%bx	# Still in sector?
 		jb scan
-		incl GPT_ADDR+GPT_PART_LBA	# Next sector
+		addl $1, GPT_ADDR+GPT_PART_LBA	# Next sector
 		adcl $0,GPT_ADDR+GPT_PART_LBA+4
 		jmp load_part
 #


More information about the dev-commits-src-main mailing list