ntdll: Randomize security cookie when available (try 3)
André Hentschel
nerv at dawncrow.de
Wed Jun 24 15:41:35 CDT 2015
try3: reuse existing variable; ULONG_PTR instead of PULONG_PTR
---
dlls/ntdll/virtual.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/dlls/ntdll/virtual.c b/dlls/ntdll/virtual.c
index 72309f6..f46eba2 100644
--- a/dlls/ntdll/virtual.c
+++ b/dlls/ntdll/virtual.c
@@ -1278,6 +1278,24 @@ static NTSTATUS map_image( HANDLE hmapping, int fd, char *base, SIZE_T total_siz
}
}
+
+ /* randomize security cookie */
+
+ if (IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG < nt->OptionalHeader.NumberOfRvaAndSizes &&
+ (pos = nt->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG].VirtualAddress))
+ {
+ IMAGE_LOAD_CONFIG_DIRECTORY *loadcfg = (IMAGE_LOAD_CONFIG_DIRECTORY *)(ptr + pos);
+ ULONG_PTR *cookie = (ULONG_PTR *)loadcfg->SecurityCookie;
+
+ srand( time( NULL ) );
+ *cookie = rand();
+#ifdef _WIN64
+ /* Fill up, but keep the highest word clear */
+ *cookie ^= (ULONG_PTR)rand() << 16;
+#endif
+ }
+
+
/* set the image protections */
VIRTUAL_SetProt( view, ptr, ROUND_SIZE( 0, header_size ), VPROT_COMMITTED | VPROT_READ );
--
1.9.1
More information about the wine-patches
mailing list