VirtualBox

Changeset 78285 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Apr 25, 2019 12:30:32 AM (6 years ago)
Author:
vboxsync
Message:

winnt/vboxsf: Fixed status code some DeleteFile & RemoveDir corner cases that made FsPerf unhappy. Problem was in RDBSS, so had to get a little inventive to work around it. bugref:9172

Location:
trunk/src/VBox/Additions/WINNT/SharedFolders/driver
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/WINNT/SharedFolders/driver/path.c

    r78283 r78285  
    4949        ULONG DeleteOnClose :1;
    5050        ULONG TemporaryFile :1;
     51        ULONG SlashHack :1;
    5152    } bf;
    5253
     
    112113        bf.TemporaryFile = TRUE;
    113114
    114     Log(("VBOXSF: vbsfProcessCreate: bf.TemporaryFile %d, bf.CreateDirectory %d, bf.DirectoryFile = %d\n",
    115          (ULONG)bf.TemporaryFile, (ULONG)bf.CreateDirectory, (ULONG)bf.DirectoryFile));
     115    bf.SlashHack = RxContext->CurrentIrpSp
     116                && (RxContext->CurrentIrpSp->Parameters.Create.ShareAccess & VBOX_MJ_CREATE_SLASH_HACK);
     117
     118    Log(("VBOXSF: vbsfProcessCreate: bf.TemporaryFile %d, bf.CreateDirectory %d, bf.DirectoryFile = %d, bf.SlashHack = %d\n",
     119         bf.TemporaryFile, bf.CreateDirectory, bf.DirectoryFile, bf.SlashHack));
    116120
    117121    /* Check consistency in specified flags. */
     
    125129    if (bf.DirectoryFile && bf.NonDirectoryFile)
    126130    {
     131        /** @todo r=bird: Check if FILE_DIRECTORY_FILE+FILE_NON_DIRECTORY_FILE really is illegal in all combinations... */
    127132        Log(("VBOXSF: vbsfProcessCreate: Unsupported combination: dir && !dir\n"));
    128133        Status = STATUS_INVALID_PARAMETER;
     
    252257        Log(("VBOXSF: vbsfProcessCreate: RemainingName->Length = %d\n", RemainingName->Length));
    253258
    254         Status = vbsfShflStringFromUnicodeAlloc(&ParsedPath, RemainingName->Buffer, RemainingName->Length);
    255         if (Status != STATUS_SUCCESS)
    256         {
    257             goto failure;
     259
     260        if (!bf.SlashHack)
     261        {
     262            Status = vbsfShflStringFromUnicodeAlloc(&ParsedPath, RemainingName->Buffer, RemainingName->Length);
     263            if (Status != STATUS_SUCCESS)
     264                goto failure;
     265        }
     266        else
     267        {
     268            /* Add back the slash we had to hide from RDBSS. */
     269            Status = vbsfShflStringFromUnicodeAlloc(&ParsedPath, NULL, RemainingName->Length + sizeof(RTUTF16));
     270            if (Status != STATUS_SUCCESS)
     271                goto failure;
     272            memcpy(ParsedPath->String.utf16, RemainingName->Buffer, RemainingName->Length);
     273            ParsedPath->String.utf16[RemainingName->Length / sizeof(RTUTF16)] = '\\';
     274            ParsedPath->String.utf16[RemainingName->Length / sizeof(RTUTF16) + 1] = '\0';
     275            ParsedPath->u16Length = RemainingName->Length + sizeof(RTUTF16);
    258276        }
    259277
  • trunk/src/VBox/Additions/WINNT/SharedFolders/driver/vbsf.c

    r78280 r78285  
    398398}
    399399
     400/**
     401 * Intercepts IRP_MJ_CREATE to workaround a RDBSS quirk.
     402 *
     403 * Our RDBSS library will return STATUS_OBJECT_NAME_INVALID when FILE_NON_DIRECTORY_FILE
     404 * is set and the path ends with a slash.  NTFS and FAT will fail with
     405 * STATUS_OBJECT_NAME_NOT_FOUND if the final component does not exist or isn't a directory,
     406 * STATUS_OBJECT_PATH_NOT_FOUND if some path component doesn't exist or isn't a directory,
     407 * or STATUS_ACCESS_DENIED if the final component is a directory.
     408 *
     409 * So, our HACK is to drop the trailing slash and set an unused flag in the ShareAccess
     410 * parameter to tell vbsfProcessCreate about it.
     411 *
     412 */
     413static NTSTATUS VBoxHookMjCreate(PDEVICE_OBJECT pDevObj, PIRP pIrp)
     414{
     415    PMRX_VBOX_DEVICE_EXTENSION  pDevExt  = (PMRX_VBOX_DEVICE_EXTENSION)((PBYTE)pDevObj + sizeof(RDBSS_DEVICE_OBJECT));
     416    PIO_STACK_LOCATION          pStack   = IoGetCurrentIrpStackLocation(pIrp);
     417    PFILE_OBJECT                pFileObj = pStack->FileObject;
     418    NTSTATUS                    rcNt;
     419
     420    Log(("VBOXSF: VBoxHookMjCreate: pDevObj %p, pDevExt %p, pFileObj %p, options %#x, attr %#x, share %#x, ealength %#x, secctx %p\n",
     421         pDevObj, pDevObj->DeviceExtension, pFileObj, pStack->Parameters.Create.Options, pStack->Parameters.Create.FileAttributes,
     422         pStack->Parameters.Create.ShareAccess, pStack->Parameters.Create.EaLength, pStack->Parameters.Create.SecurityContext));
     423    if (pFileObj)
     424        Log(("VBOXSF: VBoxHookMjCreate: FileName=%.*ls\n", pFileObj->FileName.Length / sizeof(WCHAR), pFileObj->FileName.Buffer));
     425
     426    /*
     427     * Check if we need to apply the hack.  If we do, we grab a reference to
     428     * the file object to be absolutely sure it's around for the cleanup work.
     429     */
     430    AssertMsg(!(pStack->Parameters.Create.ShareAccess & VBOX_MJ_CREATE_SLASH_HACK), ("%#x\n", pStack->Parameters.Create.ShareAccess));
     431    if (   (pStack->Parameters.Create.Options & (FILE_NON_DIRECTORY_FILE | FILE_DIRECTORY_FILE)) == FILE_NON_DIRECTORY_FILE
     432        && pFileObj
     433        && pFileObj->FileName.Length > 18
     434        && pFileObj->FileName.Buffer
     435        && pFileObj->FileName.Buffer[pFileObj->FileName.Length / sizeof(WCHAR) - 1] == '\\'
     436        && pFileObj->FileName.Buffer[pFileObj->FileName.Length / sizeof(WCHAR) - 2] != '\\')
     437    {
     438        NTSTATUS rcNtRef = ObReferenceObjectByPointer(pFileObj, (ACCESS_MASK)0, *IoFileObjectType, KernelMode);
     439        pFileObj->FileName.Length -= 2;
     440        pStack->Parameters.Create.ShareAccess |= VBOX_MJ_CREATE_SLASH_HACK; /* secret flag for vbsfProcessCreate */
     441
     442        rcNt = pDevExt->pfnRDBSSCreate(pDevObj, pIrp);
     443
     444        if (rcNt != STATUS_PENDING)
     445            pStack->Parameters.Create.ShareAccess &= ~VBOX_MJ_CREATE_SLASH_HACK;
     446        if (NT_SUCCESS(rcNtRef))
     447        {
     448            pFileObj->FileName.Length += 2;
     449            ObDereferenceObject(pFileObj);
     450        }
     451
     452        Log(("VBOXSF: VBoxHookMjCreate: returns %#x (hacked; rcNtRef=%#x)\n", rcNt, rcNtRef));
     453    }
     454    /*
     455     * No hack needed.
     456     */
     457    else
     458    {
     459        rcNt = pDevExt->pfnRDBSSCreate(pDevObj, pIrp);
     460        Log(("VBOXSF: VBoxHookMjCreate: returns %#x\n", rcNt));
     461    }
     462    return rcNt;
     463}
     464
    400465NTSTATUS DriverEntry(IN PDRIVER_OBJECT  DriverObject,
    401466                     IN PUNICODE_STRING RegistryPath)
     
    542607    pDeviceExtension->pfnRDBSSDeviceControl = DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL];
    543608    DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = VBoxMRXDeviceControl;
     609
     610    /* Intercept IRP_MJ_CREATE to fix incorrect (wrt NTFS, FAT, ++) return
     611     * codes for NtOpenFile("r:\\asdf\\", FILE_NON_DIRECTORY_FILE).
     612     */
     613    pDeviceExtension->pfnRDBSSCreate = DriverObject->MajorFunction[IRP_MJ_CREATE];
     614    DriverObject->MajorFunction[IRP_MJ_CREATE] = VBoxHookMjCreate;
     615
    544616
    545617    /** @todo start the redirector here RxStartMiniRdr. */
  • trunk/src/VBox/Additions/WINNT/SharedFolders/driver/vbsf.h

    r76563 r78285  
    7070    VBGLSFCLIENT hgcmClient;
    7171
    72     /* Saved pointer to the original IRP_MJ_DEVICE_CONTROL handler. */
     72    /** Saved pointer to the original IRP_MJ_DEVICE_CONTROL handler. */
    7373    NTSTATUS (* pfnRDBSSDeviceControl) (PDEVICE_OBJECT pDevObj, PIRP pIrp);
     74    /** Saved pointer to the original IRP_MJ_CREATE handler. */
     75    NTSTATUS (NTAPI * pfnRDBSSCreate)(PDEVICE_OBJECT pDevObj, PIRP pIrp);
    7476
    7577} MRX_VBOX_DEVICE_EXTENSION, *PMRX_VBOX_DEVICE_EXTENSION;
     
    121123        (((pFobx) == NULL) ? NULL : (PMRX_VBOX_FOBX)((pFobx)->Context))
    122124
     125/** HACK ALERT: Special Create.ShareAccess indicating trailing slash for
     126 * non-directory IRP_MJ_CREATE request.
     127 * Set by VBoxHookMjCreate, used by VBoxMRxCreate. */
     128#define VBOX_MJ_CREATE_SLASH_HACK   UINT16_C(0x0400)
     129
    123130/*
    124131 * Prototypes for the dispatch table routines.
  • trunk/src/VBox/Additions/WINNT/SharedFolders/driver/vbsfhlp.c

    r78282 r78285  
    186186        case VERR_NOT_SUPPORTED:
    187187            Status = STATUS_NOT_SUPPORTED;
     188            break;
     189
     190        case VERR_INVALID_NAME:
     191            Status = STATUS_OBJECT_NAME_INVALID;
    188192            break;
    189193
     
    409413
    410414    PSHFLSTRING pShflString;
    411     ULONG ulShflStringSize;
     415    ULONG cbShflString;
    412416
    413417    /* Calculate length required for the SHFL structure: header + chars + nul. */
    414     ulShflStringSize = SHFLSTRING_HEADER_SIZE + cb + sizeof(WCHAR);
    415     pShflString = (PSHFLSTRING)vbsfAllocNonPagedMem(ulShflStringSize);
     418    cbShflString = SHFLSTRING_HEADER_SIZE + cb + sizeof(WCHAR);
     419    pShflString = (PSHFLSTRING)vbsfAllocNonPagedMem(cbShflString);
    416420    if (pShflString)
    417421    {
    418         if (ShflStringInitBuffer(pShflString, ulShflStringSize))
     422        if (ShflStringInitBuffer(pShflString, cbShflString))
    419423        {
    420424            if (pwc)
     
    428432            else
    429433            {
     434                /** @todo r=bird: vbsfAllocNonPagedMem already zero'ed it...   */
    430435                RtlZeroMemory(pShflString->String.ucs2, cb + sizeof(WCHAR));
    431436                pShflString->u16Length = 0; /* without terminating null */
Note: See TracChangeset for help on using the changeset viewer.

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