inc: fsctl: increase request/response size to 16K

dll: remove /Gs[size] switch, fix FspFileSystemResolveReparsePoints to not use more than 4K of stack space
This commit is contained in:
Bill Zissimopoulos
2016-10-08 23:33:59 -07:00
parent f8cebd1f92
commit 6bd6f0ee35
7 changed files with 77 additions and 29 deletions

View File

@ -951,7 +951,7 @@ FSP_API NTSTATUS FspFileSystemOpQuerySecurity(FSP_FILE_SYSTEM *FileSystem,
if (0 == FileSystem->Interface->GetSecurity)
return STATUS_INVALID_DEVICE_REQUEST;
SecurityDescriptorSize = FSP_FSCTL_TRANSACT_RSP_SIZEMAX - sizeof *Response;
SecurityDescriptorSize = FSP_FSCTL_TRANSACT_RSP_BUFFER_SIZEMAX;
Result = FileSystem->Interface->GetSecurity(FileSystem, Request,
(PVOID)USERCONTEXT(Request->Req.QuerySecurity),
Response->Buffer, &SecurityDescriptorSize);
@ -989,7 +989,7 @@ FSP_API NTSTATUS FspFileSystemOpQueryStreamInformation(FSP_FILE_SYSTEM *FileSyst
Result = FileSystem->Interface->GetStreamInfo(FileSystem, Request,
(PVOID)USERCONTEXT(Request->Req.QueryStreamInformation),
Response->Buffer,
FSP_FSCTL_TRANSACT_RSP_SIZEMAX - sizeof *Response,
FSP_FSCTL_TRANSACT_RSP_BUFFER_SIZEMAX,
&BytesTransferred);
if (!NT_SUCCESS(Result))
return Result;
@ -1088,23 +1088,18 @@ FSP_API BOOLEAN FspFileSystemFindReparsePoint(FSP_FILE_SYSTEM *FileSystem,
return FALSE;
}
FSP_API NTSTATUS FspFileSystemResolveReparsePoints(FSP_FILE_SYSTEM *FileSystem,
FSP_API NTSTATUS FspFileSystemResolveReparsePointsInternal(FSP_FILE_SYSTEM *FileSystem,
NTSTATUS (*GetReparsePointByName)(
FSP_FILE_SYSTEM *FileSystem, PVOID Context,
PWSTR FileName, BOOLEAN IsDirectory, PVOID Buffer, PSIZE_T PSize),
PVOID Context,
PREPARSE_DATA_BUFFER ReparseData, SIZE_T ReparseDataSize0,
PWSTR FileName, UINT32 ReparsePointIndex, BOOLEAN ResolveLastPathComponent0,
PIO_STATUS_BLOCK PIoStatus, PVOID Buffer, PSIZE_T PSize)
{
PREPARSE_DATA_BUFFER OutputReparseData;
PWSTR TargetPath, RemainderPath, LastPathComponent, NewRemainderPath, ReparseTargetPath;
WCHAR RemainderChar;
union
{
REPARSE_DATA_BUFFER V;
UINT8 B[FSP_FSCTL_TRANSACT_RSP_BUFFER_SIZEMAX];
} ReparseDataBuf;
PREPARSE_DATA_BUFFER ReparseData = &ReparseDataBuf.V;
SIZE_T ReparseDataSize, RemainderPathSize, ReparseTargetPathLength;
BOOLEAN ResolveLastPathComponent;
ULONG MaxTries = 32;
@ -1188,7 +1183,7 @@ FSP_API NTSTATUS FspFileSystemResolveReparsePoints(FSP_FILE_SYSTEM *FileSystem,
}
RemainderChar = *RemainderPath; *RemainderPath = L'\0';
ReparseDataSize = sizeof ReparseDataBuf;
ReparseDataSize = ReparseDataSize0;
Result = GetReparsePointByName(FileSystem, Context, TargetPath, '\0' != RemainderChar,
ReparseData, &ReparseDataSize);
*RemainderPath = RemainderChar;
@ -1277,6 +1272,32 @@ reparse_data_exit:
return STATUS_REPARSE;
}
FSP_API NTSTATUS FspFileSystemResolveReparsePoints(FSP_FILE_SYSTEM *FileSystem,
NTSTATUS (*GetReparsePointByName)(
FSP_FILE_SYSTEM *FileSystem, PVOID Context,
PWSTR FileName, BOOLEAN IsDirectory, PVOID Buffer, PSIZE_T PSize),
PVOID Context,
PWSTR FileName, UINT32 ReparsePointIndex, BOOLEAN ResolveLastPathComponent,
PIO_STATUS_BLOCK PIoStatus, PVOID Buffer, PSIZE_T PSize)
{
PREPARSE_DATA_BUFFER ReparseData;
NTSTATUS Result;
ReparseData = MemAlloc(FSP_FSCTL_TRANSACT_RSP_BUFFER_SIZEMAX);
if (0 == ReparseData)
return STATUS_INSUFFICIENT_RESOURCES;
Result = FspFileSystemResolveReparsePointsInternal(FileSystem,
GetReparsePointByName, Context,
ReparseData, FSP_FSCTL_TRANSACT_RSP_BUFFER_SIZEMAX,
FileName, ReparsePointIndex, ResolveLastPathComponent,
PIoStatus, Buffer, PSize);
MemFree(ReparseData);
return Result;
}
FSP_API NTSTATUS FspFileSystemCanReplaceReparsePoint(
PVOID CurrentReparseData, SIZE_T CurrentReparseDataSize,
PVOID ReplaceReparseData, SIZE_T ReplaceReparseDataSize)

View File

@ -26,11 +26,10 @@
* - "C/C++ > Code Generation > Basic Runtime Checks" must be set to "Default"
* - "C/C++ > Code Generation > Runtime Library" must be set to "Multi-threaded (/MT)".
* - "C/C++ > Code Generation > Security Check" must be disabled (/GS-).
* - "C/C++ > Command Line > Additional Options" add "/Gs16384" to disable __chkstk probes.
* - "Linker > Input > Ignore All Default Libraries" must be "Yes".
*
*
* Update:
* Update 1:
*
* It is possible to have the "Linker > Input > Ignore All Default Libraries"
* setting to "No" and still eliminate most dependencies on the MSVCRT libraries.
@ -44,6 +43,22 @@
* that are not required (or worse create a half-baked CRT). For example, the WinFsp
* DLL ensures this by setting the "Linker > Input > Ignore All Default Libraries"
* to "Yes" on 64-bit builds and "No" on 32-bit builds.
*
*
* Update 2:
*
* Using the /Gs[size] compiler option with a large size is a very bad idea.
* Turns out that the compiler uses the _chkstk call to ensure that enough
* stack space has been committed even when a function accesses locations in
* the stack below the guard page.
*
* The following links explain the problem very well:
* - http://stackoverflow.com/questions/8400118/what-is-the-purpose-of-the-chkstk-function#8400171
* - https://support.microsoft.com/en-us/kb/100775
*
* A library/program that does not wish to use the MSVCRT libraries (and hence
* does not have _chkstk available) must take care to not use more than a page
* (4096 bytes) of stack within a single function.
*/
#undef RtlFillMemory

View File

@ -735,7 +735,7 @@ enum
FspFsvolDeviceDirInfoCacheCapacity = 100,
FspFsvolDeviceDirInfoCacheItemSizeMax = FSP_FSCTL_ALIGN_UP(16384, PAGE_SIZE),
FspFsvolDeviceStreamInfoCacheCapacity = 100,
FspFsvolDeviceStreamInfoCacheItemSizeMax = 4096,
FspFsvolDeviceStreamInfoCacheItemSizeMax = FSP_FSCTL_ALIGN_UP(16384, PAGE_SIZE),
};
typedef struct
{