Updated ntdll-FileDispositionInformation patchset to block deleting mapped files (by Qian Hong, fixes Wine Staging Bug #228).

This commit is contained in:
Sebastian Lackner
2015-04-17 21:24:21 +02:00
parent f2ecb762ea
commit 69f3294d35
4 changed files with 128 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
From 4090895abe5dafae64a25987bc1878dc5d727a67 Mon Sep 17 00:00:00 2001
From: Qian Hong <qhong@codeweavers.com>
Date: Fri, 17 Apr 2015 00:59:02 +0800
Subject: ntdll/tests: Added tests to set disposition on file which is mapped
to memory
---
dlls/ntdll/tests/file.c | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/dlls/ntdll/tests/file.c b/dlls/ntdll/tests/file.c
index 05ce517..6408eaa 100644
--- a/dlls/ntdll/tests/file.c
+++ b/dlls/ntdll/tests/file.c
@@ -1355,11 +1355,12 @@ static void test_file_disposition_information(void)
{
char tmp_path[MAX_PATH], buffer[MAX_PATH + 16];
DWORD dirpos;
- HANDLE handle, handle2;
+ HANDLE handle, handle2, mapping;
NTSTATUS res;
IO_STATUS_BLOCK io;
FILE_DISPOSITION_INFORMATION fdi;
BOOL fileDeleted;
+ void *ptr;
GetTempPathA( MAX_PATH, tmp_path );
@@ -1523,6 +1524,26 @@ static void test_file_disposition_information(void)
todo_wine
ok( !fileDeleted, "Directory shouldn't have been deleted\n" );
RemoveDirectoryA( buffer );
+
+ /* cannot set disposition on file which is mapped to memory */
+ GetTempFileNameA( tmp_path, "dis", 0, buffer );
+ handle = CreateFileA(buffer, GENERIC_READ | GENERIC_WRITE | DELETE, 0, NULL, CREATE_ALWAYS, 0, 0);
+ ok( handle != INVALID_HANDLE_VALUE, "failed to create temp file\n" );
+ mapping = CreateFileMappingA( handle, NULL, PAGE_READWRITE, 0, 64 * 1024, "DelFileTest" );
+ ok( mapping != NULL, "failed to create file mapping\n");
+ ptr = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, 4096 );
+ ok( ptr != NULL, "MapViewOfFile failed\n");
+ fdi.DoDeleteFile = TRUE;
+ res = pNtSetInformationFile( handle, &io, &fdi, sizeof fdi, FileDispositionInformation );
+todo_wine
+ ok( res == STATUS_CANNOT_DELETE, "unexpected FileDispositionInformation result (expected STATUS_CANNOT_DELETE, got %x)\n", res );
+ CloseHandle( handle );
+ UnmapViewOfFile( ptr );
+ CloseHandle( mapping );
+ fileDeleted = GetFileAttributesA( buffer ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
+todo_wine
+ ok( !fileDeleted, "File shouldn't have been deleted\n" );
+ DeleteFileA( buffer );
}
static void test_iocompletion(void)
--
2.3.5

View File

@@ -0,0 +1,65 @@
From 7e203fc3b7ef5b5a69fa60f99b57ca02a9a63033 Mon Sep 17 00:00:00 2001
From: Qian Hong <qhong@codeweavers.com>
Date: Fri, 17 Apr 2015 18:39:59 +0800
Subject: server: Do not allow to set disposition on file which has a file
mapping.
---
dlls/ntdll/tests/file.c | 2 --
server/fd.c | 15 +++++++++++++++
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/dlls/ntdll/tests/file.c b/dlls/ntdll/tests/file.c
index 6408eaa..5620815 100644
--- a/dlls/ntdll/tests/file.c
+++ b/dlls/ntdll/tests/file.c
@@ -1535,13 +1535,11 @@ static void test_file_disposition_information(void)
ok( ptr != NULL, "MapViewOfFile failed\n");
fdi.DoDeleteFile = TRUE;
res = pNtSetInformationFile( handle, &io, &fdi, sizeof fdi, FileDispositionInformation );
-todo_wine
ok( res == STATUS_CANNOT_DELETE, "unexpected FileDispositionInformation result (expected STATUS_CANNOT_DELETE, got %x)\n", res );
CloseHandle( handle );
UnmapViewOfFile( ptr );
CloseHandle( mapping );
fileDeleted = GetFileAttributesA( buffer ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
-todo_wine
ok( !fileDeleted, "File shouldn't have been deleted\n" );
DeleteFileA( buffer );
}
diff --git a/server/fd.c b/server/fd.c
index 036478a..90487cc 100644
--- a/server/fd.c
+++ b/server/fd.c
@@ -1951,6 +1951,7 @@ unsigned int get_fd_options( struct fd *fd )
void set_fd_disposition( struct fd *fd, int unlink )
{
struct stat st;
+ struct list *ptr;
if (fd->unix_fd == -1)
{
@@ -1978,6 +1979,20 @@ void set_fd_disposition( struct fd *fd, int unlink )
return;
}
+ LIST_FOR_EACH( ptr, &fd->inode->open )
+ {
+ struct fd *fd_ptr = LIST_ENTRY( ptr, struct fd, inode_entry );
+ if (fd_ptr != fd)
+ {
+ if (fd_ptr->access & FILE_MAPPING_ACCESS)
+ {
+ /* can't unlink files which are mapped to memory */
+ set_error( STATUS_CANNOT_DELETE );
+ return;
+ }
+ }
+ }
+
if (unlink)
fd->closed->unlink = 1;
else if (!(fd->options & FILE_DELETE_ON_CLOSE))
--
2.3.5