Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-cw
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-cw
Commits
e9d7cf99
Commit
e9d7cf99
authored
Jul 10, 2015
by
Erich E. Hoover
Committed by
Alexandre Julliard
Jul 14, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ntdll: Only set the security cookie if it has not already been set.
parent
abf4d591
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
12 deletions
+37
-12
virtual.c
dlls/ntdll/virtual.c
+37
-12
No files found.
dlls/ntdll/virtual.c
View file @
e9d7cf99
...
...
@@ -61,6 +61,12 @@ WINE_DECLARE_DEBUG_CHANNEL(module);
#define MAP_NORESERVE 0
#endif
#ifdef _WIN64
#define DEFAULT_SECURITY_COOKIE_64 (((ULONGLONG)0x00002b99 << 32) | 0x2ddfa232)
#endif
#define DEFAULT_SECURITY_COOKIE_32 0xbb40e64e
#define DEFAULT_SECURITY_COOKIE_16 (DEFAULT_SECURITY_COOKIE_32 >> 16)
/* File view */
struct
file_view
{
...
...
@@ -1053,6 +1059,36 @@ static NTSTATUS stat_mapping_file( struct file_view *view, struct stat *st )
return
status
;
}
/***********************************************************************
* set_security_cookie
*
* Create a random security cookie for buffer overflow protection. Make
* sure it does not accidentally match the default cookie value.
*/
static
void
set_security_cookie
(
ULONG_PTR
*
cookie
)
{
static
ULONG
seed
;
if
(
!
cookie
)
return
;
if
(
!
seed
)
seed
=
NtGetTickCount
()
^
GetCurrentProcessId
();
while
(
1
)
{
if
(
*
cookie
==
DEFAULT_SECURITY_COOKIE_16
)
*
cookie
=
RtlRandom
(
&
seed
)
>>
16
;
/* leave the high word clear */
else
if
(
*
cookie
==
DEFAULT_SECURITY_COOKIE_32
)
*
cookie
=
RtlRandom
(
&
seed
);
#ifdef DEFAULT_SECURITY_COOKIE_64
else
if
(
*
cookie
==
DEFAULT_SECURITY_COOKIE_64
)
{
*
cookie
=
RtlRandom
(
&
seed
);
/* fill up, but keep the highest word clear */
*
cookie
^=
(
ULONG_PTR
)
RtlRandom
(
&
seed
)
<<
16
;
}
#endif
else
break
;
}
}
/***********************************************************************
* map_image
...
...
@@ -1285,18 +1321,7 @@ static NTSTATUS map_image( HANDLE hmapping, int fd, char *base, SIZE_T total_siz
loadcfg
=
RtlImageDirectoryEntryToData
(
(
HMODULE
)
ptr
,
TRUE
,
IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG
,
&
loadcfg_size
);
if
(
loadcfg
&&
loadcfg_size
>=
sizeof
(
*
loadcfg
))
{
static
ULONG
seed
;
ULONG_PTR
*
cookie
=
(
ULONG_PTR
*
)
loadcfg
->
SecurityCookie
;
if
(
!
seed
)
seed
=
NtGetTickCount
()
^
GetCurrentProcessId
();
if
(
cookie
)
{
*
cookie
=
RtlRandom
(
&
seed
);
if
(
sizeof
(
ULONG_PTR
)
>
sizeof
(
ULONG
))
/* fill up, but keep the highest word clear */
*
cookie
^=
(
ULONG_PTR
)
RtlRandom
(
&
seed
)
<<
16
;
}
}
set_security_cookie
((
ULONG_PTR
*
)
loadcfg
->
SecurityCookie
);
/* set the image protections */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment