executing data needs mprotect with PROT_EXEC  
Author Message
Arne Juul





PostPosted: 2006-2-17 5:40:00 Top

java-programmer, executing data needs mprotect with PROT_EXEC This is a multi-part message in MIME format.
I've been trying to run some FreeBSD4 packages
inside a jail on a FreeBSD6 / amd64 box; and I've
hit a problem with ports/jdk.

A couple of places the VM uses an array of
integers, puts code in it, and executes it.

This doesn't work on machines where the CPU
honors the PROT_EXEC settings; this can be
different on different machines (depending on
BIOS settings probably).

The right fix is to call mprotect() from jdk to allow
execution of the memory in question, something like this:

--- ../../hotspot/src/os_cpu/bsd_i486/vm/os_bsd_i486.cpp Tue Feb
14 21:12:46 2006
+++ ../../hotspot/src/os_cpu/bsd_i486/vm/os_bsd_i486.cpp Wed Feb
15 16:30:49 2006
@@ -561,6 +562,9 @@
}
#else
static void (*fixcw)(void) = CAST_TO_FN_PTR(void (*)(void),
code_template);
+
+ ::mprotect((void *)code_template, sizeof(code_template),
+ PROT_EXEC | PROT_READ | PROT_WRITE);
#endif

fixcw();
--- ../../hotspot/src/cpu/i486/vm/vm_version_i486.cpp Thu Sep 11
03:40:14 2003
+++ ../../hotspot/src/cpu/i486/vm/vm_version_i486.cpp Tue Feb 14
23:34:40 2006
@@ -9,6 +9,8 @@
# include "incls/_precompiled.incl"
# include "incls/_vm_version_i486.cpp.incl"

+#include <sys/types.h>
+#include <sys/mman.h>

int VM_Version::_cpu;
int VM_Version::_cpuFeatures;
@@ -145,6 +147,10 @@
ResourceMark rm;
// Making this stub must be FIRST use of assembler
CodeBuffer* c = new CodeBuffer(address(stubCode), sizeof(stubCode));
+
+ ::mprotect((void *)stubCode, sizeof(stubCode),
+ PROT_EXEC | PROT_READ | PROT_WRITE);
+
VM_Version_StubGenerator g(c);
getPsrInfo_stub = CAST_TO_FN_PTR(_getPsrInfo_stub_t,
g.generate_getPsrInfo());


patches also attached in case the mail client mangles them :-)

- Arne H. J.

 
Arne.Juul





PostPosted: 2006-2-17 5:54:00 Top

java-programmer >> executing data needs mprotect with PROT_EXEC This is a multi-part message in MIME format.
--------------070902020207040407010707
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

I've been trying to run some FreeBSD4 packages
inside a jail on a FreeBSD6 / amd64 box; and I've
hit a problem with ports/jdk.

A couple of places the VM uses an array of
integers, puts code in it, and executes it.

This doesn't work on machines where the CPU
honors the PROT_EXEC settings; this can be
different on different machines (depending on
BIOS settings probably).

The right fix is to call mprotect() from jdk to allow
execution of the memory in question, something like this:

--- ../../hotspot/src/os_cpu/bsd_i486/vm/os_bsd_i486.cpp Tue Feb
14 21:12:46 2006
+++ ../../hotspot/src/os_cpu/bsd_i486/vm/os_bsd_i486.cpp Wed Feb
15 16:30:49 2006
@@ -561,6 +562,9 @@
}
#else
static void (*fixcw)(void) = CAST_TO_FN_PTR(void (*)(void),
code_template);
+
+ ::mprotect((void *)code_template, sizeof(code_template),
+ PROT_EXEC | PROT_READ | PROT_WRITE);
#endif

fixcw();
--- ../../hotspot/src/cpu/i486/vm/vm_version_i486.cpp Thu Sep 11
03:40:14 2003
+++ ../../hotspot/src/cpu/i486/vm/vm_version_i486.cpp Tue Feb 14
23:34:40 2006
@@ -9,6 +9,8 @@
# include "incls/_precompiled.incl"
# include "incls/_vm_version_i486.cpp.incl"

+#include <sys/types.h>
+#include <sys/mman.h>

int VM_Version::_cpu;
int VM_Version::_cpuFeatures;
@@ -145,6 +147,10 @@
ResourceMark rm;
// Making this stub must be FIRST use of assembler
CodeBuffer* c = new CodeBuffer(address(stubCode), sizeof(stubCode));
+
+ ::mprotect((void *)stubCode, sizeof(stubCode),
+ PROT_EXEC | PROT_READ | PROT_WRITE);
+
VM_Version_StubGenerator g(c);
getPsrInfo_stub = CAST_TO_FN_PTR(_getPsrInfo_stub_t,
g.generate_getPsrInfo());


patches also attached in case the mail client mangles them :-)

- Arne H. J.

--------------070902020207040407010707
Content-Type: text/plain;
name="patch-os_bsd_i486.cpp"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="patch-os_bsd_i486.cpp"

--- ../../hotspot/src/os_cpu/bsd_i486/vm/os_bsd_i486.cpp Tue Feb 14 21:12:46 2006
+++ ../../hotspot/src/os_cpu/bsd_i486/vm/os_bsd_i486.cpp Wed Feb 15 16:30:49 2006
@@ -561,6 +562,9 @@
}
#else
static void (*fixcw)(void) = CAST_TO_FN_PTR(void (*)(void), code_template);
+
+ ::mprotect((void *)code_template, sizeof(code_template),
+ PROT_EXEC | PROT_READ | PROT_WRITE);
#endif

fixcw();

--------------070902020207040407010707
Content-Type: text/plain;
name="patch-vm_version_i486.cpp"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="patch-vm_version_i486.cpp"

--- ../../hotspot/src/cpu/i486/vm/vm_version_i486.cpp Thu Sep 11 03:40:14 2003
+++ ../../hotspot/src/cpu/i486/vm/vm_version_i486.cpp Tue Feb 14 23:34:40 2006
@@ -9,6 +9,8 @@
# include "incls/_precompiled.incl"
# include "incls/_vm_version_i486.cpp.incl"

+#include <sys/types.h>
+#include <sys/mman.h>

int VM_Version::_cpu;
int VM_Version::_cpuFeatures;
@@ -145,6 +147,10 @@
ResourceMark rm;
// Making this stub must be FIRST use of assembler
CodeBuffer* c = new CodeBuffer(address(stubCode), sizeof(stubCode));
+
+ ::mprotect((void *)stubCode, sizeof(stubCode),
+ PROT_EXEC | PROT_READ | PROT_WRITE);
+
VM_Version_StubGenerator g(c);
getPsrInfo_stub = CAST_TO_FN_PTR(_getPsrInfo_stub_t, g.generate_getPsrInfo());


--------------070902020207040407010707
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
email***@***.com mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-java
To unsubscribe, send any mail to "email***@***.com"
--------------070902020207040407010707--