1 | ; $Id: SUPR3HardenedMainA-posix.asm 66605 2017-04-19 07:11:06Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; VirtualBox Support Library - Hardened main(), Posix assembly bits.
|
---|
4 | ;
|
---|
5 |
|
---|
6 | ;
|
---|
7 | ; Copyright (C) 2017 Oracle Corporation
|
---|
8 | ;
|
---|
9 | ; This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | ; available from http://www.virtualbox.org. This file is free software;
|
---|
11 | ; you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | ; General Public License (GPL) as published by the Free Software
|
---|
13 | ; Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | ; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | ; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | ;
|
---|
17 | ; The contents of this file may alternatively be used under the terms
|
---|
18 | ; of the Common Development and Distribution License Version 1.0
|
---|
19 | ; (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | ; VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | ; CDDL are applicable instead of those of the GPL.
|
---|
22 | ;
|
---|
23 | ; You may elect to license modified versions of this file under the
|
---|
24 | ; terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | ;
|
---|
26 |
|
---|
27 |
|
---|
28 | ;*******************************************************************************
|
---|
29 | ;* Header Files *
|
---|
30 | ;*******************************************************************************
|
---|
31 | %include "iprt/asmdefs.mac"
|
---|
32 |
|
---|
33 |
|
---|
34 | ;*********************************************************************************************************************************
|
---|
35 | ;* External Symbols *
|
---|
36 | ;*********************************************************************************************************************************
|
---|
37 | ; External code.
|
---|
38 | BEGINCODE
|
---|
39 | extern NAME(supR3HardenedPosixMonitor_VerifyLibrary)
|
---|
40 |
|
---|
41 | ; External data
|
---|
42 | BEGINDATA
|
---|
43 | extern NAME(g_pfnDlopenReal)
|
---|
44 | %ifdef SUP_HARDENED_WITH_DLMOPEN
|
---|
45 | extern NAME(g_pfnDlmopenReal)
|
---|
46 | %endif
|
---|
47 |
|
---|
48 |
|
---|
49 |
|
---|
50 | BEGINCODE
|
---|
51 |
|
---|
52 | ;;
|
---|
53 | ; Wrapper for dlopen() handing the call over to the file verification code
|
---|
54 | ; and resuming the call if we get a green light to load the library.
|
---|
55 | ;
|
---|
56 | align 16
|
---|
57 | BEGINPROC supR3HardenedPosixMonitor_Dlopen
|
---|
58 | push xBP
|
---|
59 | mov xBP, xSP
|
---|
60 |
|
---|
61 | %ifdef RT_ARCH_AMD64
|
---|
62 | ; Save parameters on the stack
|
---|
63 | push rdi
|
---|
64 | push rsi
|
---|
65 | %else
|
---|
66 | sub esp, 4 ; 16-byte stack alignment before call.
|
---|
67 | push dword [xBP + 08h] ; first parameter.
|
---|
68 | %endif
|
---|
69 |
|
---|
70 | ;
|
---|
71 | ; Call the verification method.
|
---|
72 | ;
|
---|
73 | call NAME(supR3HardenedPosixMonitor_VerifyLibrary)
|
---|
74 |
|
---|
75 | ;
|
---|
76 | ; Restore parameters for the next call and get the stack back to the
|
---|
77 | ; original state.
|
---|
78 | ;
|
---|
79 | %ifdef RT_ARCH_AMD64
|
---|
80 | pop rsi
|
---|
81 | pop rdi
|
---|
82 | %endif
|
---|
83 | leave
|
---|
84 |
|
---|
85 | ; Check the result and resume the call if the result is positive,
|
---|
86 | ; otherwise clean up and return NULL
|
---|
87 | test al, al
|
---|
88 | je short .failed
|
---|
89 |
|
---|
90 | ; Resume the original dlopen call by jumping into the saved code.
|
---|
91 | jmp [NAME(g_pfnDlopenReal) xWrtRIP]
|
---|
92 |
|
---|
93 | .failed:
|
---|
94 | ;
|
---|
95 | ; Don't use leave here as we didn't use the enter instruction. Just clear
|
---|
96 | ; xAX and return
|
---|
97 | ;
|
---|
98 | xor xAX, xAX
|
---|
99 | ret
|
---|
100 | ENDPROC supR3HardenedPosixMonitor_Dlopen
|
---|
101 |
|
---|
102 |
|
---|
103 | %ifdef SUP_HARDENED_WITH_DLMOPEN
|
---|
104 | ;;
|
---|
105 | ; Wrapper for dlmopen() handing the call over to the file verification code
|
---|
106 | ; and resuming the call if we get a green light to load the library.
|
---|
107 | ;
|
---|
108 | align 16
|
---|
109 | BEGINPROC supR3HardenedPosixMonitor_Dlmopen
|
---|
110 | push xBP
|
---|
111 | mov xBP, xSP
|
---|
112 |
|
---|
113 | %ifdef RT_ARCH_AMD64
|
---|
114 | sub rsp, 8 ; 16-byte stack alignment before call.
|
---|
115 |
|
---|
116 | ; Save parameters on the stack
|
---|
117 | push rdi
|
---|
118 | push rsi
|
---|
119 | push rdx
|
---|
120 |
|
---|
121 | mov rdi, rsi ; Move the second parameter to the front
|
---|
122 | %else
|
---|
123 | sub esp, 4 ; 16-byte stack alignment before call.
|
---|
124 | push dword [xBP + 0ch] ; Move the second parameter to the front
|
---|
125 | %endif
|
---|
126 |
|
---|
127 | ;
|
---|
128 | ; Call the verification method.
|
---|
129 | ;
|
---|
130 | call NAME(supR3HardenedPosixMonitor_VerifyLibrary)
|
---|
131 |
|
---|
132 | ;
|
---|
133 | ; Restore parameters for the next call and get the stack back to the
|
---|
134 | ; original state.
|
---|
135 | ;
|
---|
136 | %ifdef RT_ARCH_AMD64
|
---|
137 | pop rdx
|
---|
138 | pop rsi
|
---|
139 | pop rdi
|
---|
140 | %endif
|
---|
141 | leave
|
---|
142 |
|
---|
143 | ; Check the result and resume the call if the result is positive,
|
---|
144 | ; otherwise clean up and return NULL
|
---|
145 | test al, al
|
---|
146 | je short .failed
|
---|
147 |
|
---|
148 | ; Resume the original dlopen call by jumping into the saved code.
|
---|
149 | jmp [NAME(g_pfnDlmopenReal) xWrtRIP]
|
---|
150 |
|
---|
151 | .failed:
|
---|
152 | ;
|
---|
153 | ; Don't use leave here as we didn't use the enter instruction. Just clear
|
---|
154 | ; xAX and return
|
---|
155 | ;
|
---|
156 | xor xAX, xAX
|
---|
157 | ret
|
---|
158 | ENDPROC supR3HardenedPosixMonitor_Dlmopen
|
---|
159 | %endif
|
---|
160 |
|
---|