Skip to content

Commit c7d512a

Browse files
committed
fix device item leak and possible UAF
1 parent 1111e0a commit c7d512a

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

SystemInformer/devprv.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3450,6 +3450,7 @@ PPH_DEVICE_ITEM NTAPI PhpAddDeviceItem(
34503450

34513451
item = PhCreateObjectZero(sizeof(PH_DEVICE_ITEM), PhDeviceItemType);
34523452

3453+
item->Tree = Tree;
34533454
item->DeviceInfo = PhReferenceObject(Tree->DeviceInfo);
34543455
RtlCopyMemory(&item->DeviceInfoData.DeviceData, DeviceInfoData, sizeof(SP_DEVINFO_DATA));
34553456
RtlCopyMemory(&item->ClassGuid, &DeviceInfoData->ClassGuid, sizeof(GUID));
@@ -3540,6 +3541,7 @@ PPH_DEVICE_ITEM NTAPI PhpAddDeviceInterfaceItem(
35403541

35413542
item = PhCreateObjectZero(sizeof(PH_DEVICE_ITEM), PhDeviceItemType);
35423543

3544+
item->Tree = Tree;
35433545
item->DeviceInfo = PhReferenceObject(Tree->DeviceInfo);
35443546
item->DeviceInfoData.Interface = TRUE;
35453547
RtlCopyMemory(&item->DeviceInfoData.InterfaceData, DeviceInterfaceData, sizeof(SP_DEVICE_INTERFACE_DATA));

SystemInformer/include/devprv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ typedef struct _PH_DEVINFO_DATA
308308

309309
typedef struct _PH_DEVICE_ITEM
310310
{
311+
struct _PH_DEVICE_TREE* Tree;
311312
struct _PH_DEVICE_ITEM* Parent;
312313
struct _PH_DEVICE_ITEM* Sibling;
313314
struct _PH_DEVICE_ITEM* Child;

plugins/HardwareDevices/deviceprops.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,8 @@ NTSTATUS DevicePropertiesThreadStart(
973973
PhDereferenceObject(propContext);
974974
}
975975

976+
PhDereferenceObject(context->DeviceItem->Tree);
977+
PhDereferenceObject(context->DeviceItem);
976978
PhFree(context);
977979

978980
return STATUS_SUCCESS;
@@ -989,6 +991,8 @@ BOOLEAN DeviceShowProperties(
989991

990992
context->ParentWindowHandle = ParentWindowHandle;
991993
context->DeviceItem = PhReferenceObject(DeviceItem);
994+
// Since we might use the relationships of the device item, we must reference the tree too.
995+
PhReferenceObject(context->DeviceItem->Tree);
992996

993997
PhCreateThread2(DevicePropertiesThreadStart, context);
994998
return TRUE;

0 commit comments

Comments
 (0)