예전에 한번 블로그에서 다루기도 했었지만 다시보니 글이 엉망인 것 같아 다시 정리하게 되었다.
(참고 : https://sone.tistory.com/235 )
먼저 MSDN에서 Nt와 Zw에 대한 차이를 다루는지 보면 다음과 같습니다.
For system calls from user mode, the Nt and Zw versions of a routine behave identically. For calls from a kernel-mode driver, the Nt and Zw versions of a routine differ in how they handle the parameter values that the caller passes to the routine. |
요약하면 유저레벨에서는 Nt와 Zw 두 루틴 모두 동일한 루틴을 사용하고 커널모드에서는 두 루틴에 차이가 있다고 합니다. 우선 유저영역에서는 ntdll내부에서 Nt와 Zw는 모두 같은 주소를 갖습니다. 올리로 쉽게 확인가능합니다. 그렇다면 커널 영역에서 어떤 차이를 가지는지 더 읽어 보겠습니다.
A kernel-mode driver calls the Zw version of a native system services routine to inform the routine that the parameters come from a trusted, kernel-mode source. In this case, the routine assumes that it can safely use the parameters without first validating them. However, if the parameters might be from either a user-mode source or a kernel-mode source, the driver instead calls the Nt version of the routine, which determines, based on the history of the calling thread, whether the parameters originated in user mode or kernel mode. For more information about how the routine distinguishes user-mode parameters from kernel-mode parameters, see PreviousMode. |
정리하면 Zw와 Nt와의 차이는 같은 기능을 수행하지만 파라미터 검증에 차이를 가진다고 합니다. Zw가 호출되는 경우는 파라미터에 대해 신뢰성을 가지고 있을 때 호출되고 Nt경우는 파라미터 검증이 필요할때 사용합니다. Nt는 내부적으로 전달된 파라미터가 유저영역에서 호출되었는지 커널모드에서 호출되었는지 thread를 통하여 검증한다고 하는데 아마 _ETHREAD.Tcb.PreviousMode를 참조하는 모양입니다.
결론적으로 Zw는 파라미터검증을 안하고 Nt는 파라미터 검증을 한다! 입니다.
'Security > Windows System' 카테고리의 다른 글
Kernel API Prefix (0) | 2020.05.28 |
---|---|
Windows on Windows 64 : x64시스템에서 x86 프로그램 시스템 콜 (0) | 2020.05.28 |
I/O Control Code를 정의하는 CTL_CODE (0) | 2018.07.31 |
Windows x64커널 진입 : 커널모드편 (1) | 2018.04.14 |
x64 Calling Convention(Windows) (0) | 2018.04.14 |
댓글