Skip to content

Skip DXGI device discovery if Win32k system calls are disabled - #29755

Merged
adrastogi merged 4 commits into
microsoft:mainfrom
shiyi9801:skip_dxgi_if_win32k_lockdown
Jul 23, 2026
Merged

Skip DXGI device discovery if Win32k system calls are disabled#29755
adrastogi merged 4 commits into
microsoft:mainfrom
shiyi9801:skip_dxgi_if_win32k_lockdown

Conversation

@shiyi9801

Copy link
Copy Markdown
Contributor

Description

Skip DXGI device discovery when Win32k system calls are disabled.

DXGI internally calls gdi32!DdQueryDisplaySettingsUniqueness, which reads from the GDI shared memory section. Under Win32k lockdown this section may not be mapped (depending on the host's gdi32 initialization strategy), causing an access violation.

gdi32!DdQueryDisplaySettingsUniqueness+0x7:
00007ff8`30cf45f7 8b8090001800    mov     eax,dword ptr [rax+180090h] ds:00000000`00180090=????????

# Child-SP          RetAddr               Call Site
00 00000072`4b5fc6f8 00007ff8`2b0f583e     gdi32!DdQueryDisplaySettingsUniqueness+0x7
01 00000072`4b5fc700 00007ff8`2b0f433f     dxgi!CDXGIFactory::SampleAdapters+0xae
02 00000072`4b5fc780 00007ff8`2b0f3f6a     dxgi!CDXGIFactory::Initialize+0x10f
03 00000072`4b5fc870 00007ff8`2b0f34b8     dxgi!CreateDXGIFactoryImpl+0x9a
04 00000072`4b5fc8f0 00007fff`a9e08856     dxgi!CreateDXGIFactoryActualImpl2+0x58
05 00000072`4b5fc930 00007fff`a9e075c3     onnxruntime!onnxruntime::`anonymous namespace'::GetDeviceInfoD3D12+0x86 [device_discovery.cc @ 337]
06 00000072`4b5fcc10 00007fff`a9dec8a1     onnxruntime!onnxruntime::DeviceDiscovery::DiscoverDevicesForPlatform+0x323 [device_discovery.cc @ 584]
07 00000072`4b5fd000 00007fff`a9ded12e     onnxruntime!`onnxruntime::DeviceDiscovery::GetDevices'::`2'::<lambda_1>::operator()+0x61 [device_discovery_common.cc @ 20]
08 00000072`4b5fd4c0 00007fff`a93b6c46     onnxruntime!onnxruntime::DeviceDiscovery::GetDevices+0x7e [device_discovery_common.cc @ 19]
09 00000072`4b5fd4f0 00007fff`a93b2d7d     onnxruntime!onnxruntime::`anonymous namespace'::SortDevicesByType+0x36 [environment.cc @ 781]

Motivation and Context

WebNN is migrating ORT graph compilation to a sandboxed process with PROCESS_MITIGATION_SYSTEM_CALL_DISABLE_POLICY.DisallowWin32kSystemCalls enabled. This prevents calls through GDI for security hardening.

This change has no effect on normal (unsandboxed) processes.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens Windows device discovery for sandboxed processes by avoiding DXGI-based D3D12 adapter enumeration when Win32k system calls are disabled, preventing an access violation during DXGI factory initialization under Win32k lockdown.

Changes:

  • Gate both SetupDi-based discovery and D3D12/DXGI-based discovery behind a Win32k-disallowed mitigation policy check.
  • Preserve device enumeration via DXCore-only paths under Win32k lockdown (CPU still falls back to CPUID).
  • Update inline comments and logging to reflect the expanded skip behavior.

@shiyi9801
shiyi (shiyi9801) force-pushed the skip_dxgi_if_win32k_lockdown branch from 19ae009 to fc3552a Compare July 20, 2026 03:19
@shiyi9801

Copy link
Copy Markdown
Contributor Author

Hi, adrastogi Scott McKay (@skottmckay) Could you take a look? thanks!
The related Chromium issue: https://issues.chromium.org/issues/535696699

@huningxin

Copy link
Copy Markdown
Contributor

adrastogi
adrastogi previously approved these changes Jul 21, 2026

@adrastogi adrastogi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One nit, but looks good to me otherwise.

Comment thread onnxruntime/core/platform/windows/device_discovery.cc Outdated
adrastogi
adrastogi previously approved these changes Jul 22, 2026

@adrastogi adrastogi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@shiyi9801

Copy link
Copy Markdown
Contributor Author

Looks like Lint / Python format (pull_request) failed. I updated the code with clang formatted. Please help merge this PR if it looks good to you, thanks!

@adrastogi
adrastogi merged commit 1cee619 into microsoft:main Jul 23, 2026
85 of 86 checks passed
adrastogi added a commit that referenced this pull request Aug 12, 2026
This cherry-picks the following commits for the release:

* #29799 
* #29755
* #29681

---------

Co-authored-by: shiyi <shiyi.zou@intel.com>
Co-authored-by: mingmingtasd <mingming1.xu@intel.com>
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.

5 participants