2002-08-17 David Welch <welch@computer2.darkstar.org>

* ntoskrnl/mm/rmap.c (MmWritePagePhysicalAddress): Ensure the
	process isn't freed in the middle of our operations.

2002-08-17  David Welch  <welch@computer2.darkstar.org>

	* drivers/fs/vfat/finfo.c (VfatSetAllocationSizeInformation): Fixed.

svn path=/trunk/; revision=3336
This commit is contained in:
David Welch 2002-08-17 14:14:20 +00:00
parent 1a46ca7d8a
commit c62229b967
3 changed files with 60 additions and 27 deletions

View file

@ -1,3 +1,12 @@
2002-08-17 David Welch <welch@computer2.darkstar.org>
* ntoskrnl/mm/rmap.c (MmWritePagePhysicalAddress): Ensure the
process isn't freed in the middle of our operations.
2002-08-17 David Welch <welch@computer2.darkstar.org>
* drivers/fs/vfat/finfo.c (VfatSetAllocationSizeInformation): Fixed.
2002-08-17 David Welch <welch@computer2.darkstar.org> 2002-08-17 David Welch <welch@computer2.darkstar.org>
* ntoskrnl/ps/create.c (PiDeleteThread): Don't dereference * ntoskrnl/ps/create.c (PiDeleteThread): Don't dereference

View file

@ -1,4 +1,4 @@
/* $Id: finfo.c,v 1.15 2002/08/14 20:58:31 dwelch Exp $ /* $Id: finfo.c,v 1.16 2002/08/17 14:14:19 dwelch Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -351,14 +351,15 @@ VfatSetAllocationSizeInformation(PFILE_OBJECT FileObject,
PLARGE_INTEGER AllocationSize) PLARGE_INTEGER AllocationSize)
{ {
ULONG OldSize; ULONG OldSize;
ULONG FirstCluster;
ULONG Cluster; ULONG Cluster;
ULONG Offset; ULONG i;
NTSTATUS Status; NTSTATUS Status;
PDEVICE_EXTENSION DeviceExt = PDEVICE_EXTENSION DeviceExt =
(PDEVICE_EXTENSION)DeviceObject->DeviceExtension; (PDEVICE_EXTENSION)DeviceObject->DeviceExtension;
ULONG ClusterSize = DeviceExt->FatInfo.BytesPerCluster; ULONG ClusterSize = DeviceExt->FatInfo.BytesPerCluster;
ULONG NewSize = AllocationSize->u.LowPart; ULONG NewSize = AllocationSize->u.LowPart;
ULONG NextCluster; ULONG PreviousCluster;
OldSize = Fcb->entry.FileSize; OldSize = Fcb->entry.FileSize;
if (OldSize == AllocationSize->u.LowPart) if (OldSize == AllocationSize->u.LowPart)
@ -373,30 +374,36 @@ VfatSetAllocationSizeInformation(PFILE_OBJECT FileObject,
if (DeviceExt->FatInfo.FatType == FAT32) if (DeviceExt->FatInfo.FatType == FAT32)
{ {
Cluster = Fcb->entry.FirstCluster + Fcb->entry.FirstClusterHigh * 65536; FirstCluster = Fcb->entry.FirstCluster +
Fcb->entry.FirstClusterHigh * 65536;
} }
else else
{ {
Cluster = Fcb->entry.FirstCluster; FirstCluster = Fcb->entry.FirstCluster;
} }
Cluster = FirstCluster;
if (OldSize > NewSize && if (OldSize > NewSize &&
ROUND_UP(OldSize, ClusterSize) > ROUND_DOWN(NewSize, ClusterSize)) ROUND_UP(OldSize, ClusterSize) > ROUND_DOWN(NewSize, ClusterSize))
{ {
/* Seek to the new end of the file. */ /* Seek to the new end of the file. */
Offset = 0; for (i = 0; i < (NewSize / ClusterSize); i++)
while (Cluster != 0xffffffff && Cluster > 1 && Offset <= NewSize)
{ {
Status = GetNextCluster (DeviceExt, Cluster, &NextCluster, FALSE); Status = NextCluster (DeviceExt, Fcb, FirstCluster, &Cluster, FALSE);
Cluster = NextCluster; }
Offset += ClusterSize; /* Terminate the FAT chain at this point. */
if (NewSize > 0)
{
PreviousCluster = Cluster;
Status = NextCluster (DeviceExt, Fcb, FirstCluster, &Cluster, FALSE);
WriteCluster (DeviceExt, PreviousCluster, 0xFFFFFFFF);
} }
/* Free everything beyond this point. */ /* Free everything beyond this point. */
while (Cluster != 0xffffffff && Cluster > 1) while (Cluster != 0xffffffff && Cluster > 1)
{ {
Status = GetNextCluster (DeviceExt, Cluster, &NextCluster, FALSE); PreviousCluster = Cluster;
WriteCluster (DeviceExt, Cluster, 0xFFFFFFFF); Status = NextCluster (DeviceExt, Fcb, FirstCluster, &Cluster, FALSE);
Cluster = NextCluster; WriteCluster (DeviceExt, PreviousCluster, 0);
} }
if (NewSize == 0) if (NewSize == 0)
{ {
@ -408,21 +415,17 @@ VfatSetAllocationSizeInformation(PFILE_OBJECT FileObject,
ROUND_UP(NewSize, ClusterSize) > ROUND_DOWN(OldSize, ClusterSize)) ROUND_UP(NewSize, ClusterSize) > ROUND_DOWN(OldSize, ClusterSize))
{ {
/* Seek to the new end of the file. */ /* Seek to the new end of the file. */
Offset = 0;
if (OldSize == 0) if (OldSize == 0)
{ {
assert(Cluster == 0); assert(FirstCluster == 0);
Status = GetNextCluster (DeviceExt, 0, &NextCluster, TRUE); Status = NextCluster (DeviceExt, Fcb, FirstCluster, &Cluster, TRUE);
Fcb->entry.FirstCluster = (NextCluster & 0x0000FFFF) >> 0; FirstCluster = Cluster;
Fcb->entry.FirstClusterHigh = (NextCluster & 0xFFFF0000) >> 16; Fcb->entry.FirstCluster = (FirstCluster & 0x0000FFFF) >> 0;
Cluster = NextCluster; Fcb->entry.FirstClusterHigh = (FirstCluster & 0xFFFF0000) >> 16;
Offset += ClusterSize;
} }
while (Cluster != 0xffffffff && Cluster > 1 && Offset <= NewSize) for (i = 0; i < (NewSize / ClusterSize); i++)
{ {
Status = GetNextCluster (DeviceExt, Cluster, &NextCluster, TRUE); Status = NextCluster (DeviceExt, Fcb, FirstCluster, &Cluster, TRUE);
Cluster = NextCluster;
Offset += ClusterSize;
} }
} }

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* $Id: rmap.c,v 1.8 2002/08/14 20:58:36 dwelch Exp $ /* $Id: rmap.c,v 1.9 2002/08/17 14:14:20 dwelch Exp $
* *
* COPYRIGHT: See COPYING in the top directory * COPYRIGHT: See COPYING in the top directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -69,6 +69,10 @@ MmWritePagePhysicalAddress(PHYSICAL_ADDRESS PhysicalAddress)
LARGE_INTEGER Offset; LARGE_INTEGER Offset;
NTSTATUS Status; NTSTATUS Status;
/*
* Check that the address still has a valid rmap; then reference the
* process so it isn't freed while we are working.
*/
ExAcquireFastMutex(&RmapListLock); ExAcquireFastMutex(&RmapListLock);
entry = MmGetRmapListHeadPage(PhysicalAddress); entry = MmGetRmapListHeadPage(PhysicalAddress);
if (entry == NULL) if (entry == NULL)
@ -82,10 +86,22 @@ MmWritePagePhysicalAddress(PHYSICAL_ADDRESS PhysicalAddress)
{ {
KeBugCheck(0); KeBugCheck(0);
} }
ObReferenceObjectByPointer(Process, PROCESS_ALL_ACCESS, NULL, KernelMode);
ExReleaseFastMutex(&RmapListLock); ExReleaseFastMutex(&RmapListLock);
/*
* Lock the address space; then check that the address we are using
* still corresponds to a valid memory area (the page might have been
* freed or paged out after we read the rmap entry.)
*/
MmLockAddressSpace(&Process->AddressSpace); MmLockAddressSpace(&Process->AddressSpace);
MemoryArea = MmOpenMemoryAreaByAddress(&Process->AddressSpace, Address); MemoryArea = MmOpenMemoryAreaByAddress(&Process->AddressSpace, Address);
if (MemoryArea == NULL)
{
ObDereferenceObject(Process);
return(STATUS_UNSUCCESSFUL);
}
Type = MemoryArea->Type; Type = MemoryArea->Type;
if (Type == MEMORY_AREA_SECTION_VIEW) if (Type == MEMORY_AREA_SECTION_VIEW)
{ {
@ -104,6 +120,8 @@ MmWritePagePhysicalAddress(PHYSICAL_ADDRESS PhysicalAddress)
KeBugCheck(0); KeBugCheck(0);
} }
ObDereferenceObject(Process);
if (PageOp->Thread != PsGetCurrentThread()) if (PageOp->Thread != PsGetCurrentThread())
{ {
MmReleasePageOp(PageOp); MmReleasePageOp(PageOp);
@ -126,6 +144,9 @@ MmWritePagePhysicalAddress(PHYSICAL_ADDRESS PhysicalAddress)
{ {
PageOp = MmGetPageOp(MemoryArea, Process->UniqueProcessId, PageOp = MmGetPageOp(MemoryArea, Process->UniqueProcessId,
Address, NULL, 0, MM_PAGEOP_PAGEOUT); Address, NULL, 0, MM_PAGEOP_PAGEOUT);
ObDereferenceObject(Process);
if (PageOp->Thread != PsGetCurrentThread()) if (PageOp->Thread != PsGetCurrentThread())
{ {
MmReleasePageOp(PageOp); MmReleasePageOp(PageOp);
@ -147,7 +168,7 @@ MmWritePagePhysicalAddress(PHYSICAL_ADDRESS PhysicalAddress)
else else
{ {
KeBugCheck(0); KeBugCheck(0);
} }
return(Status); return(Status);
} }