SUPHardenedVerify-win.h revision 9f997e760f610c92e3a365be21ead6972bc46130
/* $Id$ */
/** @file
*/
/*
* Copyright (C) 2006-2014 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
#ifndef ___win_SUPHardenedVerify_win_h
#define ___win_SUPHardenedVerify_win_h
#ifndef SUP_CERTIFICATES_ONLY
# ifdef RT_OS_WINDOWS
# endif
#endif
#ifndef SUP_CERTIFICATES_ONLY
# ifdef RT_OS_WINDOWS
DECLHIDDEN(void) supHardenedWinTermImageVerifier(void);
typedef enum SUPHARDNTVPKIND
{
SUPHARDNTVPKIND_32BIT_HACK = 0x7fffffff
DECLHIDDEN(int) supHardenedWinVerifyProcess(HANDLE hProcess, HANDLE hThread, SUPHARDNTVPKIND enmKind,
DECLHIDDEN(bool) supHardViUtf16PathIsEqualEx(PCRTUTF16 pawcLeft, size_t cwcLeft, const char *pszRight);
/**
* SUP image verifier loader reader instance.
*/
typedef struct SUPHNTVIRDR
{
/** The core reader structure. */
/** The file handle . */
/** Current file offset. */
/** The file size. */
/** Flags for the verification callback, SUPHNTVI_F_XXX. */
/** The executable timstamp in second since unix epoch. */
/** Log name. */
char szFilename[1];
} SUPHNTVIRDR;
/** Pointer to an SUP image verifier loader reader instance. */
typedef SUPHNTVIRDR *PSUPHNTVIRDR;
DECLHIDDEN(int) supHardNtViRdrCreate(HANDLE hFile, PCRTUTF16 pwszName, uint32_t fFlags, PSUPHNTVIRDR *ppNtViRdr);
DECLHIDDEN(bool) supHardenedWinIsWinVerifyTrustCallable(void);
DECLHIDDEN(int) supHardenedWinVerifyImageTrust(HANDLE hFile, PCRTUTF16 pwszName, uint32_t fFlags, int rc,
DECLHIDDEN(int) supHardenedWinVerifyImageByHandle(HANDLE hFile, PCRTUTF16 pwszName, uint32_t fFlags, bool fAvoidWinVerifyTrust,
DECLHIDDEN(int) supHardenedWinVerifyImageByHandleNoName(HANDLE hFile, uint32_t fFlags, PRTERRINFO pErrInfo);
DECLHIDDEN(int) supHardenedWinVerifyImageByLdrMod(RTLDRMOD hLdrMod, PCRTUTF16 pwszName, PSUPHNTVIRDR pNtViRdr,
/** @name SUPHNTVI_F_XXX - Flags for supHardenedWinVerifyImageByHandle.
* @{ */
/** The signing certificate must be the same as the one the VirtualBox build
* was signed with. */
# define SUPHNTVI_F_REQUIRE_BUILD_CERT RT_BIT(0)
/** Require kernel code signing level. */
/** Require the image to force the memory mapper to do signature checking. */
/** Whether to allow image verification by catalog file. */
/** The file owner must be TrustedInstaller on Vista+. */
/** Resource image, could be any bitness. */
/** Raw-mode context image, always 32-bit. */
/** @} */
/**
* Loader cache entry.
*
* This is for avoiding loading and signature checking a file multiple times,
* due to multiple passes thru the process validation code (and syscall import
* code of NTDLL).
*/
typedef struct SUPHNTLDRCACHEENTRY
{
/** The file name (from g_apszSupNtVpAllowedDlls or
* g_apszSupNtVpAllowedVmExes). */
const char *pszName;
/** Load module associated with the image during content verfication. */
/** The file reader. */
/** The module file handle, if we've opened it.
* (pNtviRdr does not close the file handle on destruction.) */
/** Bits buffer. */
/** Set if verified. */
bool fVerified;
/** Whether we've got valid cacheable image bit.s */
bool fValidBits;
/** The image base address. */
/** Pointer to a loader cache entry. */
typedef SUPHNTLDRCACHEENTRY *PSUPHNTLDRCACHEENTRY;
DECLHIDDEN(int) supHardNtLdrCacheEntryVerify(PSUPHNTLDRCACHEENTRY pEntry, PCRTUTF16 pwszName, PRTERRINFO pErrInfo);
DECLHIDDEN(int) supHardNtLdrCacheEntryGetBits(PSUPHNTLDRCACHEENTRY pEntry, uint8_t **ppbBits, RTLDRADDR uBaseAddress,
/** Which directory under the system root to get. */
typedef enum SUPHARDNTSYSROOTDIR
{
DECLHIDDEN(int) supHardNtGetSystemRootDir(void *pvBuf, uint32_t cbBuf, SUPHARDNTSYSROOTDIR enmDir, PRTERRINFO pErrInfo);
# ifndef SUPHNTVI_NO_NT_STUFF
/** Typical system root directory buffer. */
typedef struct SUPSYSROOTDIRBUF
{
extern SUPSYSROOTDIRBUF g_System32NtPath;
extern SUPSYSROOTDIRBUF g_WinSxSNtPath;
#if defined(IN_RING3) && !defined(VBOX_PERMIT_EVEN_MORE)
extern SUPSYSROOTDIRBUF g_ProgramFilesNtPath;
extern SUPSYSROOTDIRBUF g_CommonFilesNtPath;
# if ARCH_BITS == 64
# endif
#endif /* IN_RING3 && !VBOX_PERMIT_EVEN_MORE */
extern uint32_t g_offSupLibHardenedExeNtName;
# ifdef IN_RING0
/** Pointer to NtQueryVirtualMemory. */
typedef NTSTATUS (NTAPI *PFNNTQUERYVIRTUALMEMORY)(HANDLE, void const *, MEMORY_INFORMATION_CLASS, PVOID, SIZE_T, PSIZE_T);
# endif
# endif /* SUPHNTVI_NO_NT_STUFF */
/** Creates a combined NT version number for simple comparisons. */
/** Simple version of SUP_MAKE_NT_VER_COMBINED. */
#define SUP_MAKE_NT_VER_SIMPLE(a_uMajor, a_uMinor) SUP_MAKE_NT_VER_COMBINED(a_uMajor, a_uMinor, 0, 0, 0)
extern uint32_t g_uNtVerCombined;
/** Combined NT version number for XP. */
/** Combined NT version number for Windows server 2003 & XP64. */
/** Combined NT version number for Vista. */
/** Combined NT version number for Windows 7. */
/** Combined NT version number for Windows 8.0. */
/** Combined NT version number for Windows 8.1. */
# endif
# ifndef IN_SUP_HARDENED_R3
# define suplibHardenedMemComp memcmp
# define suplibHardenedMemCopy memcpy
# define suplibHardenedMemSet memset
# define suplibHardenedStrCopy strcpy
# define suplibHardenedStrLen strlen
# define suplibHardenedStrCat strcat
# define suplibHardenedStrCmp strcmp
# define suplibHardenedStrNCmp strncmp
# else /* IN_SUP_HARDENED_R3 */
# if 0
# define memcmp suplibHardenedMemComp
# define memcpy suplibHardenedMemCopy
# define memset suplibHardenedMemSet
# define strcpy suplibHardenedStrCopy
# define strlen suplibHardenedStrLen
# define strcat suplibHardenedStrCat
# define strcmp suplibHardenedStrCmp
# define strncmp suplibHardenedStrNCmp
# endif
# endif /* IN_SUP_HARDENED_R3 */
#endif /* SUP_CERTIFICATES_ONLY */
#endif