Skip to content

Commit

Permalink
driver: maintain owner process id field of CUsbDkRedirection
Browse files Browse the repository at this point in the history
Set owner process id when device redirection successfully
established (i.e. filter device is open and respective user
mode handle created for the process).

Signed-off-by: Yuri Benditovich <[email protected]>
  • Loading branch information
ybendito authored and YanVugenfirer committed Jan 2, 2020
1 parent db6c11f commit 427b3f0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
9 changes: 9 additions & 0 deletions UsbDk/ControlDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,12 @@ void CUsbDkRedirection::Dump(LPCSTR message) const
m_DeviceID, m_InstanceID);
}

bool CUsbDkRedirection::MatchProcess(ULONG pid)
{
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_WDFDEVICE, "%!FUNC! pid 0x%X, owner 0x%X", pid, m_OwnerPid);
return pid == m_OwnerPid;
}

void CUsbDkRedirection::NotifyRedirectorCreated(CUsbDkFilterDevice *RedirectorDevice)
{
TraceEvents(TRACE_LEVEL_ERROR, TRACE_WDFDEVICE, "%!FUNC! Redirector created for");
Expand Down Expand Up @@ -1209,6 +1215,9 @@ NTSTATUS CUsbDkRedirection::CreateRedirectorHandle(HANDLE RequestorProcess, PHAN
status = m_RedirectorDevice->CreateUserModeHandle(RequestorProcess, ObjectHandle);
if (NT_SUCCESS(status))
{
ULONG pid = (ULONG)(ULONG_PTR)PsGetCurrentProcessId();
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_WDFDEVICE, "%!FUNC! done for process 0x%X", pid);
m_OwnerPid = pid;
return status;
}

Expand Down
3 changes: 3 additions & 0 deletions UsbDk/ControlDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ class CUsbDkRedirection : public CAllocatable<USBDK_NON_PAGED_POOL, 'NRHR'>, pub
bool IsPreparedForRemove() const
{ return m_RemovalInProgress; }

bool MatchProcess(ULONG pid);

NTSTATUS WaitForAttachment()
{ return m_RedirectionCreated.Wait(true, -SecondsTo100Nanoseconds(120)); }

Expand All @@ -216,6 +218,7 @@ class CUsbDkRedirection : public CAllocatable<USBDK_NON_PAGED_POOL, 'NRHR'>, pub
CWdmEvent m_RedirectionCreated;
CWdmEvent m_RedirectionRemoved;
CUsbDkFilterDevice *m_RedirectorDevice = nullptr;
ULONG m_OwnerPid = 0;

bool m_RemovalInProgress = false;

Expand Down

0 comments on commit 427b3f0

Please sign in to comment.