Skip to content

win32ss: fix TOCTOU in NtUserEnumDisplayDevices#7

Draft
Copilot wants to merge 1 commit into
masterfrom
copilot/fix-toctu-violation
Draft

win32ss: fix TOCTOU in NtUserEnumDisplayDevices#7
Copilot wants to merge 1 commit into
masterfrom
copilot/fix-toctu-violation

Conversation

Copilot AI commented Jun 12, 2026

Copy link
Copy Markdown

pDisplayDevice->cb was read from user-mode memory up to four times after the initial ProbeForWrite — including as the length argument to RtlCopyMemory. A racing user thread could inflate the value between the probe and the copy, causing the kernel to read past the end of the stack-local dispdev buffer and write that data into user space (kernel stack disclosure).

Fix

Capture pDisplayDevice->cb once into a local variable immediately after the probe, clamp it there, and use only the local for the subsequent ProbeForWrite and RtlCopyMemory.

// before
pDisplayDevice->cb = min(pDisplayDevice->cb, sizeof(dispdev));
ProbeForWrite(pDisplayDevice, pDisplayDevice->cb, 1);       // re-read #1
RtlCopyMemory(pDisplayDevice, &dispdev, pDisplayDevice->cb); // re-read #2

// after
DWORD cbCopy = min(pDisplayDevice->cb, sizeof(dispdev));
ProbeForWrite(pDisplayDevice, cbCopy, 1);
RtlCopyMemory(pDisplayDevice, &dispdev, cbCopy);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants