Changeset 52704 in vbox for trunk/src/VBox/HostDrivers
- Timestamp:
- Sep 11, 2014 2:48:45 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/win/SUPR3HardenedMain-win.cpp
r52703 r52704 1562 1562 1563 1563 /** 1564 * Helper for supR3HardenedMonitor_LdrLoadDll. 1565 * 1566 * @returns NT status code. 1567 * @param pwszPath The path destination buffer. 1568 * @param cwcPath The size of the path buffer. 1569 * @param pUniStrResult The result string. 1570 * @param pOrgName The orignal name (for errors). 1571 * @param pcwc Where to return the actual length. 1572 */ 1573 static NTSTATUS supR3HardenedCopyRedirectionResult(WCHAR *pwszPath, size_t cwcPath, PUNICODE_STRING pUniStrResult, 1574 PUNICODE_STRING pOrgName, UINT *pcwc) 1575 { 1576 UINT cwc; 1577 *pcwc = cwc = pUniStrResult->Length / sizeof(WCHAR); 1578 if (pUniStrResult->Buffer == pwszPath) 1579 pwszPath[cwc] = '\0'; 1580 else 1581 { 1582 if (cwc > cwcPath - 1) 1583 { 1584 supR3HardenedError(VINF_SUCCESS, false, 1585 "supR3HardenedMonitor_LdrLoadDll: Name too long: %.*ls -> %.*ls (RtlDosApplyFileIoslationRedirection_Ustr)\n", 1586 pOrgName->Length / sizeof(WCHAR), pOrgName->Buffer, 1587 pUniStrResult->Length / sizeof(WCHAR), pUniStrResult->Buffer); 1588 return STATUS_NAME_TOO_LONG; 1589 } 1590 memcpy(&pwszPath[0], pUniStrResult->Buffer, pUniStrResult->Length); 1591 pwszPath[cwc] = '\0'; 1592 } 1593 return STATUS_SUCCESS; 1594 } 1595 1596 1597 /** 1564 1598 * Hooks that intercepts LdrLoadDll calls. 1565 1599 * … … 1596 1630 supR3HardenedError(VINF_SUCCESS, false, "supR3HardenedMonitor_LdrLoadDll: name is NULL or have a zero length.\n"); 1597 1631 SUP_DPRINTF(("supR3HardenedMonitor_LdrLoadDll: returns rcNt=%#x (pName=%p)\n", STATUS_INVALID_PARAMETER, pName)); 1632 SetLastError(dwSavedLastError); 1598 1633 return STATUS_INVALID_PARAMETER; 1599 1634 } … … 1609 1644 supR3HardenedError(VINF_SUCCESS, false, "supR3HardenedMonitor_LdrLoadDll: too long name: %#x bytes\n", pName->Length); 1610 1645 SUP_DPRINTF(("supR3HardenedMonitor_LdrLoadDll: returns rcNt=%#x\n", STATUS_NAME_TOO_LONG)); 1646 SetLastError(dwSavedLastError); 1611 1647 return STATUS_NAME_TOO_LONG; 1612 1648 } … … 1617 1653 bool fSkipValidation = false; 1618 1654 WCHAR wszPath[260]; 1655 static UNICODE_STRING const s_DefaultSuffix = RTNT_CONSTANT_UNISTR(L".dll"); 1656 UNICODE_STRING UniStrStatic = { 0, (USHORT)sizeof(wszPath) - sizeof(WCHAR), wszPath }; 1657 UNICODE_STRING UniStrDynamic = { 0, 0, NULL }; 1658 PUNICODE_STRING pUniStrResult = NULL; 1619 1659 UNICODE_STRING ResolvedName; 1660 1620 1661 if ( ( pName->Length >= 4 * sizeof(WCHAR) 1621 1662 && RT_C_IS_ALPHA(pName->Buffer[0]) … … 1626 1667 ) 1627 1668 { 1628 memcpy(wszPath, pName->Buffer, pName->Length); 1629 wszPath[pName->Length / sizeof(WCHAR)] = '\0'; 1669 rcNt = RtlDosApplyFileIsolationRedirection_Ustr(1 /*fFlags*/, 1670 pName, 1671 (PUNICODE_STRING)&s_DefaultSuffix, 1672 &UniStrStatic, 1673 &UniStrDynamic, 1674 &pUniStrResult, 1675 NULL /*pNewFlags*/, 1676 NULL /*pcbFilename*/, 1677 NULL /*pcbNeeded*/); 1678 if (NT_SUCCESS(rcNt)) 1679 { 1680 UINT cwc; 1681 rcNt = supR3HardenedCopyRedirectionResult(wszPath, RT_ELEMENTS(wszPath), pUniStrResult, pName, &cwc); 1682 RtlFreeUnicodeString(&UniStrDynamic); 1683 if (!NT_SUCCESS(rcNt)) 1684 { 1685 SUP_DPRINTF(("supR3HardenedMonitor_LdrLoadDll: returns rcNt=%#x\n", rcNt)); 1686 SetLastError(dwSavedLastError); 1687 return rcNt; 1688 } 1689 1690 ResolvedName.Buffer = wszPath; 1691 ResolvedName.Length = (USHORT)(cwc * sizeof(WCHAR)); 1692 ResolvedName.MaximumLength = ResolvedName.Length + sizeof(WCHAR); 1693 1694 SUP_DPRINTF(("supR3HardenedMonitor_LdrLoadDll: '%.*ls' -> '%.*ls' [redir]\n", 1695 (unsigned)pName->Length / sizeof(WCHAR), pName->Buffer, 1696 ResolvedName.Length / sizeof(WCHAR), ResolvedName.Buffer, rcNt)); 1697 pName = &ResolvedName; 1698 } 1699 else 1700 { 1701 memcpy(wszPath, pName->Buffer, pName->Length); 1702 wszPath[pName->Length / sizeof(WCHAR)] = '\0'; 1703 } 1630 1704 } 1631 1705 /* … … 1679 1753 cwcName, pawcName); 1680 1754 SUP_DPRINTF(("supR3HardenedMonitor_LdrLoadDll: returns rcNt=%#x\n", STATUS_OBJECT_NAME_INVALID)); 1755 SetLastError(dwSavedLastError); 1681 1756 return STATUS_OBJECT_NAME_INVALID; 1682 1757 } … … 1687 1762 * returns a full DOS path. 1688 1763 */ 1689 UINT cwc; 1690 static UNICODE_STRING const s_DefaultSuffix = RTNT_CONSTANT_UNISTR(L".dll"); 1691 UNICODE_STRING UniStrStatic = { 0, (USHORT)sizeof(wszPath) - sizeof(WCHAR), wszPath }; 1692 UNICODE_STRING UniStrDynamic = { 0, 0, NULL }; 1693 PUNICODE_STRING pUniStrResult = NULL; 1764 UINT cwc; 1694 1765 rcNt = RtlDosApplyFileIsolationRedirection_Ustr(1 /*fFlags*/, 1695 1766 pName, … … 1703 1774 if (NT_SUCCESS(rcNt)) 1704 1775 { 1705 cwc = pUniStrResult->Length / sizeof(WCHAR); 1706 if (pUniStrResult != &UniStrDynamic) 1707 wszPath[cwc] = '\0'; 1708 else 1776 rcNt = supR3HardenedCopyRedirectionResult(wszPath, RT_ELEMENTS(wszPath), pUniStrResult, pName, &cwc); 1777 RtlFreeUnicodeString(&UniStrDynamic); 1778 if (!NT_SUCCESS(rcNt)) 1709 1779 { 1710 if (pUniStrResult->Length > sizeof(wszPath) - sizeof(WCHAR)) 1711 { 1712 supR3HardenedError(VINF_SUCCESS, false, 1713 "supR3HardenedMonitor_LdrLoadDll: Name too long: %.*ls -> %.*ls (RtlDosApplyFileIoslationRedirection_Ustr)\n", 1714 pName->Length / sizeof(WCHAR), pName->Buffer, 1715 pUniStrResult->Length / sizeof(WCHAR), pUniStrResult->Buffer); 1716 RtlFreeUnicodeString(&UniStrDynamic); 1717 SUP_DPRINTF(("supR3HardenedMonitor_LdrLoadDll: returns rcNt=%#x\n", STATUS_NAME_TOO_LONG)); 1718 return STATUS_NAME_TOO_LONG; 1719 } 1720 memcpy(&wszPath[0], pUniStrResult->Buffer, pUniStrResult->Length); 1721 wszPath[cwc] = '\0'; 1780 SUP_DPRINTF(("supR3HardenedMonitor_LdrLoadDll: returns rcNt=%#x\n", rcNt)); 1781 SetLastError(dwSavedLastError); 1782 return rcNt; 1722 1783 } 1723 RtlFreeUnicodeString(&UniStrDynamic);1724 1784 } 1725 1785 else … … 1735 1795 "supR3HardenedMonitor_LdrLoadDll: GetSystemDirectoryW failed: %u\n", GetLastError()); 1736 1796 SUP_DPRINTF(("supR3HardenedMonitor_LdrLoadDll: returns rcNt=%#x\n", STATUS_UNEXPECTED_IO_ERROR)); 1797 SetLastError(dwSavedLastError); 1737 1798 return STATUS_UNEXPECTED_IO_ERROR; 1738 1799 } … … 1742 1803 "supR3HardenedMonitor_LdrLoadDll: Name too long (system32): %.*ls\n", cwcName, pawcName); 1743 1804 SUP_DPRINTF(("supR3HardenedMonitor_LdrLoadDll: returns rcNt=%#x\n", STATUS_NAME_TOO_LONG)); 1805 SetLastError(dwSavedLastError); 1744 1806 return STATUS_NAME_TOO_LONG; 1745 1807 } … … 1792 1854 SUP_DPRINTF(("supR3HardenedMonitor_LdrLoadDll: returns rcNt=%#x '%ls'\n", rcNt, wszPath)); 1793 1855 } 1856 SetLastError(dwSavedLastError); 1794 1857 return rcNt; 1795 1858 }
Note:
See TracChangeset
for help on using the changeset viewer.