2

I am currently reading Linux Kernel Development by Robert Love.

In the chapter "15 The Process Address Space" he prints the memory map of a process.

user@machine:~$ pmap 1424
#all the processes mapped memory (skipped for readability)
bfffe000 (8KB)        rwxp (0:00 0)         [ stack ]

The last line shows the stack (as it grows down).
He now states:

The stack is, naturally, readable, writeable and executable - not of much use otherwise.

As far as I know we use the stack for data and code addresses (functions and their parameters/variable).

I do not understand why the stack must be executable?

JDurstberger
  • 135
  • 6

1 Answers1

6

That information is outdated, and the stack is typically not executable any more:

00007ffd884fa000    356K rw---   [ stack ]

GCC needs an executable stack if it generates trampolines for nested function calls. These trampolines are small pieces of code generated at runtime, and stored on the stack — so if they are used, the stack needs to be executable. The compiler keeps track of this requirement, and it outputs a flag in binaries (libraries and executables) to indicate whether they need an executable stack. You can see and manipulate the value of this flag using execstack(8).

Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164