Skip to content

Commit 843c86b

Browse files
committed
ahci: lock the disk if security disabled
1 parent a98e74f commit 843c86b

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/x86/ahci.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -444,27 +444,28 @@ int sata_unlock_disk(int drv, int freeze)
444444
#ifdef TARGET_x86_fsp_qemu
445445
wolfBoot_printf("DISK LOCK SECRET: %s\r\n", secret);
446446
#endif
447-
448447
ata_st = ata_security_get_state(drv);
449448
wolfBoot_printf("ATA: Security state SEC%d\r\n", ata_st);
450449
#if defined(TARGET_x86_fsp_qemu)
451450
if (ata_st == ATA_SEC0)
452451
return 0;
453452
#endif
454453
if (ata_st == ATA_SEC1) {
454+
AHCI_DEBUG_PRINTF("ATA: calling set passphrase\r\n", r);
455+
r = ata_security_set_password(drv, 0, (char*)secret);
456+
if (r != 0)
457+
return -1;
458+
AHCI_DEBUG_PRINTF("ATA: calling freeze lock\r\n", r);
455459
if (freeze) {
456-
AHCI_DEBUG_PRINTF("ATA identify: calling freeze lock\r\n", r);
457460
r = ata_security_freeze_lock(drv);
458461
AHCI_DEBUG_PRINTF("ATA security freeze lock: returned %d\r\n", r);
459462
if (r != 0)
460463
return -1;
461-
} else {
462-
AHCI_DEBUG_PRINTF("ATA security freeze skipped\r\n");
463464
}
464465
r = ata_identify_device(drv);
465466
AHCI_DEBUG_PRINTF("ATA identify: returned %d\r\n", r);
466467
ata_st = ata_security_get_state(drv);
467-
wolfBoot_printf("ATA: Security disabled. State SEC%d\r\n", ata_st);
468+
wolfBoot_printf("ATA: State SEC%d\r\n", ata_st);
468469
}
469470
else if (ata_st == ATA_SEC4) {
470471
AHCI_DEBUG_PRINTF("ATA identify: calling device unlock\r\n", r);
@@ -487,14 +488,15 @@ int sata_unlock_disk(int drv, int freeze)
487488
r = ata_identify_device(drv);
488489
AHCI_DEBUG_PRINTF("ATA identify: returned %d\r\n", r);
489490
}
490-
ata_st = ata_security_get_state(drv);
491-
AHCI_DEBUG_PRINTF("ATA: Security enabled. State SEC%d\r\n", ata_st);
492-
if ((freeze && ata_st != ATA_SEC6) || (!freeze && ata_st != ATA_SEC5)) {
493-
panic();
494-
}
495-
ata_st = ata_security_get_state(drv);
496-
wolfBoot_printf("ATA: Security enabled. State SEC%d\r\n", ata_st);
497491
}
492+
ata_st = ata_security_get_state(drv);
493+
if ((freeze && ata_st != ATA_SEC6) || (!freeze && ata_st != ATA_SEC5)) {
494+
AHCI_DEBUG_PRINTF("ATA: Security is not enabled/locked (State SEC%d)\r\n",
495+
ata_st);
496+
panic();
497+
}
498+
AHCI_DEBUG_PRINTF("ATA: Security enabled. State SEC%d\r\n", ata_st);
499+
498500
return 0;
499501
}
500502
#endif /* WOLFBOOT_ATA_DISK_LOCK */

0 commit comments

Comments
 (0)