From 8d72eecb3832297e3ac788ff062385f0e101ee14 Mon Sep 17 00:00:00 2001 From: Yoav Orot Date: Mon, 7 Apr 2025 14:21:20 -0400 Subject: [PATCH] Fix a race between sending data and closing the service client port According to documentation, FltCloseClientPort and FltSendMessage are synchronized by both receiving a pointer to the same location that holds the opaque port handle. This fix passes the global client port to both function calls. --- source/P4VFS.Driver/Source/DriverFilter.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/source/P4VFS.Driver/Source/DriverFilter.c b/source/P4VFS.Driver/Source/DriverFilter.c index 8b033b2..349f4e9 100644 --- a/source/P4VFS.Driver/Source/DriverFilter.c +++ b/source/P4VFS.Driver/Source/DriverFilter.c @@ -608,19 +608,10 @@ P4vfsServicePortDisconnect( goto CLEANUP; } - pConnectionHandle = (P4VFS_SERVICE_PORT_CONNECTION_HANDLE*)pConnectionCookie; - if (pConnectionHandle->pClientPort != NULL) - { - // If this connection handle is our exclusive active pServiceClientPort, clear this value as we close the handle - if (pConnectionHandle->pClientPort == g_FltContext.pServiceClientPort) - { - P4vfsTraceInfo(Filter, L"P4vfsServicePortDisconnect: Closed active connection [%p]", g_FltContext.pServiceClientPort); - g_FltContext.pServiceClientPort = NULL; - } - - FltCloseClientPort(g_FltContext.pFilter, &pConnectionHandle->pClientPort); - } + P4vfsTraceInfo(Filter, L"P4vfsServicePortDisconnect: Closed active connection [%p]", g_FltContext.pServiceClientPort); + FltCloseClientPort(g_FltContext.pFilter, &g_FltContext.pServiceClientPort); + pConnectionHandle = (P4VFS_SERVICE_PORT_CONNECTION_HANDLE*)pConnectionCookie; if (pConnectionHandle->hUserProcess != NULL) { ZwClose(pConnectionHandle->hUserProcess);