Skip to content

runtime: sigaction calls from libraries result in segfault #75253

@StaticRocket

Description

@StaticRocket

Go version

go version go1.25.0 linux/386

Output of go env in your module/workspace:

AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GO386='sse2'
GOARCH='386'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/root/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/root/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m32 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2255728299=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='386'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/root/pamcheck/go.mod'
GOMODCACHE='/root/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/root/go'
GOPRIVATE=''
GOPROXY=''
GOROOT='/usr/lib/go'
GOSUMDB=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/root/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN=''
GOTOOLDIR='/usr/lib/go/pkg/tool/linux_386'
GOVCS=''
GOVERSION='go1.25.0'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

Call any library function expecting to temporarily swap signal handlers temporarily. The following application can be used:

#include <string.h>
#include <signal.h>

int verify_bin(void) {
  struct sigaction newsa, oldsa;

  memset(&newsa, '\0', sizeof(newsa));
  newsa.sa_handler = SIG_DFL;

  sigaction(SIGCHLD, &newsa, &oldsa);
  sigaction(SIGCHLD, &oldsa, NULL);

  return 0;
}

Compile the above as a library, link it in a cgo application like the following:

package main

//#cgo CFLAGS: -Wall -std=c99
//#cgo LDFLAGS: -lsigdemo
//
//#include<sigdemo.h>
//
import "C"

import "syscall"

func main() {
	println("open")
	C.verify_bin()
	println("switch")
	syscall.Kill(syscall.Getpid(), syscall.SIGCHLD)
	println("done")
}

What did you see happen?

  • A segmentation fault is generated when the switched signal handler is triggered.
  • If the go runtime signal handler is never swapped back, then the application will not generate a segmentation fault.

What did you expect to see?

The application should not generate a segmentation fault. The following architectures are able to do the same thing without generating a fault:

  • linux/arm
  • linux/arm64
  • linux/amd64

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.FixPendingIssues that have a fix which has not yet been reviewed or submitted.compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions