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
822be6c9
Commit
822be6c9
authored
Dec 05, 2006
by
Alexandre Julliard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ntdll: Force exec permissions on all mmaps unless the app is marked NX-compatible.
parent
4b30ece8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
96 additions
and
20 deletions
+96
-20
loader.c
dlls/ntdll/loader.c
+2
-0
ntdll_misc.h
dlls/ntdll/ntdll_misc.h
+1
-0
virtual.c
dlls/ntdll/virtual.c
+93
-20
No files found.
dlls/ntdll/loader.c
View file @
822be6c9
...
...
@@ -2126,6 +2126,8 @@ void WINAPI LdrInitializeThunk( ULONG unknown1, ULONG unknown2, ULONG unknown3,
peb
->
ProcessParameters
->
ImagePathName
=
wm
->
ldr
.
FullDllName
;
version_init
(
wm
->
ldr
.
FullDllName
.
Buffer
);
if
(
!
(
nt
->
OptionalHeader
.
DllCharacteristics
&
IMAGE_DLLCHARACTERISTICS_NX_COMPAT
))
VIRTUAL_SetForceExec
(
TRUE
);
/* the main exe needs to be the first in the load order list */
RemoveEntryList
(
&
wm
->
ldr
.
InLoadOrderModuleList
);
...
...
dlls/ntdll/ntdll_misc.h
View file @
822be6c9
...
...
@@ -112,6 +112,7 @@ extern NTSTATUS DIR_get_unix_cwd( char **cwd );
/* virtual memory */
extern
NTSTATUS
VIRTUAL_HandleFault
(
LPCVOID
addr
);
extern
BOOL
VIRTUAL_HasMapping
(
LPCVOID
addr
);
extern
void
VIRTUAL_SetForceExec
(
BOOL
enable
);
extern
void
VIRTUAL_UseLargeAddressSpace
(
void
);
extern
BOOL
is_current_process
(
HANDLE
handle
);
...
...
dlls/ntdll/virtual.c
View file @
822be6c9
...
...
@@ -143,6 +143,7 @@ static void *user_space_limit = USER_SPACE_LIMIT;
static
void
*
preload_reserve_start
;
static
void
*
preload_reserve_end
;
static
int
use_locks
;
static
int
force_exec_prot
;
/* whether to force PROT_EXEC on all PROT_READ mmaps */
/***********************************************************************
...
...
@@ -162,6 +163,26 @@ static const char *VIRTUAL_GetProtStr( BYTE prot )
/***********************************************************************
* VIRTUAL_GetUnixProt
*
* Convert page protections to protection for mmap/mprotect.
*/
static
int
VIRTUAL_GetUnixProt
(
BYTE
vprot
)
{
int
prot
=
0
;
if
((
vprot
&
VPROT_COMMITTED
)
&&
!
(
vprot
&
VPROT_GUARD
))
{
if
(
vprot
&
VPROT_READ
)
prot
|=
PROT_READ
;
if
(
vprot
&
VPROT_WRITE
)
prot
|=
PROT_WRITE
;
if
(
vprot
&
VPROT_WRITECOPY
)
prot
|=
PROT_WRITE
;
if
(
vprot
&
VPROT_EXEC
)
prot
|=
PROT_EXEC
;
}
if
(
!
prot
)
prot
=
PROT_NONE
;
return
prot
;
}
/***********************************************************************
* VIRTUAL_DumpView
*/
static
void
VIRTUAL_DumpView
(
FILE_VIEW
*
view
)
...
...
@@ -391,6 +412,7 @@ static NTSTATUS create_view( struct file_view **view_ret, void *base, size_t siz
{
struct
file_view
*
view
;
struct
list
*
ptr
;
int
unix_prot
=
VIRTUAL_GetUnixProt
(
vprot
);
assert
(
!
((
UINT_PTR
)
base
&
page_mask
)
);
assert
(
!
(
size
&
page_mask
)
);
...
...
@@ -446,27 +468,13 @@ static NTSTATUS create_view( struct file_view **view_ret, void *base, size_t siz
*
view_ret
=
view
;
VIRTUAL_DEBUG_DUMP_VIEW
(
view
);
return
STATUS_SUCCESS
;
}
/***********************************************************************
* VIRTUAL_GetUnixProt
*
* Convert page protections to protection for mmap/mprotect.
*/
static
int
VIRTUAL_GetUnixProt
(
BYTE
vprot
)
{
int
prot
=
0
;
if
((
vprot
&
VPROT_COMMITTED
)
&&
!
(
vprot
&
VPROT_GUARD
))
if
(
force_exec_prot
&&
(
unix_prot
&
PROT_READ
)
&&
!
(
unix_prot
&
PROT_EXEC
))
{
if
(
vprot
&
VPROT_READ
)
prot
|=
PROT_READ
;
if
(
vprot
&
VPROT_WRITE
)
prot
|=
PROT_WRITE
;
if
(
vprot
&
VPROT_WRITECOPY
)
prot
|=
PROT_WRITE
;
if
(
vprot
&
VPROT_EXEC
)
prot
|=
PROT_EXEC
;
TRACE
(
"forcing exec permission on %p-%p
\n
"
,
base
,
(
char
*
)
base
+
size
-
1
);
mprotect
(
base
,
size
,
unix_prot
|
PROT_EXEC
);
}
if
(
!
prot
)
prot
=
PROT_NONE
;
return
prot
;
return
STATUS_SUCCESS
;
}
...
...
@@ -555,12 +563,22 @@ static BOOL VIRTUAL_SetProt( FILE_VIEW *view, /* [in] Pointer to view */
size_t
size
,
/* [in] Size in bytes */
BYTE
vprot
)
/* [in] Protections to use */
{
int
unix_prot
=
VIRTUAL_GetUnixProt
(
vprot
);
TRACE
(
"%p-%p %s
\n
"
,
base
,
(
char
*
)
base
+
size
-
1
,
VIRTUAL_GetProtStr
(
vprot
)
);
if
(
mprotect
(
base
,
size
,
VIRTUAL_GetUnixProt
(
vprot
)
))
return
FALSE
;
/* FIXME: last error */
if
(
force_exec_prot
&&
(
unix_prot
&
PROT_READ
)
&&
!
(
unix_prot
&
PROT_EXEC
))
{
TRACE
(
"forcing exec permission on %p-%p
\n
"
,
base
,
(
char
*
)
base
+
size
-
1
);
if
(
!
mprotect
(
base
,
size
,
unix_prot
|
PROT_EXEC
))
goto
done
;
/* exec + write may legitimately fail, in that case fall back to write only */
if
(
!
(
unix_prot
&
PROT_WRITE
))
return
FALSE
;
}
if
(
mprotect
(
base
,
size
,
unix_prot
))
return
FALSE
;
/* FIXME: last error */
done:
memset
(
view
->
prot
+
(((
char
*
)
base
-
(
char
*
)
view
->
base
)
>>
page_shift
),
vprot
,
size
>>
page_shift
);
VIRTUAL_DEBUG_DUMP_VIEW
(
view
);
...
...
@@ -1285,6 +1303,61 @@ BOOL VIRTUAL_HasMapping( LPCVOID addr )
/***********************************************************************
* VIRTUAL_SetForceExec
*
* Whether to force exec prot on all views.
*/
void
VIRTUAL_SetForceExec
(
BOOL
enable
)
{
struct
file_view
*
view
;
RtlEnterCriticalSection
(
&
csVirtual
);
if
(
!
force_exec_prot
!=
!
enable
)
/* change all existing views */
{
force_exec_prot
=
enable
;
LIST_FOR_EACH_ENTRY
(
view
,
&
views_list
,
struct
file_view
,
entry
)
{
UINT
i
,
count
;
int
unix_prot
;
char
*
addr
=
view
->
base
;
BYTE
prot
=
view
->
prot
[
0
];
for
(
count
=
i
=
1
;
i
<
view
->
size
>>
page_shift
;
i
++
,
count
++
)
{
if
(
view
->
prot
[
i
]
==
prot
)
continue
;
unix_prot
=
VIRTUAL_GetUnixProt
(
prot
);
if
((
unix_prot
&
PROT_READ
)
&&
!
(
unix_prot
&
PROT_EXEC
))
{
TRACE
(
"%s exec prot for %p-%p
\n
"
,
force_exec_prot
?
"enabling"
:
"disabling"
,
addr
,
addr
+
(
count
<<
page_shift
)
-
1
);
mprotect
(
addr
,
count
<<
page_shift
,
unix_prot
|
(
force_exec_prot
?
PROT_EXEC
:
0
)
);
}
addr
+=
(
count
<<
page_shift
);
prot
=
view
->
prot
[
i
];
count
=
0
;
}
if
(
count
)
{
unix_prot
=
VIRTUAL_GetUnixProt
(
prot
);
if
((
unix_prot
&
PROT_READ
)
&&
!
(
unix_prot
&
PROT_EXEC
))
{
TRACE
(
"%s exec prot for %p-%p
\n
"
,
force_exec_prot
?
"enabling"
:
"disabling"
,
addr
,
addr
+
(
count
<<
page_shift
)
-
1
);
mprotect
(
addr
,
count
<<
page_shift
,
unix_prot
|
(
force_exec_prot
?
PROT_EXEC
:
0
)
);
}
}
}
}
RtlLeaveCriticalSection
(
&
csVirtual
);
}
/***********************************************************************
* VIRTUAL_UseLargeAddressSpace
*
* Increase the address space size for apps that support it.
...
...
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