Changeset 56818 in vbox for trunk/src/VBox/HostDrivers
- Timestamp:
- Jul 6, 2015 2:15:29 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/SUPR3HardenedMain.cpp
r56817 r56818 1720 1720 1721 1721 /** 1722 * Construct the path to the DLL/SO/DYLIB containing the actual program. 1723 * 1724 * @returns VBox status code. 1725 * @param pszProgName The program name. 1726 * @param fMainFlags The flags passed to SUPR3HardenedMain. 1727 * @param pszPath The output buffer. 1728 * @param cbPath The size of the output buffer, in bytes. Must be at 1729 * least 128 bytes! 1730 */ 1731 static int supR3HardenedMainGetTrustedLib(const char *pszProgName, uint32_t fMainFlags, char *pszPath, size_t cbPath) 1732 { 1733 supR3HardenedPathAppPrivateArch(pszPath, sizeof(cbPath) - 10); 1734 const char *pszSubDirSlash; 1735 switch (g_fSupHardenedMain & SUPSECMAIN_FLAGS_LOC_MASK) 1736 { 1737 case SUPSECMAIN_FLAGS_LOC_APP_BIN: 1738 pszSubDirSlash = "/"; 1739 break; 1740 case SUPSECMAIN_FLAGS_LOC_TESTCASE: 1741 pszSubDirSlash = "/testcase/"; 1742 break; 1743 default: 1744 pszSubDirSlash = "/"; 1745 supR3HardenedFatal("supR3HardenedMainGetTrustedMain: Unknown program binary location: %#x\n", g_fSupHardenedMain); 1746 } 1747 #ifdef RT_OS_DARWIN 1748 if (fFlags & SUPSECMAIN_FLAGS_OSX_VM_APP) 1749 pszProgName = "VirtualBox"; 1750 #endif 1751 size_t cch = suplibHardenedStrLen(pszPath); 1752 return suplibHardenedStrCopyEx(&pszPath[cch], cbPath - cch, pszSubDirSlash, pszProgName, SUPLIB_DLL_SUFF, NULL); 1753 } 1754 1755 1756 /** 1722 1757 * Loads the DLL/SO/DYLIB containing the actual program and 1723 1758 * resolves the TrustedError symbol. … … 1743 1778 */ 1744 1779 char szPath[RTPATH_MAX]; 1745 supR3HardenedPathAppPrivateArch(szPath, sizeof(szPath) - 10); 1746 size_t cch = suplibHardenedStrLen(szPath); 1747 suplibHardenedStrCopyEx(&szPath[cch], sizeof(szPath) - cch, "/", pszProgName, SUPLIB_DLL_SUFF, NULL); 1780 supR3HardenedMainGetTrustedLib(pszProgName, g_fSupHardenedMain, szPath, sizeof(szPath)); 1748 1781 1749 1782 /* … … 1779 1812 * @returns Pointer to the trusted main of the actual program. 1780 1813 * @param pszProgName The program name. 1814 * @param fMainFlags The flags passed to SUPR3HardenedMain. 1781 1815 * @remarks This function will not return on failure. 1782 1816 */ 1783 static PFNSUPTRUSTEDMAIN supR3HardenedMainGetTrustedMain(const char *pszProgName )1817 static PFNSUPTRUSTEDMAIN supR3HardenedMainGetTrustedMain(const char *pszProgName, uint32_t fMainFlags) 1784 1818 { 1785 1819 /* … … 1787 1821 */ 1788 1822 char szPath[RTPATH_MAX]; 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 } 1803 size_t cch = suplibHardenedStrLen(szPath); 1804 suplibHardenedStrCopyEx(&szPath[cch], sizeof(szPath) - cch, pszSubDirSlash, pszProgName, SUPLIB_DLL_SUFF, NULL); 1823 supR3HardenedMainGetTrustedLib(pszProgName, fMainFlags, szPath, sizeof(szPath)); 1805 1824 1806 1825 /* … … 1811 1830 if (!hMod) 1812 1831 supR3HardenedFatal("supR3HardenedMainGetTrustedMain: LoadLibrary \"%s\" failed, rc=%d\n", 1813 1832 szPath, RtlGetLastWin32Error()); 1814 1833 FARPROC pfn = GetProcAddress(hMod, SUP_HARDENED_SYM("TrustedMain")); 1815 1834 if (!pfn) 1816 1835 supR3HardenedFatal("supR3HardenedMainGetTrustedMain: Entrypoint \"TrustedMain\" not found in \"%s\" (rc=%d)\n", 1817 1836 szPath, RtlGetLastWin32Error()); 1818 1837 return (PFNSUPTRUSTEDMAIN)pfn; 1819 1838 … … 1823 1842 if (!pvMod) 1824 1843 supR3HardenedFatal("supR3HardenedMainGetTrustedMain: dlopen(\"%s\",) failed: %s\n", 1825 1844 szPath, dlerror()); 1826 1845 void *pvSym = dlsym(pvMod, SUP_HARDENED_SYM("TrustedMain")); 1827 1846 if (!pvSym) 1828 1847 supR3HardenedFatal("supR3HardenedMainGetTrustedMain: Entrypoint \"TrustedMain\" not found in \"%s\"!\ndlerror: %s\n", 1829 1848 szPath, dlerror()); 1830 1849 return (PFNSUPTRUSTEDMAIN)(uintptr_t)pvSym; 1831 1850 #endif … … 2002 2021 SUP_DPRINTF(("SUPR3HardenedMain: Load TrustedMain...\n")); 2003 2022 g_enmSupR3HardenedMainState = SUPR3HARDENEDMAINSTATE_GET_TRUSTED_MAIN; 2004 PFNSUPTRUSTEDMAIN pfnTrustedMain = supR3HardenedMainGetTrustedMain(pszProgName );2023 PFNSUPTRUSTEDMAIN pfnTrustedMain = supR3HardenedMainGetTrustedMain(pszProgName, fFlags); 2005 2024 2006 2025 SUP_DPRINTF(("SUPR3HardenedMain: Calling TrustedMain (%p)...\n", pfnTrustedMain));
Note:
See TracChangeset
for help on using the changeset viewer.