VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/Support/win/SUPHardenedVerify-win.h@ 52936

Last change on this file since 52936 was 52634, checked in by vboxsync, 11 years ago

SUP: Fix deadlock problem when mounting ISO on vista. (Never all WinVerifyTrust while holding the loader semaphore.)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.2 KB
Line 
1/* $Id: SUPHardenedVerify-win.h 52634 2014-09-06 20:21:03Z vboxsync $ */
2/** @file
3 * VirtualBox Support Library/Driver - Hardened Verification, Windows.
4 */
5
6/*
7 * Copyright (C) 2006-2014 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#ifndef ___win_SUPHardenedVerify_win_h
28#define ___win_SUPHardenedVerify_win_h
29
30#include <iprt/types.h>
31#include <iprt/crypto/x509.h>
32#ifndef SUP_CERTIFICATES_ONLY
33# ifdef RT_OS_WINDOWS
34# include <iprt/ldr.h>
35# endif
36#endif
37
38
39RT_C_DECLS_BEGIN
40
41#ifndef SUP_CERTIFICATES_ONLY
42# ifdef RT_OS_WINDOWS
43DECLHIDDEN(int) supHardenedWinInitImageVerifier(PRTERRINFO pErrInfo);
44DECLHIDDEN(void) supHardenedWinTermImageVerifier(void);
45DECLHIDDEN(void) supR3HardenedWinVerifyCacheScheduleImports(RTLDRMOD hLdrMod, PCRTUTF16 pwszName);
46DECLHIDDEN(void) supR3HardenedWinVerifyCachePreload(PCRTUTF16 pwszName);
47
48
49typedef enum SUPHARDNTVPKIND
50{
51 SUPHARDNTVPKIND_VERIFY_ONLY = 1,
52 SUPHARDNTVPKIND_CHILD_PURIFICATION,
53 SUPHARDNTVPKIND_SELF_PURIFICATION,
54 SUPHARDNTVPKIND_32BIT_HACK = 0x7fffffff
55} SUPHARDNTVPKIND;
56DECLHIDDEN(int) supHardenedWinVerifyProcess(HANDLE hProcess, HANDLE hThread, SUPHARDNTVPKIND enmKind,
57 uint32_t *pcFixes, PRTERRINFO pErrInfo);
58
59DECLHIDDEN(bool) supHardViUtf16PathIsEqualEx(PCRTUTF16 pawcLeft, size_t cwcLeft, const char *pszRight);
60DECLHIDDEN(bool) supHardViUniStrPathStartsWithUniStr(UNICODE_STRING const *pUniStrLeft,
61 UNICODE_STRING const *pUniStrRight, bool fCheckSlash);
62DECLHIDDEN(bool) supHardViUtf16PathStartsWithEx(PCRTUTF16 pwszLeft, uint32_t cwcLeft,
63 PCRTUTF16 pwszRight, uint32_t cwcRight, bool fCheckSlash);
64DECLHIDDEN(bool) supHardViIsAppPatchDir(PCRTUTF16 pwszPath, uint32_t cwcName);
65
66
67/**
68 * SUP image verifier loader reader instance.
69 */
70typedef struct SUPHNTVIRDR
71{
72 /** The core reader structure. */
73 RTLDRREADER Core;
74 /** The file handle . */
75 HANDLE hFile;
76 /** Current file offset. */
77 RTFOFF off;
78 /** The file size. */
79 RTFOFF cbFile;
80 /** Flags for the verification callback, SUPHNTVI_F_XXX. */
81 uint32_t fFlags;
82 /** The executable timstamp in second since unix epoch. */
83 uint64_t uTimestamp;
84 /** Log name. */
85 char szFilename[1];
86} SUPHNTVIRDR;
87/** Pointer to an SUP image verifier loader reader instance. */
88typedef SUPHNTVIRDR *PSUPHNTVIRDR;
89DECLHIDDEN(int) supHardNtViRdrCreate(HANDLE hFile, PCRTUTF16 pwszName, uint32_t fFlags, PSUPHNTVIRDR *ppNtViRdr);
90DECLHIDDEN(bool) supHardenedWinIsWinVerifyTrustCallable(void);
91DECLHIDDEN(int) supHardenedWinVerifyImageTrust(HANDLE hFile, PCRTUTF16 pwszName, uint32_t fFlags, int rc,
92 bool *pfWinVerifyTrust, PRTERRINFO pErrInfo);
93DECLHIDDEN(int) supHardenedWinVerifyImageByHandle(HANDLE hFile, PCRTUTF16 pwszName, uint32_t fFlags, bool fAvoidWinVerifyTrust,
94 bool *pfWinVerifyTrust, PRTERRINFO pErrInfo);
95DECLHIDDEN(int) supHardenedWinVerifyImageByHandleNoName(HANDLE hFile, uint32_t fFlags, PRTERRINFO pErrInfo);
96DECLHIDDEN(int) supHardenedWinVerifyImageByLdrMod(RTLDRMOD hLdrMod, PCRTUTF16 pwszName, PSUPHNTVIRDR pNtViRdr,
97 bool fAvoidWinVerifyTrust, bool *pfWinVerifyTrust, PRTERRINFO pErrInfo);
98/** @name SUPHNTVI_F_XXX - Flags for supHardenedWinVerifyImageByHandle.
99 * @{ */
100/** The signing certificate must be the same as the one the VirtualBox build
101 * was signed with. */
102# define SUPHNTVI_F_REQUIRE_BUILD_CERT RT_BIT(0)
103/** Require kernel code signing level. */
104# define SUPHNTVI_F_REQUIRE_KERNEL_CODE_SIGNING RT_BIT(1)
105/** Require the image to force the memory mapper to do signature checking. */
106# define SUPHNTVI_F_REQUIRE_SIGNATURE_ENFORCEMENT RT_BIT(2)
107/** Whether to allow image verification by catalog file. */
108# define SUPHNTVI_F_ALLOW_CAT_FILE_VERIFICATION RT_BIT(3)
109/** The file owner must be TrustedInstaller on Vista+. */
110# define SUPHNTVI_F_TRUSTED_INSTALLER_OWNER RT_BIT(4)
111/** Resource image, could be any bitness. */
112# define SUPHNTVI_F_RESOURCE_IMAGE RT_BIT(30)
113/** Raw-mode context image, always 32-bit. */
114# define SUPHNTVI_F_RC_IMAGE RT_BIT(31)
115/** @} */
116
117/**
118 * Loader cache entry.
119 *
120 * This is for avoiding loading and signature checking a file multiple times,
121 * due to multiple passes thru the process validation code (and syscall import
122 * code of NTDLL).
123 */
124typedef struct SUPHNTLDRCACHEENTRY
125{
126 /** The file name (from g_apszSupNtVpAllowedDlls or
127 * g_apszSupNtVpAllowedVmExes). */
128 const char *pszName;
129 /** Load module associated with the image during content verfication. */
130 RTLDRMOD hLdrMod;
131 /** The file reader. */
132 PSUPHNTVIRDR pNtViRdr;
133 /** The module file handle, if we've opened it.
134 * (pNtviRdr does not close the file handle on destruction.) */
135 HANDLE hFile;
136 /** Bits buffer. */
137 uint8_t *pbBits;
138 /** Set if verified. */
139 bool fVerified;
140} SUPHNTLDRCACHEENTRY;
141/** Pointer to a loader cache entry. */
142typedef SUPHNTLDRCACHEENTRY *PSUPHNTLDRCACHEENTRY;
143DECLHIDDEN(int) supHardNtLdrCacheOpen(const char *pszName, PSUPHNTLDRCACHEENTRY *ppEntry);
144DECLHIDDEN(int) supHardNtLdrCacheEntryVerify(PSUPHNTLDRCACHEENTRY pEntry, PCRTUTF16 pwszName, PRTERRINFO pErrInfo);
145DECLHIDDEN(int) supHardNtLdrCacheEntryAllocBits(PSUPHNTLDRCACHEENTRY pEntry, uint8_t **ppbBits, PRTERRINFO pErrInfo);
146
147
148/** Which directory under the system root to get. */
149typedef enum SUPHARDNTSYSROOTDIR
150{
151 kSupHardNtSysRootDir_System32 = 0,
152 kSupHardNtSysRootDir_WinSxS,
153} SUPHARDNTSYSROOTDIR;
154
155DECLHIDDEN(int) supHardNtGetSystemRootDir(void *pvBuf, uint32_t cbBuf, SUPHARDNTSYSROOTDIR enmDir, PRTERRINFO pErrInfo);
156
157# ifndef SUPHNTVI_NO_NT_STUFF
158
159/** Typical system root directory buffer. */
160typedef struct SUPSYSROOTDIRBUF
161{
162 UNICODE_STRING UniStr;
163 WCHAR awcBuffer[260];
164} SUPSYSROOTDIRBUF;
165extern SUPSYSROOTDIRBUF g_System32NtPath;
166extern SUPSYSROOTDIRBUF g_WinSxSNtPath;
167#ifdef IN_RING3
168extern SUPSYSROOTDIRBUF g_ProgramFilesNtPath;
169extern SUPSYSROOTDIRBUF g_CommonFilesNtPath;
170# if ARCH_BITS == 64
171extern SUPSYSROOTDIRBUF g_ProgramFilesX86NtPath;
172extern SUPSYSROOTDIRBUF g_CommonFilesX86NtPath;
173# endif
174#endif
175extern SUPSYSROOTDIRBUF g_SupLibHardenedExeNtPath;
176extern uint32_t g_offSupLibHardenedExeNtName;
177
178# ifdef IN_RING0
179/** Pointer to NtQueryVirtualMemory. */
180typedef NTSTATUS (NTAPI *PFNNTQUERYVIRTUALMEMORY)(HANDLE, void const *, MEMORY_INFORMATION_CLASS, PVOID, SIZE_T, PSIZE_T);
181extern PFNNTQUERYVIRTUALMEMORY g_pfnNtQueryVirtualMemory;
182# endif
183
184# endif /* SUPHNTVI_NO_NT_STUFF */
185
186/** Creates a combined NT version number for simple comparisons. */
187#define SUP_MAKE_NT_VER_COMBINED(a_uMajor, a_uMinor, a_uBuild, a_uSpMajor, a_uSpMinor) \
188 ( ((uint32_t)((a_uMajor) & UINT32_C(0xf)) << 28) \
189 | ((uint32_t)((a_uMinor) & UINT32_C(0xf)) << 24) \
190 | ((uint32_t)((a_uBuild) & UINT32_C(0xffff)) << 8) \
191 | ((uint32_t)((a_uSpMajor) & UINT32_C(0xf)) << 4) \
192 | RT_MIN((uint32_t)(a_uSpMinor), UINT32_C(0xf)) )
193/** Simple version of SUP_MAKE_NT_VER_COMBINED. */
194#define SUP_MAKE_NT_VER_SIMPLE(a_uMajor, a_uMinor) SUP_MAKE_NT_VER_COMBINED(a_uMajor, a_uMinor, 0, 0, 0)
195extern uint32_t g_uNtVerCombined;
196
197/** Combined NT version number for XP. */
198#define SUP_NT_VER_XP SUP_MAKE_NT_VER_SIMPLE(5,1)
199/** Combined NT version number for Windows server 2003 & XP64. */
200#define SUP_NT_VER_W2K3 SUP_MAKE_NT_VER_SIMPLE(5,2)
201/** Combined NT version number for Vista. */
202#define SUP_NT_VER_VISTA SUP_MAKE_NT_VER_SIMPLE(6,0)
203/** Combined NT version number for Windows 7. */
204#define SUP_NT_VER_W70 SUP_MAKE_NT_VER_SIMPLE(6,1)
205/** Combined NT version number for Windows 8.0. */
206#define SUP_NT_VER_W80 SUP_MAKE_NT_VER_SIMPLE(6,2)
207/** Combined NT version number for Windows 8.1. */
208#define SUP_NT_VER_W81 SUP_MAKE_NT_VER_SIMPLE(6,3)
209
210# endif
211
212# ifndef IN_SUP_HARDENED_R3
213# include <iprt/mem.h>
214# include <iprt/string.h>
215
216# define suplibHardenedAllocZ RTMemAllocZ
217# define suplibHardenedReAlloc RTMemRealloc
218# define suplibHardenedFree RTMemFree
219# define suplibHardenedMemComp memcmp
220# define suplibHardenedMemCopy memcpy
221# define suplibHardenedMemSet memset
222# define suplibHardenedStrCopy strcpy
223# define suplibHardenedStrLen strlen
224# define suplibHardenedStrCat strcat
225# define suplibHardenedStrCmp strcmp
226# define suplibHardenedStrNCmp strncmp
227# else /* IN_SUP_HARDENED_R3 */
228# include <iprt/mem.h>
229#if 0
230# define memcmp suplibHardenedMemComp
231# define memcpy suplibHardenedMemCopy
232# define memset suplibHardenedMemSet
233# define strcpy suplibHardenedStrCopy
234# define strlen suplibHardenedStrLen
235# define strcat suplibHardenedStrCat
236# define strcmp suplibHardenedStrCmp
237# define strncmp suplibHardenedStrNCmp
238#endif
239DECLHIDDEN(void *) suplibHardenedAllocZ(size_t cb);
240DECLHIDDEN(void *) suplibHardenedReAlloc(void *pvOld, size_t cbNew);
241DECLHIDDEN(void) suplibHardenedFree(void *pv);
242# endif /* IN_SUP_HARDENED_R3 */
243
244#endif /* SUP_CERTIFICATES_ONLY */
245
246RT_C_DECLS_END
247
248#endif
249
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette