Repository navigation
fix: enable SeIncreaseBasePriorityPrivilege when setting High I/O priority - #65
Conversation
… map privilege errors
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
Thanks for the PR. Please scope SeIncreaseBasePriorityPrivilege to the NtSetInformationProcess operation. Capture PreviousState when calling AdjustTokenPrivileges and restore it in a finally block on both success and failure. Since this modifies the process-wide token, please also prevent overlapping callers from restoring the privilege while another call still needs it. Add a Windows integration test that verifies the original privilege state is restored. The existing fake-based tests do not exercise the native token path. |
…th reference counting
|
Thanks for the detailed and constructive review @PrimeBuild-pc! I've addressed all four points in commit 795db6f: 1. Scoped Privilege to
|
|
The new native integration coverage does not yet verify concurrent callers. |
|
Good catch @PrimeBuild-pc! You're completely right that nested scopes on a single thread don't exercise inter-thread concurrency and potential race conditions between independent callers. I've added the requested concurrent multi-threaded integration test in commit df5cf5d (
All 769 tests are passing locally on Windows ( |
PrimeBuild-pc
left a comment
There was a problem hiding this comment.
Verified df5cf5d against the requested changes. The new Windows integration test uses two independent threads and a barrier, releases the first scope while the second is still active, checks that the privilege remains enabled, and verifies the original state after the final disposal. The native implementation captures PreviousState and protects shared scope reference counts with a lock; the service disposes the scope in finally on success and failure. Ran the full Release test suite on Windows: 769 passed, 0 failed. SeShutdownPrivilege is present and initially disabled on this machine, so the concurrency test exercises actual token changes. CI build/test/security checks and CodeQL are also green. The local token does not contain SeIncreaseBasePriorityPrivilege, so a live elevated High-I/O operation was not exercised locally. Thank you for addressing the review.
Description
When configuring process I/O priority to
High(ProcessIoPriority.High/ level 3), Windows NT requiresSeIncreaseBasePriorityPrivilegein the calling process's token.Even though ThreadPilot runs elevated as administrator, Windows administrative user tokens have
SeIncreaseBasePriorityPrivilegedisabled by default until explicitly enabled viaAdjustTokenPrivileges. Without enabling this privilege,NtSetInformationProcess(..., ProcessIoPriority, ...)fails with NTSTATUS0xC0000061(STATUS_PRIVILEGE_NOT_HELD). In ThreadPilot, this unmapped status previously produced a genericNativeApplyFailederror while leaving targeted processes stuck at default/throttled Low I/O priority.Changes
Privilege Adjustment P/Invoke:
OpenProcessToken,LookupPrivilegeValueW,AdjustTokenPrivileges) toProcessMemoryPriorityNativeMethods.TryEnablePrivilegeand exposedTryEnableProcessPrivilegeonIProcessMemoryPriorityNativeApi.Acquire Privilege on High I/O Priority:
ProcessMemoryPriorityService.SetIoPriorityAsyncto invokeTryEnableProcessPrivilege(SeIncreaseBasePriorityPrivilege)before callingSetIoPrioritywhen requestingProcessIoPriority.High.Status Code Mapping:
0xC0000061(STATUS_PRIVILEGE_NOT_HELD) alongside0xC0000022(STATUS_ACCESS_DENIED) toAffinityApplyErrorCodes.AccessDeniedand user-friendly access denied messaging.Unit Tests:
ProcessMemoryPriorityServiceTestsverifying thatProcessIoPriority.Highattempts to acquireSeIncreaseBasePriorityPrivilege.0xC0000061maps safely toAccessDenied.Verification
0xC0000061error mapping.