Cannot make segment writable for relocation error

I’m trying to run a java application but I’m getting following error:

java Sample
Error: dl failure on line 893
Error: failed /usr/lib/i386/server/libjvm.so, because /usr/lib/i386/server/libjvm.so: 
cannot make segment writable for relocation: Permission denied

How can I solve the segment writable for relocation problem?

It seems that you’re trying to run a program with grsecurity patched kernel (see https://grsecurity.net/)

In order to solve this problem you must disable MPROTECT PaX flags on the binary (/usr/bin/java here)

The goal of MPROTECT is to help prevent the introduction of new executable code into the task’s address space. This is accomplished by restricting the mmap() and mprotect() interfaces.

The restrictions prevent

  • creating executable anonymous mappings
  • creating executable/writable file mappings
  • making an executable/read-only file mapping writable except for performing relocations on an ET_DYN ELF file (non-PIC shared library)
  • making a non-executable mapping executable

See more on: https://pax.grsecurity.net/docs/mprotect.txt

Run following command to disable mprotect:

$ sudo paxctl -m /usr/bin/java

If you’re getting an error like file java does not have a PT_PAX_FLAGS program header, try conversion, you should convert PT_GNU_STACK into PT_PAX_FLAGS with::

$ sudo paxctl -c /usr/bin/java

After a successfull convert, you can should run previous command again. To check whether flags are added or not you can use -v option:

$ sudo paxctl -v /usr/bin/java
PaX control v0.7
Copyright 2004,2005,2006,2007,2009,2010,2011,2012 PaX Team <[email protected]>

- PaX flags: -----m-x-e-- [java]
	MPROTECT is disabled
	RANDEXEC is disabled
	EMUTRAMP is disabled