Changeset 56733 in vbox for trunk/src/VBox/HostDrivers
- Timestamp:
- Jul 1, 2015 2:01:43 PM (10 years ago)
- Location:
- trunk/src/VBox/HostDrivers/Support
- Files:
-
- 7 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/SUPLibInternal.h
r56293 r56733 79 79 # define supR3HardenedPathAppPrivateNoArch supR3HardenedStaticPathAppPrivateNoArch 80 80 # define supR3HardenedPathAppPrivateArch supR3HardenedStaticPathAppPrivateArch 81 # define supR3HardenedPath SharedLibs supR3HardenedStaticPathSharedLibs81 # define supR3HardenedPathAppSharedLibs supR3HardenedStaticPathAppSharedLibs 82 82 # define supR3HardenedPathAppDocs supR3HardenedStaticPathAppDocs 83 # define supR3HardenedPath ExecDir supR3HardenedStaticPathExecDir83 # define supR3HardenedPathAppBin supR3HardenedStaticPathAppBin 84 84 # define supR3HardenedPathFilename supR3HardenedStaticPathFilename 85 85 # define supR3HardenedFatalV supR3HardenedStaticFatalV … … 176 176 { 177 177 kSupID_Invalid = 0, 178 kSupID_Bin,179 178 kSupID_AppBin, 180 kSupID_ SharedLib,179 kSupID_AppSharedLib, 181 180 kSupID_AppPrivArch, 182 181 kSupID_AppPrivArchComp, … … 382 381 DECLHIDDEN(int) supR3HardenedPathAppPrivateArch(char *pszPath, size_t cchPath); 383 382 /** @copydoc RTPathSharedLibs */ 384 DECLHIDDEN(int) supR3HardenedPath SharedLibs(char *pszPath, size_t cchPath);383 DECLHIDDEN(int) supR3HardenedPathAppSharedLibs(char *pszPath, size_t cchPath); 385 384 /** @copydoc RTPathAppDocs */ 386 385 DECLHIDDEN(int) supR3HardenedPathAppDocs(char *pszPath, size_t cchPath); 387 386 /** @copydoc RTPathExecDir */ 388 DECLHIDDEN(int) supR3HardenedPath ExecDir(char *pszPath, size_t cchPath);387 DECLHIDDEN(int) supR3HardenedPathAppBin(char *pszPath, size_t cchPath); 389 388 /** @copydoc RTPathFilename */ 390 389 DECLHIDDEN(char *) supR3HardenedPathFilename(const char *pszPath); … … 441 440 442 441 443 DECLHIDDEN(int) supR3HardenedVerifyAll(bool fFatal, const char *pszProgName );442 DECLHIDDEN(int) supR3HardenedVerifyAll(bool fFatal, const char *pszProgName, const char *pszExePath); 444 443 DECLHIDDEN(int) supR3HardenedVerifyFixedDir(SUPINSTDIR enmDir, bool fFatal); 445 444 DECLHIDDEN(int) supR3HardenedVerifyFixedFile(const char *pszFilename, bool fFatal); … … 452 451 #ifdef RT_OS_WINDOWS 453 452 DECLHIDDEN(void) supR3HardenedWinInit(uint32_t fFlags, bool fAvastKludge); 453 DECLHIDDEN(void) supR3HardenedWinInitAppBin(uint32_t fFlags); 454 454 DECLHIDDEN(void) supR3HardenedWinInitVersion(void); 455 455 DECLHIDDEN(void) supR3HardenedWinInitImports(void); 456 DECLHIDDEN(void) supR3HardenedWinModifyDllSearchPath(uint32_t fFlags, const char *pszAppBinPath); 456 457 # ifdef ___iprt_nt_nt_h___ 457 458 DECLHIDDEN(void) supR3HardenedWinGetVeryEarlyImports(uintptr_t uNtDllAddr, -
trunk/src/VBox/HostDrivers/Support/SUPR3HardenedIPRT.cpp
r56293 r56733 71 71 * @copydoc RTPathSharedLibs 72 72 */ 73 DECLHIDDEN(int) supR3HardenedPath SharedLibs(char *pszPath, size_t cchPath)73 DECLHIDDEN(int) supR3HardenedPathAppSharedLibs(char *pszPath, size_t cchPath) 74 74 { 75 75 return RTPathSharedLibs(pszPath, cchPath); … … 89 89 * @copydoc RTPathExecDir 90 90 */ 91 DECLHIDDEN(int) supR3HardenedPath ExecDir(char *pszPath, size_t cchPath)91 DECLHIDDEN(int) supR3HardenedPathAppBin(char *pszPath, size_t cchPath) 92 92 { 93 93 return RTPathExecDir(pszPath, cchPath); -
trunk/src/VBox/HostDrivers/Support/SUPR3HardenedMain.cpp
r56293 r56733 134 134 #endif 135 135 char g_szSupLibHardenedExePath[RTPATH_MAX]; 136 /** The programdirectory path. */137 static char g_szSupLibHardened DirPath[RTPATH_MAX];136 /** The application bin directory path. */ 137 static char g_szSupLibHardenedAppBinPath[RTPATH_MAX]; 138 138 139 139 /** The program name. */ … … 781 781 782 782 #else 783 return supR3HardenedPath ExecDir(pszPath, cchPath);783 return supR3HardenedPathAppBin(pszPath, cchPath); 784 784 #endif 785 785 } … … 800 800 801 801 #else 802 return supR3HardenedPath ExecDir(pszPath, cchPath);802 return supR3HardenedPathAppBin(pszPath, cchPath); 803 803 #endif 804 804 } … … 808 808 * @copydoc RTPathSharedLibs 809 809 */ 810 DECLHIDDEN(int) supR3HardenedPath SharedLibs(char *pszPath, size_t cchPath)810 DECLHIDDEN(int) supR3HardenedPathAppSharedLibs(char *pszPath, size_t cchPath) 811 811 { 812 812 #if !defined(RT_OS_WINDOWS) && defined(RTPATH_SHARED_LIBS) … … 814 814 size_t cchPathSharedLibs = suplibHardenedStrLen(pszSrcPath); 815 815 if (cchPathSharedLibs >= cchPath) 816 supR3HardenedFatal("supR3HardenedPath SharedLibs: Buffer overflow, %zu >= %zu\n", cchPathSharedLibs, cchPath);816 supR3HardenedFatal("supR3HardenedPathAppSharedLibs: Buffer overflow, %zu >= %zu\n", cchPathSharedLibs, cchPath); 817 817 suplibHardenedMemCopy(pszPath, pszSrcPath, cchPathSharedLibs + 1); 818 818 return VINF_SUCCESS; 819 819 820 820 #else 821 return supR3HardenedPath ExecDir(pszPath, cchPath);821 return supR3HardenedPathAppBin(pszPath, cchPath); 822 822 #endif 823 823 } … … 838 838 839 839 #else 840 return supR3HardenedPath ExecDir(pszPath, cchPath);840 return supR3HardenedPathAppBin(pszPath, cchPath); 841 841 #endif 842 842 } … … 911 911 912 912 /* 913 * Strip off the filename part (RTPathStripFilename()). 914 */ 915 suplibHardenedStrCopy(g_szSupLibHardenedDirPath, g_szSupLibHardenedExePath); 916 suplibHardenedPathStripFilename(g_szSupLibHardenedDirPath); 913 * Determine the application binary directory location. 914 */ 915 suplibHardenedStrCopy(g_szSupLibHardenedAppBinPath, g_szSupLibHardenedExePath); 916 suplibHardenedPathStripFilename(g_szSupLibHardenedAppBinPath); 917 918 if (g_enmSupR3HardenedMainState < SUPR3HARDENEDMAINSTATE_HARDENED_MAIN_CALLED) 919 supR3HardenedFatal("supR3HardenedExecDir: Called before SUPR3HardenedMain! (%d)\n", g_enmSupR3HardenedMainState); 920 switch (g_fSupHardenedMain & SUPSECMAIN_FLAGS_LOC_MASK) 921 { 922 case SUPSECMAIN_FLAGS_LOC_APP_BIN: 923 break; 924 case SUPSECMAIN_FLAGS_LOC_TESTCASE: 925 suplibHardenedPathStripFilename(g_szSupLibHardenedAppBinPath); 926 break; 927 default: 928 supR3HardenedFatal("supR3HardenedExecDir: Unknown program binary location: %#x\n", g_fSupHardenedMain); 929 } 917 930 } 918 931 … … 939 952 /** 940 953 * @copydoc RTPathExecDir 941 */ 942 DECLHIDDEN(int) supR3HardenedPathExecDir(char *pszPath, size_t cchPath) 954 * @remarks not quite like RTPathExecDir actually... 955 */ 956 DECLHIDDEN(int) supR3HardenedPathAppBin(char *pszPath, size_t cchPath) 943 957 { 944 958 /* 945 959 * Lazy init (probably not required). 946 960 */ 947 if (!g_szSupLibHardened DirPath[0])961 if (!g_szSupLibHardenedAppBinPath[0]) 948 962 supR3HardenedGetFullExePath(); 949 963 … … 951 965 * Calc the length and check if there is space before copying. 952 966 */ 953 size_t cch = suplibHardenedStrLen(g_szSupLibHardened DirPath) + 1;967 size_t cch = suplibHardenedStrLen(g_szSupLibHardenedAppBinPath) + 1; 954 968 if (cch <= cchPath) 955 969 { 956 suplibHardenedMemCopy(pszPath, g_szSupLibHardened DirPath, cch + 1);970 suplibHardenedMemCopy(pszPath, g_szSupLibHardenedAppBinPath, cch + 1); 957 971 return VINF_SUCCESS; 958 972 } 959 973 960 supR3HardenedFatal("supR3HardenedPath ExecDir: Buffer too small (%u < %u)\n", cchPath, cch);974 supR3HardenedFatal("supR3HardenedPathAppBin: Buffer too small (%u < %u)\n", cchPath, cch); 961 975 return VERR_BUFFER_OVERFLOW; 962 976 } … … 1628 1642 */ 1629 1643 char szPath[RTPATH_MAX]; 1630 supR3HardenedPath SharedLibs(szPath, sizeof(szPath) - sizeof("/VBoxRT" SUPLIB_DLL_SUFF));1644 supR3HardenedPathAppSharedLibs(szPath, sizeof(szPath) - sizeof("/VBoxRT" SUPLIB_DLL_SUFF)); 1631 1645 suplibHardenedStrCat(szPath, "/VBoxRT" SUPLIB_DLL_SUFF); 1632 1646 … … 1774 1788 char szPath[RTPATH_MAX]; 1775 1789 supR3HardenedPathAppPrivateArch(szPath, sizeof(szPath) - 10); 1790 const char *pszSubDirSlash; 1791 switch (g_fSupHardenedMain & SUPSECMAIN_FLAGS_LOC_MASK) 1792 { 1793 case SUPSECMAIN_FLAGS_LOC_APP_BIN: 1794 pszSubDirSlash = "/"; 1795 break; 1796 case SUPSECMAIN_FLAGS_LOC_TESTCASE: 1797 pszSubDirSlash = "/testcase/"; 1798 break; 1799 default: 1800 pszSubDirSlash = "/"; 1801 supR3HardenedFatal("supR3HardenedMainGetTrustedMain: Unknown program binary location: %#x\n", g_fSupHardenedMain); 1802 } 1776 1803 size_t cch = suplibHardenedStrLen(szPath); 1777 suplibHardenedStrCopyEx(&szPath[cch], sizeof(szPath) - cch, "/", pszProgName, SUPLIB_DLL_SUFF, NULL);1804 suplibHardenedStrCopyEx(&szPath[cch], sizeof(szPath) - cch, pszSubDirSlash, pszProgName, SUPLIB_DLL_SUFF, NULL); 1778 1805 1779 1806 /* … … 1844 1871 g_SupPreInitData.Data.hDevice = SUP_HDEVICE_NIL; 1845 1872 1873 /* 1874 * Determine the full exe path as we'll be needing it for the verify all 1875 * call(s) below. (We have to do this early on Linux because we * *might* 1876 * not be able to access /proc/self/exe after the seteuid call.) 1877 */ 1878 supR3HardenedGetFullExePath(); 1879 #ifdef RT_OS_WINDOWS 1880 supR3HardenedWinInitAppBin(fFlags); 1881 #endif 1882 1846 1883 #ifdef SUP_HARDENED_SUID 1847 # ifdef RT_OS_LINUX1848 /*1849 * On linux we have to make sure the path is initialized because we1850 * *might* not be able to access /proc/self/exe after the seteuid call.1851 */1852 supR3HardenedGetFullExePath();1853 # endif1854 1855 1884 /* 1856 1885 * Grab any options from the environment. … … 1881 1910 SUP_DPRINTF(("SUPR3HardenedMain: Respawn #1\n")); 1882 1911 supR3HardenedWinInit(SUPSECMAIN_FLAGS_DONT_OPEN_DEV, false /*fAvastKludge*/); 1883 supR3HardenedVerifyAll(true /* fFatal */, pszProgName );1912 supR3HardenedVerifyAll(true /* fFatal */, pszProgName, g_szSupLibHardenedExePath); 1884 1913 return supR3HardenedWinReSpawn(1 /*iWhich*/); 1885 1914 } … … 1898 1927 * Validate the installation. 1899 1928 */ 1900 supR3HardenedVerifyAll(true /* fFatal */, pszProgName );1929 supR3HardenedVerifyAll(true /* fFatal */, pszProgName, g_szSupLibHardenedExePath); 1901 1930 1902 1931 /* … … 1963 1992 g_enmSupR3HardenedMainState = SUPR3HARDENEDMAINSTATE_INIT_RUNTIME; 1964 1993 supR3HardenedMainInitRuntime(fFlags); 1994 #ifdef RT_OS_WINDOWS 1995 supR3HardenedWinModifyDllSearchPath(fFlags, g_szSupLibHardenedAppBinPath); 1996 #endif 1965 1997 1966 1998 /* -
trunk/src/VBox/HostDrivers/Support/SUPR3HardenedMainTemplateTestcase.cpp
r56721 r56733 1 1 /* $Id$ */ 2 2 /** @file 3 * Hardened main() template .3 * Hardened main() template for testcases (in testcase subdir). 4 4 */ 5 5 … … 30 30 int main(int argc, char **argv, char **envp) 31 31 { 32 return SUPR3HardenedMain(PROGRAM_NAME_STR, 0, argc, argv, envp);32 return SUPR3HardenedMain(PROGRAM_NAME_STR, SUPSECMAIN_FLAGS_LOC_TESTCASE, argc, argv, envp); 33 33 } 34 34 -
trunk/src/VBox/HostDrivers/Support/SUPR3HardenedVerify.cpp
r56293 r56733 105 105 * 106 106 * @todo This needs reviewing against the linux packages. 107 * @todo The excessive use of kSupID_ SharedLib needs to be reviewed at some point. For107 * @todo The excessive use of kSupID_AppSharedLib needs to be reviewed at some point. For 108 108 * the time being we're building the linux packages with SharedLib pointing to 109 109 * AppPrivArch (lazy bird). … … 123 123 #endif 124 124 125 { kSupIFT_Dll, kSupID_ SharedLib,false, "VBoxRT" SUPLIB_DLL_SUFF },126 { kSupIFT_Dll, kSupID_ SharedLib,false, "VBoxVMM" SUPLIB_DLL_SUFF },127 { kSupIFT_Dll, kSupID_ SharedLib,false, "VBoxREM" SUPLIB_DLL_SUFF },125 { kSupIFT_Dll, kSupID_AppSharedLib, false, "VBoxRT" SUPLIB_DLL_SUFF }, 126 { kSupIFT_Dll, kSupID_AppSharedLib, false, "VBoxVMM" SUPLIB_DLL_SUFF }, 127 { kSupIFT_Dll, kSupID_AppSharedLib, false, "VBoxREM" SUPLIB_DLL_SUFF }, 128 128 #if HC_ARCH_BITS == 32 129 { kSupIFT_Dll, kSupID_ SharedLib,true, "VBoxREM32" SUPLIB_DLL_SUFF },130 { kSupIFT_Dll, kSupID_ SharedLib,true, "VBoxREM64" SUPLIB_DLL_SUFF },131 #endif 132 { kSupIFT_Dll, kSupID_ SharedLib,false, "VBoxDD" SUPLIB_DLL_SUFF },133 { kSupIFT_Dll, kSupID_ SharedLib,false, "VBoxDD2" SUPLIB_DLL_SUFF },134 { kSupIFT_Dll, kSupID_ SharedLib,false, "VBoxDDU" SUPLIB_DLL_SUFF },129 { kSupIFT_Dll, kSupID_AppSharedLib, true, "VBoxREM32" SUPLIB_DLL_SUFF }, 130 { kSupIFT_Dll, kSupID_AppSharedLib, true, "VBoxREM64" SUPLIB_DLL_SUFF }, 131 #endif 132 { kSupIFT_Dll, kSupID_AppSharedLib, false, "VBoxDD" SUPLIB_DLL_SUFF }, 133 { kSupIFT_Dll, kSupID_AppSharedLib, false, "VBoxDD2" SUPLIB_DLL_SUFF }, 134 { kSupIFT_Dll, kSupID_AppSharedLib, false, "VBoxDDU" SUPLIB_DLL_SUFF }, 135 135 136 136 //#ifdef VBOX_WITH_DEBUGGER_GUI 137 { kSupIFT_Dll, kSupID_ SharedLib,true, "VBoxDbg" SUPLIB_DLL_SUFF },138 { kSupIFT_Dll, kSupID_ SharedLib,true, "VBoxDbg3" SUPLIB_DLL_SUFF },137 { kSupIFT_Dll, kSupID_AppSharedLib, true, "VBoxDbg" SUPLIB_DLL_SUFF }, 138 { kSupIFT_Dll, kSupID_AppSharedLib, true, "VBoxDbg3" SUPLIB_DLL_SUFF }, 139 139 //#endif 140 140 … … 165 165 { kSupIFT_Exe, kSupID_AppBin, false, "VBoxSVC" SUPLIB_EXE_SUFF }, 166 166 #ifdef RT_OS_WINDOWS 167 { kSupIFT_Dll, kSupID_ SharedLib,false, "VBoxC" SUPLIB_DLL_SUFF },167 { kSupIFT_Dll, kSupID_AppSharedLib, false, "VBoxC" SUPLIB_DLL_SUFF }, 168 168 #else 169 169 { kSupIFT_Exe, kSupID_AppPrivArch, false, "VBoxXPCOMIPCD" SUPLIB_EXE_SUFF }, 170 { kSupIFT_Dll, kSupID_ SharedLib,false, "VBoxXPCOM" SUPLIB_DLL_SUFF },170 { kSupIFT_Dll, kSupID_AppSharedLib, false, "VBoxXPCOM" SUPLIB_DLL_SUFF }, 171 171 { kSupIFT_Dll, kSupID_AppPrivArchComp, false, "VBoxXPCOMIPCC" SUPLIB_DLL_SUFF }, 172 172 { kSupIFT_Dll, kSupID_AppPrivArchComp, false, "VBoxC" SUPLIB_DLL_SUFF }, … … 176 176 #endif 177 177 178 { kSupIFT_Dll, kSupID_ SharedLib,true, "VRDPAuth" SUPLIB_DLL_SUFF },179 { kSupIFT_Dll, kSupID_ SharedLib,true, "VBoxAuth" SUPLIB_DLL_SUFF },180 { kSupIFT_Dll, kSupID_ SharedLib,true, "VBoxVRDP" SUPLIB_DLL_SUFF },178 { kSupIFT_Dll, kSupID_AppSharedLib, true, "VRDPAuth" SUPLIB_DLL_SUFF }, 179 { kSupIFT_Dll, kSupID_AppSharedLib, true, "VBoxAuth" SUPLIB_DLL_SUFF }, 180 { kSupIFT_Dll, kSupID_AppSharedLib, true, "VBoxVRDP" SUPLIB_DLL_SUFF }, 181 181 182 182 //#ifdef VBOX_WITH_HEADLESS … … 190 190 { kSupIFT_Dll, kSupID_AppPrivArch, true, "VirtualBox" SUPLIB_DLL_SUFF }, 191 191 # if !defined(RT_OS_DARWIN) && !defined(RT_OS_WINDOWS) && !defined(RT_OS_OS2) 192 { kSupIFT_Dll, kSupID_ SharedLib,true, "VBoxKeyboard" SUPLIB_DLL_SUFF },192 { kSupIFT_Dll, kSupID_AppSharedLib, true, "VBoxKeyboard" SUPLIB_DLL_SUFF }, 193 193 # endif 194 194 //#endif … … 263 263 switch (enmDir) 264 264 { 265 case kSupID_AppBin: /** @todo fix this AppBin crap (uncertain wtf some binaries actually are installed). */ 266 case kSupID_Bin: 267 rc = supR3HardenedPathExecDir(pszDst, cchDst); 265 case kSupID_AppBin: 266 rc = supR3HardenedPathAppBin(pszDst, cchDst); 268 267 break; 269 case kSupID_ SharedLib:270 rc = supR3HardenedPath SharedLibs(pszDst, cchDst);268 case kSupID_AppSharedLib: 269 rc = supR3HardenedPathAppSharedLibs(pszDst, cchDst); 271 270 break; 272 271 case kSupID_AppPrivArch: … … 288 287 break; 289 288 case kSupID_Testcase: 290 rc = supR3HardenedPath ExecDir(pszDst, cchDst);289 rc = supR3HardenedPathAppBin(pszDst, cchDst); 291 290 if (RT_SUCCESS(rc)) 292 291 { … … 850 849 * @returns See supR3HardenedVerifyAll. 851 850 * @param pszProgName See supR3HardenedVerifyAll. 851 * @param pszExePath The path to the executable. 852 852 * @param fFatal See supR3HardenedVerifyAll. 853 853 * @param fLeaveOpen The leave open setting used by 854 854 * supR3HardenedVerifyAll. 855 855 */ 856 static int supR3HardenedVerifyProgram(const char *pszProgName, bool fFatal, bool fLeaveOpen)856 static int supR3HardenedVerifyProgram(const char *pszProgName, const char *pszExePath, bool fFatal, bool fLeaveOpen) 857 857 { 858 858 /* … … 891 891 fExe = true; 892 892 893 char szFilename[RTPATH_MAX]; 894 int rc2 = supR3HardenedPathExecDir(szFilename, sizeof(szFilename) - cchProgName - sizeof(SUPLIB_EXE_SUFF)); 895 if (RT_SUCCESS(rc2)) 896 { 897 suplibHardenedStrCat(szFilename, "/"); 898 suplibHardenedStrCat(szFilename, g_aSupInstallFiles[iFile].pszFile); 899 supR3HardenedVerifySameFile(iFile, szFilename, fFatal); 900 } 901 else 902 rc = supR3HardenedError(rc2, fFatal, 903 "supR3HardenedVerifyProgram: failed to query program path: rc=%d\n", rc2); 893 supR3HardenedVerifySameFile(iFile, pszExePath, fFatal); 904 894 } 905 895 } … … 936 926 * both the executable and corresponding 937 927 * DLL/DYLIB/SO are valid. 938 */ 939 DECLHIDDEN(int) supR3HardenedVerifyAll(bool fFatal, const char *pszProgName) 928 * @param pszExePath The path to the executable. 929 */ 930 DECLHIDDEN(int) supR3HardenedVerifyAll(bool fFatal, const char *pszProgName, const char *pszExePath) 940 931 { 941 932 /* … … 964 955 * sign things. 965 956 */ 966 int rc2 = supR3HardenedVerifyProgram(pszProgName, fFatal, fLeaveOpen);957 int rc2 = supR3HardenedVerifyProgram(pszProgName, pszExePath, fFatal, fLeaveOpen); 967 958 if (RT_FAILURE(rc2) && RT_SUCCESS(rc)) 968 959 rc2 = rc; -
trunk/src/VBox/HostDrivers/Support/win/SUPHardenedVerify-win.h
r56293 r56733 205 205 #endif /* IN_RING3 && !VBOX_PERMIT_EVEN_MORE */ 206 206 extern SUPSYSROOTDIRBUF g_SupLibHardenedExeNtPath; 207 extern uint32_t g_offSupLibHardenedExeNtName;207 extern SUPSYSROOTDIRBUF g_SupLibHardenedAppBinNtPath; 208 208 209 209 # ifdef IN_RING0 -
trunk/src/VBox/HostDrivers/Support/win/SUPHardenedVerifyImage-win.cpp
r56293 r56733 2039 2039 */ 2040 2040 char szPath[RTPATH_MAX]; 2041 supR3HardenedPath SharedLibs(szPath, sizeof(szPath) - sizeof("/VBoxSupLib.DLL"));2041 supR3HardenedPathAppSharedLibs(szPath, sizeof(szPath) - sizeof("/VBoxSupLib.DLL")); 2042 2042 suplibHardenedStrCat(szPath, "/VBoxSupLib.DLL"); 2043 2043 HMODULE hSupLibMod = (HMODULE)supR3HardenedWinLoadLibrary(szPath, true /*fSystem32Only*/); -
trunk/src/VBox/HostDrivers/Support/win/SUPR3HardenedMain-win.cpp
r56293 r56733 35 35 #endif 36 36 #ifndef LOAD_LIBRARY_SEARCH_APPLICATION_DIR 37 # define LOAD_LIBRARY_SEARCH_APPLICATION_DIR 0x200 38 # define LOAD_LIBRARY_SEARCH_SYSTEM32 0x800 37 # define LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR UINT32_C(0x100) 38 # define LOAD_LIBRARY_SEARCH_APPLICATION_DIR UINT32_C(0x200) 39 # define LOAD_LIBRARY_SEARCH_USER_DIRS UINT32_C(0x400) 40 # define LOAD_LIBRARY_SEARCH_SYSTEM32 UINT32_C(0x800) 39 41 #endif 40 42 … … 274 276 /** The NT path of the executable. */ 275 277 SUPSYSROOTDIRBUF g_SupLibHardenedExeNtPath; 278 /** The NT path of the application binary directory. */ 279 SUPSYSROOTDIRBUF g_SupLibHardenedAppBinNtPath; 276 280 /** The offset into g_SupLibHardenedExeNtPath of the executable name (WCHAR, 277 281 * not byte). This also gives the length of the exectuable directory path, 278 282 * including a trailing slash. */ 279 uint32_t g_offSupLibHardenedExeNtName; 283 static uint32_t g_offSupLibHardenedExeNtName; 284 /** Set if we need to use the LOAD_LIBRARY_SEARCH_USER_DIRS option. */ 285 bool g_fSupLibHardenedDllSearchUserDirs = false; 280 286 /** @} */ 281 287 … … 464 470 if (g_uNtVerCombined >= SUP_MAKE_NT_VER_SIMPLE(6, 0)) 465 471 { 466 fFlags |= LOAD_LIBRARY_SEARCH_SYSTEM32; 467 if (!fSystem32Only) 468 fFlags |= LOAD_LIBRARY_SEARCH_APPLICATION_DIR; 472 fFlags |= LOAD_LIBRARY_SEARCH_SYSTEM32; 473 if (!fSystem32Only) 474 { 475 fFlags |= LOAD_LIBRARY_SEARCH_APPLICATION_DIR; 476 if (g_fSupLibHardenedDllSearchUserDirs) 477 fFlags |= LOAD_LIBRARY_SEARCH_USER_DIRS; 478 } 469 479 } 470 480 … … 806 816 continue; 807 817 } 808 if (supR3HardenedWinVerifyCacheLookupImport(g_SupLibHardened ExeNtPath.UniStr.Buffer,809 g_ offSupLibHardenedExeNtName,818 if (supR3HardenedWinVerifyCacheLookupImport(g_SupLibHardenedAppBinNtPath.UniStr.Buffer, 819 g_SupLibHardenedAppBinNtPath.UniStr.Length / sizeof(CHAR), 810 820 uBuf.szName) != NULL) 811 821 { … … 889 899 g_System32NtPath.UniStr.Length / sizeof(WCHAR), 890 900 pCur->szName) 891 && !supR3HardenedWinVerifyCacheLookupImport(g_SupLibHardened ExeNtPath.UniStr.Buffer,892 g_ offSupLibHardenedExeNtName,901 && !supR3HardenedWinVerifyCacheLookupImport(g_SupLibHardenedAppBinNtPath.UniStr.Buffer, 902 g_SupLibHardenedAppBinNtPath.UniStr.Length / sizeof(WCHAR), 893 903 pCur->szName) 894 904 && ( pCur->cwcAltSearchDir == 0 … … 983 993 { 984 994 { g_System32NtPath.UniStr.Buffer, g_System32NtPath.UniStr.Length / sizeof(WCHAR) }, 985 { g_SupLibHardenedExeNtPath.UniStr.Buffer, g_ offSupLibHardenedExeNtName - 1},995 { g_SupLibHardenedExeNtPath.UniStr.Buffer, g_SupLibHardenedAppBinNtPath.UniStr.Length / sizeof(WCHAR) }, 986 996 { pCur->pwszAltSearchDir, pCur->cwcAltSearchDir }, 987 997 }; … … 1352 1362 * 7. x86 variations of 4 & 5 - ditto. 1353 1363 */ 1354 Assert(g_SupLibHardenedExeNtPath.UniStr.Buffer[g_offSupLibHardenedExeNtName - 1] == '\\');1355 1364 uint32_t fFlags = 0; 1356 1365 if (supHardViUniStrPathStartsWithUniStr(&uBuf.UniStr, &g_System32NtPath.UniStr, true /*fCheckSlash*/)) … … 1358 1367 else if (supHardViUniStrPathStartsWithUniStr(&uBuf.UniStr, &g_WinSxSNtPath.UniStr, true /*fCheckSlash*/)) 1359 1368 fFlags |= SUPHNTVI_F_ALLOW_CAT_FILE_VERIFICATION | SUPHNTVI_F_TRUSTED_INSTALLER_OWNER; 1360 else if (supHardViUtf16PathStartsWithEx(uBuf.UniStr.Buffer, uBuf.UniStr.Length / sizeof(WCHAR), 1361 g_SupLibHardenedExeNtPath.UniStr.Buffer, 1362 g_offSupLibHardenedExeNtName, false /*fCheckSlash*/)) 1369 else if (supHardViUniStrPathStartsWithUniStr(&uBuf.UniStr, &g_SupLibHardenedAppBinNtPath.UniStr, true /*fCheckSlash*/)) 1363 1370 fFlags |= SUPHNTVI_F_REQUIRE_KERNEL_CODE_SIGNING | SUPHNTVI_F_REQUIRE_SIGNATURE_ENFORCEMENT; 1364 1371 # ifdef VBOX_PERMIT_MORE … … 1404 1411 * integrity checks. 1405 1412 */ 1406 Assert(g_SupLibHardenedExeNtPath.UniStr.Buffer[g_offSupLibHardenedExeNtName - 1] == '\\');1407 1413 uint32_t fFlags = 0; 1408 if (supHardViUtf16PathStartsWithEx(uBuf.UniStr.Buffer, uBuf.UniStr.Length / sizeof(WCHAR), 1409 g_SupLibHardenedExeNtPath.UniStr.Buffer, 1410 g_offSupLibHardenedExeNtName, false /*fCheckSlash*/)) 1414 if (supHardViUniStrPathStartsWithUniStr(&uBuf.UniStr, &g_SupLibHardenedAppBinNtPath.UniStr, true /*fCheckSlash*/)) 1411 1415 fFlags |= SUPHNTVI_F_REQUIRE_KERNEL_CODE_SIGNING | SUPHNTVI_F_REQUIRE_SIGNATURE_ENFORCEMENT; 1412 1416 else … … 4649 4653 "Window Vista without any service pack installed is not supported. Please install the latest service pack."); 4650 4654 #endif 4655 } 4656 4657 4658 /** 4659 * Modifies the DLL search path for testcases. 4660 * 4661 * This makes sure the application binary path is in the search path. When 4662 * starting a testcase executable in the testcase/ subdirectory this isn't the 4663 * case by default. So, unless we do something about it we won't be able to 4664 * import VBox DLLs. 4665 * 4666 * @param fFlags The main flags (giving the location). 4667 * @param pszAppBinPath The path to the application binary directory 4668 * (windows style). 4669 */ 4670 DECLHIDDEN(void) supR3HardenedWinModifyDllSearchPath(uint32_t fFlags, const char *pszAppBinPath) 4671 { 4672 /* 4673 * For the testcases to work, we must add the app bin directory to the 4674 * DLL search list before the testcase dll is loaded or it won't be 4675 * able to find the VBox DLLs. This is done _after_ VBoxRT.dll is 4676 * initialized and sets its defaults. 4677 */ 4678 switch (fFlags & SUPSECMAIN_FLAGS_LOC_MASK) 4679 { 4680 case SUPSECMAIN_FLAGS_LOC_TESTCASE: 4681 break; 4682 default: 4683 return; 4684 } 4685 4686 /* 4687 * Dynamically resolve the two APIs we need (the latter uses forwarders on w7). 4688 */ 4689 HMODULE hModKernel32 = GetModuleHandleW(L"kernel32.dll"); 4690 4691 typedef BOOL (WINAPI *PFNSETDLLDIRECTORY)(LPCWSTR); 4692 PFNSETDLLDIRECTORY pfnSetDllDir; 4693 pfnSetDllDir = (PFNSETDLLDIRECTORY)GetProcAddress(hModKernel32, "SetDllDirectoryW"); 4694 4695 typedef BOOL (WINAPI *PFNSETDEFAULTDLLDIRECTORIES)(DWORD); 4696 PFNSETDEFAULTDLLDIRECTORIES pfnSetDefDllDirs; 4697 pfnSetDefDllDirs = (PFNSETDEFAULTDLLDIRECTORIES)GetProcAddress(hModKernel32, "SetDefaultDllDirectories"); 4698 4699 if (pfnSetDllDir != NULL) 4700 { 4701 /* 4702 * Convert the path to UTF-16 and try set it. 4703 */ 4704 PRTUTF16 pwszAppBinPath = NULL; 4705 int rc = RTStrToUtf16(pszAppBinPath, &pwszAppBinPath); 4706 if (RT_SUCCESS(rc)) 4707 { 4708 if (pfnSetDllDir(pwszAppBinPath)) 4709 { 4710 SUP_DPRINTF(("supR3HardenedWinModifyDllSearchPath: Set dll dir to '%ls'\n", pwszAppBinPath)); 4711 g_fSupLibHardenedDllSearchUserDirs = true; 4712 4713 /* 4714 * We set it alright, on W7 and later we also must modify the 4715 * default DLL search order. See @bugref{6861} for details on 4716 * why we don't do this on Vista (also see init-win.cpp in IPRT). 4717 */ 4718 if ( pfnSetDefDllDirs 4719 && g_uNtVerCombined >= SUP_NT_VER_W70) 4720 { 4721 if (pfnSetDefDllDirs( LOAD_LIBRARY_SEARCH_APPLICATION_DIR 4722 | LOAD_LIBRARY_SEARCH_SYSTEM32 4723 | LOAD_LIBRARY_SEARCH_USER_DIRS)) 4724 SUP_DPRINTF(("supR3HardenedWinModifyDllSearchPath: Successfully modified search dirs.\n")); 4725 else 4726 supR3HardenedFatal("supR3HardenedWinModifyDllSearchPath: SetDllDirectoryW(%ls) failed: %d\n", 4727 pwszAppBinPath, RtlGetLastWin32Error()); 4728 } 4729 } 4730 else 4731 supR3HardenedFatal("supR3HardenedWinModifyDllSearchPath: SetDllDirectoryW(%ls) failed: %d\n", 4732 pwszAppBinPath, RtlGetLastWin32Error()); 4733 RTUtf16Free(pwszAppBinPath); 4734 } 4735 else 4736 supR3HardenedFatal("supR3HardenedWinModifyDllSearchPath: RTStrToUtf16(%s) failed: %d\n", pszAppBinPath, rc); 4737 } 4738 } 4739 4740 4741 /** 4742 * Initializes the application binary directory path. 4743 * 4744 * This is called once or twice. 4745 * 4746 * @param fFlags The main flags (giving the location). 4747 */ 4748 DECLHIDDEN(void) supR3HardenedWinInitAppBin(uint32_t fFlags) 4749 { 4750 USHORT cwc = (USHORT)g_offSupLibHardenedExeNtName - 1; 4751 g_SupLibHardenedAppBinNtPath.UniStr.Buffer = g_SupLibHardenedAppBinNtPath.awcBuffer; 4752 memcpy(g_SupLibHardenedAppBinNtPath.UniStr.Buffer, g_SupLibHardenedExeNtPath.UniStr.Buffer, cwc * sizeof(WCHAR)); 4753 4754 switch (fFlags & SUPSECMAIN_FLAGS_LOC_MASK) 4755 { 4756 case SUPSECMAIN_FLAGS_LOC_APP_BIN: 4757 break; 4758 case SUPSECMAIN_FLAGS_LOC_TESTCASE: 4759 { 4760 /* Drop one directory level. */ 4761 USHORT off = cwc; 4762 WCHAR wc; 4763 while ( off > 1 4764 && (wc = g_SupLibHardenedAppBinNtPath.UniStr.Buffer[off - 1]) != '\0') 4765 if (wc != '\\' && wc != '/') 4766 off--; 4767 else 4768 { 4769 if (g_SupLibHardenedAppBinNtPath.UniStr.Buffer[off - 2] == ':') 4770 cwc = off; 4771 else 4772 cwc = off - 1; 4773 break; 4774 } 4775 break; 4776 } 4777 default: 4778 supR3HardenedFatal("supR3HardenedWinInitAppBin: Unknown program binary location: %#x\n", fFlags); 4779 } 4780 4781 g_SupLibHardenedAppBinNtPath.UniStr.Buffer[cwc] = '\0'; 4782 g_SupLibHardenedAppBinNtPath.UniStr.Length = cwc * sizeof(WCHAR); 4783 g_SupLibHardenedAppBinNtPath.UniStr.MaximumLength = sizeof(g_SupLibHardenedAppBinNtPath.awcBuffer); 4784 SUP_DPRINTF(("supR3HardenedWinInitAppBin(%#x): '%ls'\n", fFlags, g_SupLibHardenedAppBinNtPath.UniStr.Buffer)); 4651 4785 } 4652 4786 … … 5372 5506 5373 5507 /* 5508 * Preliminary app binary path init. May change when SUPR3HardenedMain is 5509 * called (via main below). 5510 */ 5511 supR3HardenedWinInitAppBin(SUPSECMAIN_FLAGS_LOC_APP_BIN); 5512 5513 /* 5374 5514 * If we've done early init already, register the DLL load notification 5375 5515 * callback and reinstall the NtDll patches. … … 5566 5706 5567 5707 /* 5708 * Preliminary app binary path init. May change when SUPR3HardenedMain is called. 5709 */ 5710 supR3HardenedWinInitAppBin(SUPSECMAIN_FLAGS_LOC_APP_BIN); 5711 5712 /* 5568 5713 * Initialize the image verification stuff (hooks LdrLoadDll and NtCreateSection). 5569 5714 */
Note:
See TracChangeset
for help on using the changeset viewer.