VirtualBox

Changeset 77816 in vbox


Ignore:
Timestamp:
Mar 21, 2019 12:01:49 AM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
129490
Message:

SupHardNt: Made RTNtPathExpand8dot3Path() work correctly in kernel context (needs IPRT_NT_MAP_TO_ZW) and expand 8.3 names when comparing the executable image we found in the memory map with what NT returns for the process.

Location:
trunk
Files:
1 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Config.kmk

    r77802 r77816  
    45064506 TEMPLATE_VBOXR0DRV_DEFS.x86          += WIN9X_COMPAT_SPINLOCK     # Avoid multiply defined _KeInitializeSpinLock@4
    45074507 TEMPLATE_VBOXR0DRV_DEFS.amd64         = _AMD64_
     4508 TEMPLATE_VBOXR0DRV_DEFS.win           = IPRT_NT_MAP_TO_ZW
    45084509 TEMPLATE_VBOXR0DRV_CXXFLAGS           = -Zi -Zl -GR- -EHs- -GF -Gz -GS- -Zc:wchar_t- $(VBOX_VCC_FP) -Gs4096 $(VBOX_VCC_OPT) \
    45094510        $(VBOX_VCC_WARN_ALL) $(VBOX_VCC_WERR)
  • trunk/include/iprt/nt/nt.h

    r76585 r77816  
    4040
    4141#ifdef IPRT_NT_MAP_TO_ZW
     42# define NtQueryDirectoryFile           ZwQueryDirectoryFile
    4243# define NtQueryInformationFile         ZwQueryInformationFile
    4344# define NtQueryInformationProcess      ZwQueryInformationProcess
     
    388389 */
    389390RTDECL(int) RTNtPathExpand8dot3Path(struct _UNICODE_STRING *pUniStr, bool fPathOnly);
     391
     392/**
     393 * Wrapper around RTNtPathExpand8dot3Path that allocates a buffer instead of
     394 * working on the input buffer.
     395 *
     396 * @returns IPRT status code, see RTNtPathExpand8dot3Path().
     397 * @param   pUniStrSrc  The path to fix up. MaximumLength is the max buffer
     398 *                      length.
     399 * @param   fPathOnly   Whether to only process the path and leave the filename
     400 *                      as passed in.
     401 * @param   pUniStrDst  Output string.  On success, the caller must use
     402 *                      RTUtf16Free to free what the Buffer member points to.
     403 *                      This is all zeros and NULL on failure.
     404 */
     405RTDECL(int) RTNtPathExpand8dot3PathA(struct _UNICODE_STRING const *pShort, bool fPathOnly, struct _UNICODE_STRING *pUniStrDst);
    390406
    391407
  • trunk/src/VBox/HostDrivers/Support/Makefile.kmk

    r77803 r77816  
    393393        $(VBOX_PATH_RUNTIME_SRC)/nt/RTNtPathFindPossible8dot3Name.cpp \
    394394        $(VBOX_PATH_RUNTIME_SRC)/nt/RTNtPathExpand8dot3Path.cpp \
     395        $(VBOX_PATH_RUNTIME_SRC)/nt/RTNtPathExpand8dot3PathA.cpp \
    395396        $(VBOX_PATH_RUNTIME_SRC)/r3/nt/pathint-nt.cpp \
    396397        $(VBOX_PATH_RUNTIME_SRC)/win/RTErrConvertFromWin32.cpp \
  • trunk/src/VBox/HostDrivers/Support/win/SUPDrv-win.cpp

    r76785 r77816  
    2929*   Header Files                                                                                                                 *
    3030*********************************************************************************************************************************/
    31 #define IPRT_NT_MAP_TO_ZW
     31#ifndef IPRT_NT_MAP_TO_ZW
     32# define IPRT_NT_MAP_TO_ZW
     33#endif
    3234#define LOG_GROUP LOG_GROUP_SUP_DRV
    3335#include "../SUPDrvInternal.h"
  • trunk/src/VBox/HostDrivers/Support/win/SUPHardenedVerifyImage-win.cpp

    r76553 r77816  
    3030*********************************************************************************************************************************/
    3131#ifdef IN_RING0
    32 # define IPRT_NT_MAP_TO_ZW
     32# ifndef IPRT_NT_MAP_TO_ZW
     33#  define IPRT_NT_MAP_TO_ZW
     34# endif
    3335# include <iprt/nt/nt.h>
    3436# include <ntimage.h>
  • trunk/src/VBox/HostDrivers/Support/win/SUPHardenedVerifyProcess-win.cpp

    r76818 r77816  
    3030*********************************************************************************************************************************/
    3131#ifdef IN_RING0
    32 # define IPRT_NT_MAP_TO_ZW
     32# ifndef IPRT_NT_MAP_TO_ZW
     33#  define IPRT_NT_MAP_TO_ZW
     34# endif
    3335# include <iprt/nt/nt.h>
    3436# include <ntimage.h>
     
    11661168            return true;
    11671169    }
     1170}
     1171
     1172
     1173/**
     1174 * Compares two paths, expanding 8.3 short names as needed.
     1175 *
     1176 * @returns true / false.
     1177 * @param   pUniStr1        The first path.  Must be zero terminated!
     1178 * @param   pUniStr2        The second path.  Must be zero terminated!
     1179 */
     1180static bool supHardNtVpArePathsEqual(PCUNICODE_STRING pUniStr1, PCUNICODE_STRING pUniStr2)
     1181{
     1182    /* Both strings must be null terminated. */
     1183    Assert(pUniStr1->Buffer[pUniStr1->Length / sizeof(WCHAR)] == '\0');
     1184    Assert(pUniStr2->Buffer[pUniStr1->Length / sizeof(WCHAR)] == '\0');
     1185
     1186    /* Simple compare first.*/
     1187    if (supHardNtVpAreUniStringsEqual(pUniStr1, pUniStr2))
     1188        return true;
     1189
     1190    /* Make long names if needed. */
     1191    UNICODE_STRING UniStrLong1 = { 0, 0, NULL };
     1192    if (RTNtPathFindPossible8dot3Name(pUniStr1->Buffer))
     1193    {
     1194        int rc = RTNtPathExpand8dot3PathA(pUniStr1, false /*fPathOnly*/, &UniStrLong1);
     1195        if (RT_SUCCESS(rc))
     1196            pUniStr1 = &UniStrLong1;
     1197    }
     1198
     1199    UNICODE_STRING UniStrLong2 = { 0, 0, NULL };
     1200    if (RTNtPathFindPossible8dot3Name(pUniStr2->Buffer))
     1201    {
     1202        int rc = RTNtPathExpand8dot3PathA(pUniStr2, false /*fPathOnly*/, &UniStrLong2);
     1203        if (RT_SUCCESS(rc))
     1204            pUniStr2 = &UniStrLong2;
     1205    }
     1206
     1207    /* Compare again. */
     1208    bool fCompare = supHardNtVpAreUniStringsEqual(pUniStr1, pUniStr2);
     1209
     1210    /* Clean up. */
     1211    if (UniStrLong1.Buffer)
     1212        RTUtf16Free(UniStrLong1.Buffer);
     1213    if (UniStrLong2.Buffer)
     1214        RTUtf16Free(UniStrLong2.Buffer);
     1215
     1216    return fCompare;
    11681217}
    11691218
     
    22642313    if (NT_SUCCESS(rcNt))
    22652314    {
    2266         if (supHardNtVpAreUniStringsEqual(pUniStr, &pImage->Name.UniStr))
     2315        pUniStr->Buffer[pUniStr->Length / sizeof(WCHAR)] = '\0';
     2316        if (supHardNtVpArePathsEqual(pUniStr, &pImage->Name.UniStr))
    22672317            rc = VINF_SUCCESS;
    22682318        else
    2269         {
    2270             pUniStr->Buffer[pUniStr->Length / sizeof(WCHAR)] = '\0';
    22712319            rc = supHardNtVpSetInfo2(pThis, VERR_SUP_VP_EXE_VS_PROC_NAME_MISMATCH,
    22722320                                     "Process image name does not match the exectuable we found: %ls vs %ls.",
    22732321                                     pUniStr->Buffer, pImage->Name.UniStr.Buffer);
    2274         }
    22752322    }
    22762323    else
  • trunk/src/VBox/Runtime/Makefile.kmk

    r77797 r77816  
    840840        nt/RTErrConvertFromNtStatus.cpp \
    841841        nt/RTNtPathExpand8dot3Path.cpp \
     842        nt/RTNtPathExpand8dot3PathA.cpp \
    842843        nt/RTNtPathFindPossible8dot3Name.cpp \
    843844        nt/fileioutils-nt.cpp \
     
    29302931        nt/RTErrConvertFromNtStatus.cpp \
    29312932        nt/RTNtPathExpand8dot3Path.cpp \
     2933        nt/RTNtPathExpand8dot3PathA.cpp \
    29322934        nt/RTNtPathFindPossible8dot3Name.cpp \
    29332935        r0drv/generic/threadctxhooks-r0drv-generic.cpp \
  • trunk/src/VBox/Runtime/nt/RTErrConvertFromNtStatus.cpp

    r76553 r77816  
    8585        case STATUS_SHARING_VIOLATION:      return VERR_SHARING_VIOLATION;
    8686        case STATUS_NO_MEDIA_IN_DEVICE:     return VERR_DRIVE_IS_EMPTY;
     87        case STATUS_ACCESS_VIOLATION:       return VERR_INVALID_POINTER;
    8788
    8889        case STATUS_REPARSE_POINT_NOT_RESOLVED:
  • trunk/src/VBox/Runtime/nt/RTNtPathExpand8dot3Path.cpp

    r76553 r77816  
    3030*********************************************************************************************************************************/
    3131#define LOG_GROUP RTLOGGROUP_FS
     32#if !defined(IPRT_NT_MAP_TO_ZW) && defined(IN_RING0)
     33# define IPRT_NT_MAP_TO_ZW
     34#endif
    3235#ifdef IN_SUP_HARDENED_R3
    3336# include <iprt/nt/nt-and-windows.h>
  • trunk/src/VBox/Runtime/r0drv/nt/dbgkrnlinfo-r0drv-nt.cpp

    r77473 r77816  
    3535#define PIMAGE_NT_HEADERS32 NT_PIMAGE_NT_HEADERS32
    3636#define PIMAGE_NT_HEADERS64 NT_PIMAGE_NT_HEADERS64
    37 #define IPRT_NT_MAP_TO_ZW
     37#ifndef IPRT_NT_MAP_TO_ZW
     38# define IPRT_NT_MAP_TO_ZW
     39#endif
    3840#include "the-nt-kernel.h"
    3941#include <iprt/dbg.h>
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette