[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
* 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
* PROGRAMMER: Ge van Geldorp (gvg@reactos.com)
* UPDATE HISTORY:
* 2004/12/04: Created
* 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))
{
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);
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
@ -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;
}