From 8ef99527391d2ed35f17c8afbcc1039145692a58 Mon Sep 17 00:00:00 2001 From: Amlal Date: Tue, 6 May 2025 11:10:52 +0200 Subject: feat(ahci-generic): validate sector_sz when dealing with AHCI I/O. why? - This will cause math exceptions being raised by the CPU if it happens to be zero. Signed-off-by: Amlal --- dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'dev/kernel') diff --git a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc index 3f2cf9e8..cf1841bd 100644 --- a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc +++ b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc @@ -132,11 +132,16 @@ STATIC Int32 drv_find_cmd_slot_ahci(HbaPort* port) noexcept { template STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz, SizeT size_buffer) noexcept { - NE_UNUSED(sector_sz); + if (sector_sz == 0) { + kout << "Invalid sector size.\r"; + err_global_get() = kErrorDisk; + return; + } lba /= sector_sz; if (lba > kSATASectorCount) { + kout << "Out of range LBA.\r"; err_global_get() = kErrorDisk; return; } @@ -165,6 +170,7 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz // Clear old command table memory volatile HbaCmdTbl* command_table = (volatile HbaCmdTbl*) (((UInt64) command_header->Ctbau << 32) | command_header->Ctba); + rt_set_memory((VoidPtr) command_table, 0, sizeof(HbaCmdTbl)); VoidPtr ptr = rtl_dma_alloc(size_buffer, 4096); @@ -270,7 +276,6 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz ahci_io_end: rtl_dma_free(size_buffer); - err_global_get() = kErrorSuccess; } } -- cgit v1.2.3