[HALXBOX] Don't use Xbox partitions if MBR signature found (#2253)

* [HALXBOX] Formatting only.

* [HALXBOX] Don't use Xbox partitions if MBR signature found.

- Fixes BSOD 0x7B when booting from a HDD that have both MBR and BRFR signatures.
- It happens when you format Xbox (BRFR) disk as MBR.
  After that "BRFR" signature is still located at sector 3.
- Also fix pre-existing leaks.

CORE-16216 CORE-16329
This commit is contained in:
Stanislav Motylkov 2020-01-18 20:41:32 +03:00 committed by Hermès BÉLUSCA - MAÏTO
parent 0a274da7cd
commit af7ec17ce1
2 changed files with 42 additions and 22 deletions

View file

@ -3,7 +3,7 @@
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
* PURPOSE: Xbox specific routines
* COPYRIGHT: Copyright 2004 van Geldorp (gvg@reactos.com)
* Copyright 2019 Stanislav Motylkov (x86corez@gmail.com)
* Copyright 2019-2020 Stanislav Motylkov (x86corez@gmail.com)
*
* REFERENCES: https://xboxdevwiki.net/SMBus
* https://github.com/XboxDev/cromwell/blob/master/drivers/pci/i2cio.c
@ -17,6 +17,8 @@
#include <hal.h>
#include <ntdddisk.h>
#define TAG_HAL_XBOX 'XlaH'
#define SMB_IO_BASE 0xC000
#define SMB_GLOBAL_STATUS (0 + SMB_IO_BASE)

View file

@ -1,16 +1,15 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: hal/halx86/xbox/part_xbox.c
* PURPOSE: Xbox specific handling of partition tables
* PROGRAMMER: Ge van Geldorp (gvg@reactos.com)
* UPDATE HISTORY:
* 2004/12/04: Created
* PROJECT: Xbox HAL
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
* PURPOSE: Xbox specific handling of partition tables
* COPYRIGHT: Copyright 2004 Ge van Geldorp (gvg@reactos.com)
* Copyright 2020 Stanislav Motylkov (x86corez@gmail.com)
*/
/* INCLUDES *****************************************************************/
#include "halxbox.h"
#include <internal/tag.h>
#define NDEBUG
#include <debug.h>
@ -106,32 +105,51 @@ HalpXboxDeviceHasXboxPartitioning(IN PDEVICE_OBJECT DeviceObject,
PVOID SectorData;
LARGE_INTEGER Offset;
NTSTATUS Status;
BOOLEAN HasMBRPartitioning;
DPRINT("HalpXboxDeviceHasXboxPartitioning(%p %lu %p)\n",
DeviceObject,
SectorSize,
HasXboxPartitioning);
SectorData = ExAllocatePool(PagedPool, SectorSize);
SectorData = ExAllocatePoolWithTag(PagedPool, SectorSize, TAG_HAL_XBOX);
if (!SectorData)
{
return STATUS_NO_MEMORY;
}
Offset.QuadPart = 0;
Status = HalpXboxReadSector(DeviceObject, SectorSize, &Offset, SectorData);
if (!NT_SUCCESS(Status))
{
goto Cleanup;
}
HasMBRPartitioning = (*((USHORT *)SectorData + (SectorSize / sizeof(USHORT)) - 1) == PARTITION_SIGNATURE);
if (HasMBRPartitioning)
{
*HasXboxPartitioning = FALSE;
goto Cleanup;
}
Offset.QuadPart = XBOX_SIGNATURE_SECTOR * SectorSize;
Status = HalpXboxReadSector(DeviceObject, SectorSize, &Offset, SectorData);
if (! NT_SUCCESS(Status))
if (!NT_SUCCESS(Status))
{
return Status;
goto Cleanup;
}
DPRINT("Signature 0x%02x 0x%02x 0x%02x 0x%02x\n",
*((UCHAR *) SectorData), *((UCHAR *) SectorData + 1), *((UCHAR *) SectorData + 2), *((UCHAR *) SectorData + 3));
*HasXboxPartitioning = (XBOX_SIGNATURE == *((ULONG *) SectorData));
ExFreePool(SectorData);
DPRINT("%s partitioning found\n", *HasXboxPartitioning ? "Xbox" : "MBR");
Cleanup:
ExFreePoolWithTag(SectorData, TAG_HAL_XBOX);
if (NT_SUCCESS(Status))
{
DPRINT("%s partitioning found\n", *HasXboxPartitioning ? "Xbox" : "MBR");
}
return STATUS_SUCCESS;
return Status;
}
static VOID FASTCALL
@ -152,12 +170,12 @@ HalpXboxExamineMBR(IN PDEVICE_OBJECT DeviceObject,
*Buffer = NULL;
Status = HalpXboxDeviceHasXboxPartitioning(DeviceObject, SectorSize, &HasXboxPartitioning);
if (! NT_SUCCESS(Status))
if (!NT_SUCCESS(Status))
{
return;
}
if (! HasXboxPartitioning)
if (!HasXboxPartitioning)
{
DPRINT("Delegating to standard MBR code\n");
NtoskrnlExamineMBR(DeviceObject, SectorSize, MBRTypeIdentifier, Buffer);
@ -186,12 +204,12 @@ HalpXboxIoReadPartitionTable(IN PDEVICE_OBJECT DeviceObject,
PartitionBuffer);
Status = HalpXboxDeviceHasXboxPartitioning(DeviceObject, SectorSize, &HasXboxPartitioning);
if (! NT_SUCCESS(Status))
if (!NT_SUCCESS(Status))
{
return Status;
}
if (! HasXboxPartitioning)
if (!HasXboxPartitioning)
{
DPRINT("Delegating to standard MBR code\n");
return NtoskrnlIoReadPartitionTable(DeviceObject, SectorSize,
@ -202,8 +220,8 @@ HalpXboxIoReadPartitionTable(IN PDEVICE_OBJECT DeviceObject,
PagedPool,
sizeof(DRIVE_LAYOUT_INFORMATION) +
XBOX_PARTITION_COUNT * sizeof(PARTITION_INFORMATION),
'SYSF');
if (NULL == *PartitionBuffer)
TAG_FILE_SYSTEM);
if (*PartitionBuffer == NULL)
{
return STATUS_NO_MEMORY;
}
@ -251,7 +269,7 @@ HalpXboxIoSetPartitionInformation(IN PDEVICE_OBJECT DeviceObject,
PartitionType);
Status = HalpXboxDeviceHasXboxPartitioning(DeviceObject, SectorSize, &HasXboxPartitioning);
if (! NT_SUCCESS(Status))
if (!NT_SUCCESS(Status))
{
return Status;
}
@ -286,7 +304,7 @@ HalpXboxIoWritePartitionTable(IN PDEVICE_OBJECT DeviceObject,
PartitionBuffer);
Status = HalpXboxDeviceHasXboxPartitioning(DeviceObject, SectorSize, &HasXboxPartitioning);
if (! NT_SUCCESS(Status))
if (!NT_SUCCESS(Status))
{
return Status;
}