From 3d9b919814a8445cf5cb218b9b306b7fc6fa61c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20S=C5=82abo=C5=84?= Date: Thu, 17 Apr 2025 15:26:58 +0200 Subject: [PATCH] [MOUNTMGR] Few fixes and improvements (#7896) - `MountMgrVolumeMountPointChanged()`: Set status code in all failure paths and correct the check for remote or removable media. - `DeleteRemoteDatabaseEntry()`: Do not allow the database with size of zero. - `QueryVolumeName()`: Use reparse point file reference when no file name is supplied. --- drivers/storage/mountmgr/database.c | 12 +++++++----- drivers/storage/mountmgr/device.c | 6 +++++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/drivers/storage/mountmgr/database.c b/drivers/storage/mountmgr/database.c index 9801d708ba0..787a0dffa02 100644 --- a/drivers/storage/mountmgr/database.c +++ b/drivers/storage/mountmgr/database.c @@ -255,8 +255,8 @@ DeleteRemoteDatabaseEntry(IN HANDLE Database, return STATUS_INVALID_PARAMETER; } - /* Validate parameters: ensure we won't get negative size */ - if (Entry->EntrySize + StartingOffset > DatabaseSize) + /* Validate parameters: ensure we won't get zero or negative size */ + if (Entry->EntrySize + StartingOffset >= DatabaseSize) { /* If we get invalid parameters, truncate the whole database * starting the wrong entry. We can't rely on the rest @@ -1303,12 +1303,14 @@ QueryVolumeName(IN HANDLE RootDirectory, PFILE_NAME_INFORMATION FileNameInfo; PREPARSE_DATA_BUFFER ReparseDataBuffer; - UNREFERENCED_PARAMETER(ReparsePointInformation); - if (!FileName) { + UNICODE_STRING Reference; + + Reference.Length = Reference.MaximumLength = sizeof(ReparsePointInformation->FileReference); + Reference.Buffer = (PWSTR)&(ReparsePointInformation->FileReference); InitializeObjectAttributes(&ObjectAttributes, - NULL, + &Reference, OBJ_KERNEL_HANDLE, RootDirectory, NULL); diff --git a/drivers/storage/mountmgr/device.c b/drivers/storage/mountmgr/device.c index 7000d4a4218..15c52ba9ee4 100644 --- a/drivers/storage/mountmgr/device.c +++ b/drivers/storage/mountmgr/device.c @@ -2062,13 +2062,17 @@ MountMgrVolumeMountPointChanged(IN PDEVICE_EXTENSION DeviceExtension, goto Cleanup; } + /* Mount points can be stored only on storage disks */ if (FsDeviceInfo.DeviceType != FILE_DEVICE_DISK && FsDeviceInfo.DeviceType != FILE_DEVICE_VIRTUAL_DISK) { + Status = STATUS_INVALID_PARAMETER; goto Cleanup; } - if (FsDeviceInfo.Characteristics != (FILE_REMOTE_DEVICE | FILE_REMOVABLE_MEDIA)) + /* And they can be on local fixed disks only */ + if (FsDeviceInfo.Characteristics & (FILE_REMOTE_DEVICE | FILE_REMOVABLE_MEDIA)) { + Status = STATUS_INVALID_PARAMETER; goto Cleanup; }