Changeset 67979 in vbox for trunk/src/VBox/HostDrivers/Support/win
- Timestamp:
- Jul 15, 2017 11:02:00 AM (8 years ago)
- Location:
- trunk/src/VBox/HostDrivers/Support/win
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/win/SUPR3HardenedMain-win.cpp
r67978 r67979 1672 1672 1673 1673 /** 1674 * Checks if the given name is a valid ApiSet name. 1675 * 1676 * This is only called on likely looking names. 1677 * 1678 * @returns true if ApiSet name, false if not. 1679 * @param pName The name to check out. 1680 */ 1681 static bool supR3HardenedIsApiSetDll(PUNICODE_STRING pName) 1682 { 1683 /* 1684 * API added in Windows 8, or so they say. 1685 */ 1686 if (ApiSetQueryApiSetPresence != NULL) 1687 { 1688 BOOLEAN fPresent = FALSE; 1689 NTSTATUS rcNt = ApiSetQueryApiSetPresence(pName, &fPresent); 1690 SUP_DPRINTF(("supR3HardenedIsApiSetDll: ApiSetQueryApiSetPresence(%.*ls) -> %#x, fPresent=%d\n", 1691 pName->Length / sizeof(WCHAR), pName->Buffer, rcNt, fPresent)); 1692 return fPresent != 0; 1693 } 1694 1695 /* 1696 * Fallback needed for Windows 7. Fortunately, there aren't too many fake DLLs here. 1697 */ 1698 if ( supHardViUtf16PathStartsWithEx(pName->Buffer, pName->Length / sizeof(WCHAR), 1699 L"api-ms-win-", 11, false /*fCheckSlash*/) 1700 || supHardViUtf16PathStartsWithEx(pName->Buffer, pName->Length / sizeof(WCHAR), 1701 L"ext-ms-win-", 11, false /*fCheckSlash*/) ) 1702 { 1703 #define MY_ENTRY(a) { a, sizeof(a) - 1 } 1704 static const struct { const char *psz; size_t cch; } s_aKnownSets[] = 1705 { 1706 MY_ENTRY("api-ms-win-core-console-l1-1-0 "), 1707 MY_ENTRY("api-ms-win-core-datetime-l1-1-0"), 1708 MY_ENTRY("api-ms-win-core-debug-l1-1-0"), 1709 MY_ENTRY("api-ms-win-core-delayload-l1-1-0"), 1710 MY_ENTRY("api-ms-win-core-errorhandling-l1-1-0"), 1711 MY_ENTRY("api-ms-win-core-fibers-l1-1-0"), 1712 MY_ENTRY("api-ms-win-core-file-l1-1-0"), 1713 MY_ENTRY("api-ms-win-core-handle-l1-1-0"), 1714 MY_ENTRY("api-ms-win-core-heap-l1-1-0"), 1715 MY_ENTRY("api-ms-win-core-interlocked-l1-1-0"), 1716 MY_ENTRY("api-ms-win-core-io-l1-1-0"), 1717 MY_ENTRY("api-ms-win-core-libraryloader-l1-1-0"), 1718 MY_ENTRY("api-ms-win-core-localization-l1-1-0"), 1719 MY_ENTRY("api-ms-win-core-localregistry-l1-1-0"), 1720 MY_ENTRY("api-ms-win-core-memory-l1-1-0"), 1721 MY_ENTRY("api-ms-win-core-misc-l1-1-0"), 1722 MY_ENTRY("api-ms-win-core-namedpipe-l1-1-0"), 1723 MY_ENTRY("api-ms-win-core-processenvironment-l1-1-0"), 1724 MY_ENTRY("api-ms-win-core-processthreads-l1-1-0"), 1725 MY_ENTRY("api-ms-win-core-profile-l1-1-0"), 1726 MY_ENTRY("api-ms-win-core-rtlsupport-l1-1-0"), 1727 MY_ENTRY("api-ms-win-core-string-l1-1-0"), 1728 MY_ENTRY("api-ms-win-core-synch-l1-1-0"), 1729 MY_ENTRY("api-ms-win-core-sysinfo-l1-1-0"), 1730 MY_ENTRY("api-ms-win-core-threadpool-l1-1-0"), 1731 MY_ENTRY("api-ms-win-core-ums-l1-1-0"), 1732 MY_ENTRY("api-ms-win-core-util-l1-1-0"), 1733 MY_ENTRY("api-ms-win-core-xstate-l1-1-0"), 1734 MY_ENTRY("api-ms-win-security-base-l1-1-0"), 1735 MY_ENTRY("api-ms-win-security-lsalookup-l1-1-0"), 1736 MY_ENTRY("api-ms-win-security-sddl-l1-1-0"), 1737 MY_ENTRY("api-ms-win-service-core-l1-1-0"), 1738 MY_ENTRY("api-ms-win-service-management-l1-1-0"), 1739 MY_ENTRY("api-ms-win-service-management-l2-1-0"), 1740 MY_ENTRY("api-ms-win-service-winsvc-l1-1-0"), 1741 }; 1742 #undef MY_ENTRY 1743 1744 /* drop the dll suffix if present. */ 1745 PCRTUTF16 pawcName = pName->Buffer; 1746 size_t cwcName = pName->Length / sizeof(WCHAR); 1747 if ( cwcName > 5 1748 && (pawcName[cwcName - 1] == 'l' || pawcName[cwcName - 1] == 'L') 1749 && (pawcName[cwcName - 2] == 'l' || pawcName[cwcName - 2] == 'L') 1750 && (pawcName[cwcName - 3] == 'd' || pawcName[cwcName - 3] == 'D') 1751 && pawcName[cwcName - 4] == '.') 1752 cwcName -= 4; 1753 1754 /* Search the table. */ 1755 for (size_t i = 0; i < RT_ELEMENTS(s_aKnownSets); i++) 1756 if ( cwcName == s_aKnownSets[i].cch 1757 && RTUtf16NICmpAscii(pawcName, s_aKnownSets[i].psz, cwcName) == 0) 1758 { 1759 SUP_DPRINTF(("supR3HardenedIsApiSetDll: '%.*ls' -> true\n", pName->Length / sizeof(WCHAR))); 1760 return true; 1761 } 1762 1763 SUP_DPRINTF(("supR3HardenedIsApiSetDll: Warning! '%.*ls' looks like an API set, but it's not in the list!\n", 1764 pName->Length / sizeof(WCHAR), pName->Buffer)); 1765 } 1766 1767 SUP_DPRINTF(("supR3HardenedIsApiSetDll: '%.*ls' -> false\n", pName->Length / sizeof(WCHAR))); 1768 return false; 1769 } 1770 1771 1772 /** 1773 * Checks whether the given unicode string contains a path separator and at 1774 * least one dash. 1775 * 1776 * This is used to check for likely ApiSet name. So far, all the pseudo DLL 1777 * names include multiple dashes, so we use that as a criteria for recognizing 1778 * them. By happy coincident, most regular DLLs doesn't include dashes. 1779 * 1780 * @returns true if it contains path separator, false if only a name. 1781 * @param pPath The path to check. 1782 */ 1783 static bool supR3HardenedHasDashButNoPath(PUNICODE_STRING pPath) 1784 { 1785 size_t cDashes = 0; 1786 size_t cwcLeft = pPath->Length / sizeof(WCHAR); 1787 PCRTUTF16 pwc = pPath->Buffer; 1788 while (cwcLeft-- > 0) 1789 { 1790 RTUTF16 wc = *pwc++; 1791 switch (wc) 1792 { 1793 default: 1794 break; 1795 1796 case '-': 1797 cDashes++; 1798 break; 1799 1800 case '\\': 1801 case '/': 1802 case ':': 1803 return false; 1804 } 1805 } 1806 return cDashes > 0; 1807 } 1808 1809 1810 /** 1674 1811 * Helper for supR3HardenedMonitor_LdrLoadDll. 1675 1812 * … … 1724 1861 return false; 1725 1862 return RTUtf16ICmpAscii(pwszTmp, pszName) == 0; 1726 }1727 1728 /**1729 * Checks whether the given unicode string contains a path separator.1730 *1731 * @returns true if it contains path separator, false if only a name.1732 * @param pPath The path to check.1733 */1734 static bool supR3HardenedContainsPathSep(PUNICODE_STRING pPath)1735 {1736 size_t cwcLeft = pPath->Length / sizeof(WCHAR);1737 PCRTUTF16 pwc = pPath->Buffer;1738 while (cwcLeft-- > 0)1739 {1740 RTUTF16 wc = *pwc++;1741 switch (wc)1742 {1743 default:1744 break;1745 case '\\':1746 case '/':1747 case ':':1748 return true;1749 }1750 }1751 return false;1752 1863 } 1753 1864 … … 1955 2066 * or something we're known to use but should be taken from WinSxS. 1956 2067 */ 1957 else if ( ( supHardViUtf16PathStartsWithEx(pName->Buffer, pName->Length / sizeof(WCHAR), 1958 L"api-ms-win-", 11, false /*fCheckSlash*/) 1959 || supHardViUtf16PathStartsWithEx(pName->Buffer, pName->Length / sizeof(WCHAR), 1960 L"ext-ms-win-", 11, false /*fCheckSlash*/) ) 1961 && !supR3HardenedContainsPathSep(pName)) 2068 else if ( supR3HardenedHasDashButNoPath(pName) 2069 && supR3HardenedIsApiSetDll(pName)) 1962 2070 { 1963 2071 memcpy(wszPath, pName->Buffer, pName->Length); -
trunk/src/VBox/HostDrivers/Support/win/import-template-ntdll.h
r54998 r67979 63 63 SUPHARNT_IMPORT_STDCALL_EARLY_OPTIONAL(LdrRegisterDllNotification, 16) 64 64 SUPHARNT_IMPORT_STDCALL_EARLY(LdrGetDllHandle, 16) 65 SUPHARNT_IMPORT_STDCALL_EARLY_OPTIONAL(ApiSetQueryApiSetPresence, 8) 65 66 66 67 SUPHARNT_IMPORT_STDCALL(RtlAddAccessAllowedAce, 16)
Note:
See TracChangeset
for help on using the changeset viewer.