vbox的更動 67977 路徑 trunk/src/VBox/HostDrivers
- 時間撮記:
- 2017-7-14 下午03:09:46 (7 年 以前)
- 檔案:
-
- 修改 1 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk/src/VBox/HostDrivers/Support/win/SUPR3HardenedMain-win.cpp
r67968 r67977 1568 1568 PLARGE_INTEGER pcbSection, ULONG fProtect, ULONG fAttribs, HANDLE hFile) 1569 1569 { 1570 bool fNeedUncChecking = false; 1570 1571 if ( hFile != NULL 1571 1572 && hFile != INVALID_HANDLE_VALUE) … … 1577 1578 if (fImage || fExecMap || fExecProt) 1578 1579 { 1580 fNeedUncChecking = true; 1579 1581 DWORD dwSavedLastError = RtlGetLastWin32Error(); 1580 1582 … … 1599 1601 * Call checked out OK, call the original. 1600 1602 */ 1601 return g_pfnNtCreateSectionReal(phSection, fAccess, pObjAttribs, pcbSection, fProtect, fAttribs, hFile); 1603 NTSTATUS rcNtReal = g_pfnNtCreateSectionReal(phSection, fAccess, pObjAttribs, pcbSection, fProtect, fAttribs, hFile); 1604 1605 /* 1606 * Check that the image that got mapped bear some resemblance to the one that was 1607 * requested. Apparently there are ways to trick the NT cache manager to map a 1608 * file different from hFile into memory using local UNC accesses. 1609 */ 1610 if ( NT_SUCCESS(rcNtReal) 1611 && fNeedUncChecking) 1612 { 1613 DWORD dwSavedLastError = RtlGetLastWin32Error(); 1614 1615 bool fOkay = false; 1616 1617 /* To get the name of the file backing the section, we unfortunately have to map it. */ 1618 SIZE_T cbView = 0; 1619 PVOID pvTmpMap = NULL; 1620 NTSTATUS rcNt = NtMapViewOfSection(*phSection, NtCurrentProcess(), &pvTmpMap, 0, 0, NULL /*poffSection*/, &cbView, 1621 ViewUnmap, MEM_TOP_DOWN, PAGE_EXECUTE); 1622 if (NT_SUCCESS(rcNt)) 1623 { 1624 /* Query the name. */ 1625 union 1626 { 1627 UNICODE_STRING UniStr; 1628 RTUTF16 awcBuf[512]; 1629 } uBuf; 1630 RT_ZERO(uBuf); 1631 SIZE_T cbActual = 0; 1632 NTSTATUS rcNtQuery = NtQueryVirtualMemory(NtCurrentProcess(), pvTmpMap, MemorySectionName, 1633 &uBuf, sizeof(uBuf) - sizeof(RTUTF16), &cbActual); 1634 1635 /* Unmap the view. */ 1636 rcNt = NtUnmapViewOfSection(NtCurrentProcess(), pvTmpMap); 1637 if (!NT_SUCCESS(rcNt)) 1638 SUP_DPRINTF(("supR3HardenedMonitor_NtCreateSection: NtUnmapViewOfSection failed on %p (hSection=%p, hFile=%p) with %#x!\n", 1639 pvTmpMap, *phSection, hFile, rcNt)); 1640 1641 /* Process the name query result. */ 1642 if (NT_SUCCESS(rcNtQuery)) 1643 { 1644 static UNICODE_STRING const s_UncPrefix = RTNT_CONSTANT_UNISTR(L"\\Device\\Mup"); 1645 if (!supHardViUniStrPathStartsWithUniStr(&uBuf.UniStr, &s_UncPrefix, true /*fCheckSlash*/)) 1646 fOkay = true; 1647 else 1648 supR3HardenedError(VINF_SUCCESS, false, 1649 "supR3HardenedMonitor_NtCreateSection: Image section with UNC path is not trusted: '%.*ls'\n", 1650 uBuf.UniStr.Length / sizeof(RTUTF16), uBuf.UniStr.Buffer); 1651 } 1652 else 1653 SUP_DPRINTF(("supR3HardenedMonitor_NtCreateSection: NtQueryVirtualMemory failed on %p (hFile=%p) with %#x -> STATUS_TRUST_FAILURE\n", 1654 *phSection, hFile, rcNt)); 1655 } 1656 else 1657 SUP_DPRINTF(("supR3HardenedMonitor_NtCreateSection: NtMapViewOfSection failed on %p (hFile=%p) with %#x -> STATUS_TRUST_FAILURE\n", 1658 *phSection, hFile, rcNt)); 1659 if (!fOkay) 1660 { 1661 NtClose(*phSection); 1662 *phSection = INVALID_HANDLE_VALUE; 1663 RtlRestoreLastWin32Error(dwSavedLastError); 1664 return STATUS_TRUST_FAILURE; 1665 } 1666 1667 RtlRestoreLastWin32Error(dwSavedLastError); 1668 } 1669 return rcNtReal; 1602 1670 } 1603 1671 … … 1734 1802 return STATUS_INVALID_PARAMETER; 1735 1803 } 1804 PCWCHAR const pawcOrgName = pName->Buffer; 1805 uint32_t const cwcOrgName = pName->Length / sizeof(WCHAR); 1806 1736 1807 /*SUP_DPRINTF(("supR3HardenedMonitor_LdrLoadDll: pName=%.*ls *pfFlags=%#x pwszSearchPath=%p:%ls\n", 1737 1808 (unsigned)pName->Length / sizeof(WCHAR), pName->Buffer, pfFlags ? *pfFlags : UINT32_MAX, pwszSearchPath, … … 1741 1812 * Reject long paths that's close to the 260 limit without looking. 1742 1813 */ 1743 if ( pName->Length > 256 * sizeof(WCHAR))1814 if (cwcOrgName > 256) 1744 1815 { 1745 1816 supR3HardenedError(VINF_SUCCESS, false, "supR3HardenedMonitor_LdrLoadDll: too long name: %#x bytes\n", pName->Length); … … 1748 1819 return STATUS_NAME_TOO_LONG; 1749 1820 } 1821 1822 #if 0 1823 /* 1824 * Reject all UNC-like paths as we cannot trust non-local files at all. 1825 * Note! We may have to relax this to deal with long path specifications and NT pass thrus. 1826 */ 1827 if ( cwcOrgName >= 3 1828 && RTPATH_IS_SLASH(pawcOrgName[0]) 1829 && RTPATH_IS_SLASH(pawcOrgName[1]) 1830 && !RTPATH_IS_SLASH(pawcOrgName[2])) 1831 { 1832 supR3HardenedError(VINF_SUCCESS, false, "supR3HardenedMonitor_LdrLoadDll: rejecting UNC name '%.*ls'\n", cwcOrgName, pawcOrgName); 1833 SUP_DPRINTF(("supR3HardenedMonitor_LdrLoadDll: returns rcNt=%#x\n", STATUS_REDIRECTOR_NOT_STARTED)); 1834 RtlRestoreLastWin32Error(dwSavedLastError); 1835 return STATUS_REDIRECTOR_NOT_STARTED; 1836 } 1837 #endif 1750 1838 1751 1839 /* … … 1787 1875 * Process the name a little, checking if it needs a DLL suffix and is pathless. 1788 1876 */ 1789 PCWCHAR pawcName = pName->Buffer;1790 uint32_t cwcName = pName->Length / sizeof(WCHAR);1791 1877 uint32_t offLastSlash = UINT32_MAX; 1792 1878 uint32_t offLastDot = UINT32_MAX; 1793 for (uint32_t i = 0; i < cwc Name; i++)1794 switch (pawc Name[i])1879 for (uint32_t i = 0; i < cwcOrgName; i++) 1880 switch (pawcOrgName[i]) 1795 1881 { 1796 1882 case '\\': … … 1804 1890 } 1805 1891 bool const fNeedDllSuffix = offLastDot == UINT32_MAX; 1806 //bool const fTrailingDot = offLastDot == cwc Name - 1;1892 //bool const fTrailingDot = offLastDot == cwcOrgName - 1; 1807 1893 1808 1894 /* 1809 1895 * Absolute path? 1810 1896 */ 1811 if ( ( cwc Name >= 41812 && RT_C_IS_ALPHA(pawc Name[0])1813 && pawc Name[1] == ':'1814 && RTPATH_IS_SLASH(pawc Name[2]) )1815 || ( cwc Name >= 11816 && RTPATH_IS_SLASH(pawc Name[0]) )1897 if ( ( cwcOrgName >= 4 1898 && RT_C_IS_ALPHA(pawcOrgName[0]) 1899 && pawcOrgName[1] == ':' 1900 && RTPATH_IS_SLASH(pawcOrgName[2]) ) 1901 || ( cwcOrgName >= 1 1902 && RTPATH_IS_SLASH(pawcOrgName[0]) ) 1817 1903 ) 1818 1904 { … … 1850 1936 { 1851 1937 /* Copy the path. */ 1852 memcpy(wszPath, pawcName, cwcName * sizeof(WCHAR)); 1853 if (fNeedDllSuffix) 1938 memcpy(wszPath, pawcOrgName, cwcOrgName * sizeof(WCHAR)); 1939 if (!fNeedDllSuffix) 1940 wszPath[cwcOrgName] = '\0'; 1941 else 1854 1942 { 1855 if (cwc Name + 4 >= RT_ELEMENTS(wszPath))1943 if (cwcOrgName + 4 >= RT_ELEMENTS(wszPath)) 1856 1944 { 1857 1945 supR3HardenedError(VINF_SUCCESS, false, 1858 "supR3HardenedMonitor_LdrLoadDll: Name too long (abs): %.*ls\n", cwc Name, pawcName);1946 "supR3HardenedMonitor_LdrLoadDll: Name too long (abs): %.*ls\n", cwcOrgName, pawcOrgName); 1859 1947 SUP_DPRINTF(("supR3HardenedMonitor_LdrLoadDll: returns rcNt=%#x\n", STATUS_NAME_TOO_LONG)); 1860 1948 RtlRestoreLastWin32Error(dwSavedLastError); 1861 1949 return STATUS_NAME_TOO_LONG; 1862 1950 } 1863 memcpy(&wszPath[cwcName], L".dll", 5 * sizeof(WCHAR)); 1864 cwcName += 4; 1951 memcpy(&wszPath[cwcOrgName], L".dll", 5 * sizeof(WCHAR)); 1865 1952 } 1866 wszPath[cwcName] = '\0';1867 1953 } 1868 1954 } … … 1896 1982 supR3HardenedError(VINF_SUCCESS, false, 1897 1983 "supR3HardenedMonitor_LdrLoadDll: relative name not permitted: %.*ls\n", 1898 cwc Name, pawcName);1984 cwcOrgName, pawcOrgName); 1899 1985 SUP_DPRINTF(("supR3HardenedMonitor_LdrLoadDll: returns rcNt=%#x\n", STATUS_OBJECT_NAME_INVALID)); 1900 1986 RtlRestoreLastWin32Error(dwSavedLastError); … … 1938 2024 AssertCompile(sizeof(g_System32WinPath.awcBuffer) <= sizeof(wszPath)); 1939 2025 cwc = g_System32WinPath.UniStr.Length / sizeof(RTUTF16); Assert(cwc > 2); 1940 if (cwc + 1 + cwc Name + fNeedDllSuffix * 4 >= RT_ELEMENTS(wszPath))2026 if (cwc + 1 + cwcOrgName + fNeedDllSuffix * 4 >= RT_ELEMENTS(wszPath)) 1941 2027 { 1942 2028 supR3HardenedError(VINF_SUCCESS, false, 1943 "supR3HardenedMonitor_LdrLoadDll: Name too long (system32): %.*ls\n", cwc Name, pawcName);2029 "supR3HardenedMonitor_LdrLoadDll: Name too long (system32): %.*ls\n", cwcOrgName, pawcOrgName); 1944 2030 SUP_DPRINTF(("supR3HardenedMonitor_LdrLoadDll: returns rcNt=%#x\n", STATUS_NAME_TOO_LONG)); 1945 2031 RtlRestoreLastWin32Error(dwSavedLastError); … … 1948 2034 memcpy(wszPath, g_System32WinPath.UniStr.Buffer, cwc * sizeof(RTUTF16)); 1949 2035 wszPath[cwc++] = '\\'; 1950 memcpy(&wszPath[cwc], pawc Name, cwcName * sizeof(WCHAR));1951 cwc += cwc Name;2036 memcpy(&wszPath[cwc], pawcOrgName, cwcOrgName * sizeof(WCHAR)); 2037 cwc += cwcOrgName; 1952 2038 if (!fNeedDllSuffix) 1953 2039 wszPath[cwc] = '\0';
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器