October 27th, 2016

How to electrify your own fence: ProcessStrictHandleCheckPolicy

During process termination, if you try to enter a critical section that is owned by another thread that has already been terminated, the gates are now electrified, and the kernel simply terminates your process.

We saw that an invalid handle error and an object type mismatch error both mean that your critical section is corrupted.

And as noted in a comment on the last linked article, there is an option (enabled by default for Store apps) to electrify the fences and raise a exception if an application tries to use an invalid handle or an invalid type of handle (for example, trying to Set­Event on a semaphore). Classic Win32 applications can opt into this behavior by calling Set­Process­Mitigation­Policy and asking for the Process­Strict­Handle­Check­Policy to be turned on.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.