5

I recently read this article http://codearcana.com/posts/2012/05/06/securing-and-exploiting-go-binaries.html which claims in Go that the heap is executable. This raises a few different questions for me about the interaction between the runtime and the operating system.

In C, when a program needs space on the heap, it makes a call to malloc, which in turn calls sbrk which gives it memory. As far as I know in C the heap is read-write only.

Why is the heap in Go executable? What is different about the application - OS interaction in Go then in C?

Thanks

Carson Harmon
  • 319
  • 1
  • 8
  • 3
    Nothing in the C standard [n1570](http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf) suggests that its heap is not executable. It is a quality of implementation issue (and the C heap could be executable on some systems). BTW, on my system, `malloc` may -and often does, for big memory zones- use `mmap` (not only `sbrk`) – Basile Starynkevitch Sep 25 '18 at 04:46

2 Answers2

9

The heap is no longer executable.

Code was generated at runtime for function literals prior to Go 1.1, thus requiring an executable heap. Function calls were revamped in Go 1.1 to eliminate the need for an executable heap and to provide other benefits.

Charlie Tumahai
  • 113,709
  • 12
  • 249
  • 242
5

Why is the heap in Go executable?

Go heap is not executable since 2013.

Foo Bar
  • 51
  • 1