by Mitja Kolsek, the 0patch Team
September 2022 Windows Updates brought a fix for a remote code execution vulnerability in Windows IKE Extension discovered by Yuki Chen with Cyber KunLun. Soon after that, researchers from 78ResearchLab published an analysis and POC for this vulnerability. This made it possible for us to create a patch for affected "security-adopted" Windows systems that no longer receive official fixes from Microsoft.
The vulnerability is in the code responsible for handling IKEv1 (Internet Key Exchange version 1) key exchange protocol, which is deprecated but still supported for legacy reasons. It is a memory corruption issue, with the POC causing the svchost.exe process hosting the IKEEXT service to crash by attempting to read data beyond an allocated buffer. The crash only occurs with page heap (a debugging accessory) enabled for the process, while in a typical production configuration, the vulnerability could potentially be used for arbitrary code execution (as confirmed by Microsoft's advisory).
Microsoft assigned this issue CVE-2022-34721 and fixed it by adding a check for the length of incoming data, and bypassing the processing of such data if the length is too small. Our micropatch is logically equivalent to Microsoft's:
; 0xaafd8 -> IkeCopyIncomingData
; 0x2d1c0 -> first WfpMemFree block
; 0x2d14f -> jump to NtohHeader in same block as patch
mov r8d, 1Ch ; number of characters to copy; for memcpy in IkeCopyIncomingData
lea rcx, [rbp-30h] ; new buffer; for memcpy in IkeCopyIncomingData mov rdx, r14 ; buffer to copy from; for memcpy in IkeCopyIncomingData
call PIT_0xaafd8 ; call IkeCopyIncomingData
mov rbx, rax ; save return from IkeCopyIncomingData
test rax, rax ; check if return from IkeCopyIncomingData is non-zero
jnz PIT_0x2d1c0 ; jump to WfpMemFree block if non-zero
lea rcx, [rbp-30h] ; buffer with copied data
jmp PIT_0x2d14f ; jmp to NtohHeader in same block as patch
This video demonstrates the effect of our micropatch. With 0patch disabled, launching the POC against a vulnerable computer causes a svchost.exe process to crash due to memory access violation. With 0patch enabled, the vulnerability is no longer there, the malformed IKEv1 packet is blocked, and the service doesn't crash.
The micropatch was written for the following Versions of Windows with all available Windows Updates installed:
- Windows 10 v2004
- Windows 10 v1909
- Windows 10 v1903
- Windows 10 v1809
- Windows 10 v1803
- Windows 7 without ESU, with year 1 of ESU and with year 2 of ESU
- Windows Server 2008 R2 without ESU, with year 1 of ESU and with year 2 of ESU
We'd like to thank Yuki Chen for finding this issue, and 78ResearchLab researchers for publishing their analysis and providing a proof-of-concept that allowed us to reproduce the vulnerability and create a micropatch. We also encourage security researchers to privately share their analyses with us for micropatching.