VirtualBox

Changeset 101319 in vbox


Ignore:
Timestamp:
Sep 29, 2023 3:25:06 PM (18 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
159319
Message:

BIOS: Improved invalid boot sector check (see ticketref:21861)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/PC/BIOS/boot.c

    r98103 r101319  
    178178}
    179179
     180
     181#define BOOT_CHK_WORDS  8
     182
     183/* Check if the first n words of a boot sector
     184 * are identical. Only consider the boot sector
     185 * valid if they're not.
     186 */
     187static int valid_bootsect(uint16_t __far *boot)
     188{
     189    int         i;
     190    uint16_t    word1;
     191
     192    word1 = boot[0];
     193    for (i = 1; i < BOOT_CHK_WORDS; ++i) {
     194        if (word1 != boot[i])
     195            break;
     196    }
     197
     198    return i != BOOT_CHK_WORDS;
     199}
     200
    180201// returns bootsegment in ax, drive in bl
    181202uint32_t BIOSCALL int19_function(uint8_t bseqnr)
     
    334355    // NB: It is somewhat common for failed OS installs to have the
    335356    // 0x55AA signature and a valid partition table but zeros in the
    336     // rest of the boot sector. We do a quick check by comparing the first
    337     // and third word of boot sector; if identical, the boot sector is
    338     // extremely unlikely to be valid.
     357    // rest of the boot sector. We check the first few words; if identical,
     358    // the boot sector is extremely unlikely to be valid.
    339359    if (bootdrv != 0) bootchk = 0;
    340360    else bootchk = 1; /* disable 0x55AA signature check on drive A: */
     
    346366#endif // BX_ELTORITO_BOOT
    347367
    348     if (read_word(bootseg,0) == read_word(bootseg,4)
     368    if (!valid_bootsect(MK_FP(bootseg,0))
    349369      || (bootchk == 0 && read_word(bootseg,0x1fe) != 0xaa55))
    350370    {
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette