From a68d895e4d04e8f21e79ec93efaa9892d4141fc4 Mon Sep 17 00:00:00 2001 From: Pierre Schweitzer Date: Sun, 24 Feb 2008 10:06:37 +0000 Subject: [PATCH] =?UTF-8?q?-=20Added=20more=20checks=20when=20mounting=20a?= =?UTF-8?q?=20volume=20(based=20on:=20http://technet2.microsoft.com/window?= =?UTF-8?q?sserver/en/library/8cc5891d-bf8e-4164-862d-dac5418c59481033.msp?= =?UTF-8?q?x)=20-=20Removed=20some=20useless=20debug=20Thanks=20to=20Herv?= =?UTF-8?q?=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit svn path=/trunk/; revision=32462 --- reactos/drivers/filesystems/ntfs/fsctl.c | 72 +++++++++++++++--------- reactos/drivers/filesystems/ntfs/ntfs.h | 2 +- 2 files changed, 45 insertions(+), 29 deletions(-) diff --git a/reactos/drivers/filesystems/ntfs/fsctl.c b/reactos/drivers/filesystems/ntfs/fsctl.c index 1103329f8e3..95cee620ab9 100644 --- a/reactos/drivers/filesystems/ntfs/fsctl.c +++ b/reactos/drivers/filesystems/ntfs/fsctl.c @@ -21,7 +21,8 @@ * FILE: drivers/filesystems/ntfs/fsctl.c * PURPOSE: NTFS filesystem driver * PROGRAMMER: Eric Kohl - * Updated by Valentin Verkhovsky 2003/09/12 + * Valentin Verkhovsky + * Pierre Schweitzer */ /* INCLUDES *****************************************************************/ @@ -44,9 +45,9 @@ NtfsHasFileSystem(PDEVICE_OBJECT DeviceToMount) { PARTITION_INFORMATION PartitionInfo; DISK_GEOMETRY DiskGeometry; - ULONG Size; PBOOT_SECTOR BootSector; NTSTATUS Status; + ULONG Size, k; DPRINT1("NtfsHasFileSystem() called\n"); @@ -102,18 +103,45 @@ NtfsHasFileSystem(PDEVICE_OBJECT DeviceToMount) DiskGeometry.BytesPerSector, (PVOID)BootSector, TRUE); - if (NT_SUCCESS(Status)) + if (!NT_SUCCESS(Status)) { - DPRINT1("NTFS-identifier: [%.8s]\n", BootSector->OEMID); - if (RtlCompareMemory(BootSector->OEMID, "NTFS ", 8) != 8) + goto ByeBye; + } + + /* Check values of different fields. If those fields have not expected + * values, we fail, to avoid mounting partitions that Windows won't mount. + */ + /* OEMID: this field must be NTFS */ + if (RtlCompareMemory(BootSector->OEMID, "NTFS ", 8) != 8) + { + DPRINT1("Failed with NTFS-identifier: [%.8s]\n", BootSector->OEMID); + Status = STATUS_UNRECOGNIZED_VOLUME; + goto ByeBye; + } + /* Unused0: this field must be COMPLETELY null */ + for (k=0; k<7; k++) + { + if (BootSector->BPB.Unused0[k] != 0) { + DPRINT1("Failed in field Unused0: [%.7s]\n", BootSector->BPB.Unused0); Status = STATUS_UNRECOGNIZED_VOLUME; + goto ByeBye; + } + } + /* Unused3: this field must be COMPLETELY null */ + for (k=0; k<4; k++) + { + if (BootSector->BPB.Unused3[k] != 0) + { + DPRINT1("Failed in field Unused3: [%.4s]\n", BootSector->BPB.Unused3); + Status = STATUS_UNRECOGNIZED_VOLUME; + goto ByeBye; } } +ByeBye: ExFreePool(BootSector); - - return(Status); + return Status; } @@ -181,21 +209,15 @@ NtfsGetVolumeData(PDEVICE_OBJECT DeviceObject, else NtfsInfo->BytesPerFileRecord = 1 << (-BootSector->EBPB.ClustersPerMftRecord); -//#ifndef NDEBUG - DbgPrint("Boot sector information:\n"); - DbgPrint(" BytesPerSector: %hu\n", BootSector->BPB.BytesPerSector); - DbgPrint(" SectorsPerCluster: %hu\n", BootSector->BPB.SectorsPerCluster); - - DbgPrint(" SectorCount: %I64u\n", BootSector->EBPB.SectorCount); - - DbgPrint(" MftStart: %I64u\n", BootSector->EBPB.MftLocation); - DbgPrint(" MftMirrStart: %I64u\n", BootSector->EBPB.MftMirrLocation); - - DbgPrint(" ClustersPerMftRecord: %lx\n", BootSector->EBPB.ClustersPerMftRecord); - DbgPrint(" ClustersPerIndexRecord: %lx\n", BootSector->EBPB.ClustersPerIndexRecord); - - DbgPrint(" SerialNumber: %I64x\n", BootSector->EBPB.SerialNumber); -//#endif + DPRINT("Boot sector information:\n"); + DPRINT(" BytesPerSector: %hu\n", BootSector->BPB.BytesPerSector); + DPRINT(" SectorsPerCluster: %hu\n", BootSector->BPB.SectorsPerCluster); + DPRINT(" SectorCount: %I64u\n", BootSector->EBPB.SectorCount); + DPRINT(" MftStart: %I64u\n", BootSector->EBPB.MftLocation); + DPRINT(" MftMirrStart: %I64u\n", BootSector->EBPB.MftMirrLocation); + DPRINT(" ClustersPerMftRecord: %lx\n", BootSector->EBPB.ClustersPerMftRecord); + DPRINT(" ClustersPerIndexRecord: %lx\n", BootSector->EBPB.ClustersPerIndexRecord); + DPRINT(" SerialNumber: %I64x\n", BootSector->EBPB.SerialNumber); ExFreePool(BootSector); @@ -234,17 +256,11 @@ NtfsGetVolumeData(PDEVICE_OBJECT DeviceObject, return Status; } -#ifndef NDEBUG - DbgPrint("\n\n"); /* Enumerate attributes */ NtfsDumpFileAttributes (MftRecord); - DbgPrint("\n\n"); - DbgPrint("\n\n"); /* Enumerate attributes */ NtfsDumpFileAttributes (VolumeRecord); - DbgPrint("\n\n"); -#endif /* Get volume name */ Attribute = FindAttribute (VolumeRecord, AttributeVolumeName, NULL); diff --git a/reactos/drivers/filesystems/ntfs/ntfs.h b/reactos/drivers/filesystems/ntfs/ntfs.h index 3523d6e6829..5aa741d8bff 100644 --- a/reactos/drivers/filesystems/ntfs/ntfs.h +++ b/reactos/drivers/filesystems/ntfs/ntfs.h @@ -38,7 +38,7 @@ typedef struct _BIOS_PARAMETERS_BLOCK typedef struct _EXTENDED_BIOS_PARAMETERS_BLOCK { - UCHAR Unknown[4]; // 0x24, always 80 00 80 00 + USHORT Unknown[2]; // 0x24, always 80 00 80 00 ULONGLONG SectorCount; // 0x28 ULONGLONG MftLocation; // 0x30 ULONGLONG MftMirrLocation; // 0x38