Skip to content

PT_DYNAMIC can end up in r/o PT_LOAD segment #146

@mwhudson

Description

@mwhudson

Reproducer:

$ cat trivialcgo.go
package main

import "C"

func main() {

}
$ go build -ldflags=-linkmode=internal /opt/opensource/go-test-cases/trivialcgo.go 
$ objcopy --remove-section .note.go.buildid   trivialcgo 
$ patchelf --set-rpath doesntmatter ./trivialcgo$ ./trivialcgo 
Segmentation fault (core dumped)

The reason for the crash is seen in readelf -l:

$ readelf -l ./trivialcgo
...
Program Headers:
  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
...
  LOAD           0x000000 0x0000000000400000 0x0000000000400000 0x04e270 0x04e270 R E 0x1000
  DYNAMIC        0x000270 0x0000000000400270 0x0000000000400270 0x000140 0x000140 RW  0x8
...

The PT_DYNAMIC header points into a PT_LOAD section that does not have the W flag, which causes glibc to segv very early in program startup.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions