1

I need to add a new section to my application (.elf). I have got the default linker script. Then I have read the GNU Linker manual. By following the instructions in manual, I have edited linker script file. However, the application gives a segmentation fault error when a 0x400 byte area is reserved for the .patchText section shown below.

Here is the relevant part of the linker script I have edited :

.patchText :
{
   *patchObsw.o (.text .data .rodata)
   . = 0x400;
} > ram

In this case the application is compiled and linked successfully, but running the application gives a segmentation fault.

If I remove the . = 0x400; line from the linker script, redo the compilation and linking process it is still successful there is no segmentation fault.

According to the GNU linker manual this line is OK.

I could not understand what the problem is here.

1 Answers1

0

I assume you are trying to run it on a Linux OS since you mention ELF files.

You probably need to lower mmap_min_addr:

mmap_min_addr is a kernel tunable that specifies the minimum virtual address that a process is allowed to mmap. Allowing processes to map low values increases the security implications of a class of defects known as "kernel NULL pointer dereference" defects. If a malicious local user finds a way to trigger one of these NULL pointer defects, they can exploit it to cause system hangs, crashes, or otherwise make parts of the system unusable. If this user is also able to map low portions of virtual memory, they can often further exploit this issue to gain increased privileges.

The downside to preventing applications from mmap'ing low virtual memory addresses is that certain applications depend on this functionality. dosemu, qemu and wine are three such applications that exist in Debian. See the application specific information below.

Example usage:

$ cat /proc/sys/vm/mmap_min_addr
65536
$ echo 0x1000 > /proc/sys/mmap_min_addr
$ cat /proc/sys/vm/mmap_min_addr
4096
Community
  • 1
  • 1
Demindiro
  • 314
  • 1
  • 4
  • 15