[CSRSRV] Addendum to e3a70662: Fix build.

Since indeeed the memcpy/move type of functions usually don't operate on
pointers to 'volatile' data, don't make ClientCaptureBuffer volatile.
Instead when retrieving the values of its 'Size' and 'PointerCount'
members (see the SEH block), use the so-called technique of "volatile
glasses" [1], where the pointer will be explicitly casted to "volatile TYPE*"
where needed.

[1]: https://docs.microsoft.com/archive/blogs/itgoestoeleven/why-your-user-mode-pointer-captures-are-probably-broken
This commit is contained in:
Hermès Bélusca-Maïto 2020-04-15 15:53:47 +02:00
parent 2032c3afba
commit 1815aae877
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0

View file

@ -1120,8 +1120,7 @@ CsrCaptureArguments(IN PCSR_THREAD CsrThread,
IN PCSR_API_MESSAGE ApiMessage)
{
PCSR_PROCESS CsrProcess = CsrThread->Process;
volatile CSR_CAPTURE_BUFFER* ClientCaptureBuffer;
PCSR_CAPTURE_BUFFER ServerCaptureBuffer = NULL;
PCSR_CAPTURE_BUFFER ClientCaptureBuffer, ServerCaptureBuffer = NULL;
ULONG_PTR EndOfClientBuffer;
SIZE_T SizeOfBufferThroughOffsetsArray;
SIZE_T BufferDistance;
@ -1151,7 +1150,7 @@ CsrCaptureArguments(IN PCSR_THREAD CsrThread,
}
/* Capture the buffer length */
Length = ClientCaptureBuffer->Size;
Length = ((volatile CSR_CAPTURE_BUFFER*)ClientCaptureBuffer)->Size;
/*
* Now check if the remaining of the buffer is inside our mapped section.
@ -1171,7 +1170,7 @@ CsrCaptureArguments(IN PCSR_THREAD CsrThread,
}
/* Capture the pointer count */
PointerCount = ClientCaptureBuffer->PointerCount;
PointerCount = ((volatile CSR_CAPTURE_BUFFER*)ClientCaptureBuffer)->PointerCount;
/*
* Check whether the total buffer size and the pointer count are consistent