CVE-2024-24787 Overview
CVE-2024-24787 is an arbitrary code execution vulnerability affecting the Go programming language on Darwin (macOS) systems. When building a Go module that contains CGO code, an attacker can trigger arbitrary code execution through the exploitation of the -lto_library flag in a #cgo LDFLAGS directive when using Apple's version of the linker (ld).
This vulnerability affects developers building Go modules with CGO on macOS systems, potentially allowing malicious code execution during the build process itself. The attack requires local access and specific conditions to be exploited, but represents a significant supply chain risk for development environments.
Critical Impact
Building untrusted Go modules containing CGO on Darwin systems can lead to arbitrary code execution during the compilation process, potentially compromising developer workstations and CI/CD pipelines.
Affected Products
- Go programming language (versions prior to patch)
- macOS/Darwin systems using Apple's ld linker
- Development environments building CGO-enabled Go modules
Discovery Timeline
- 2024-05-08 - CVE-2024-24787 published to NVD
- 2024-11-21 - Last updated in NVD database
Technical Details for CVE-2024-24787
Vulnerability Analysis
This vulnerability resides in Go's handling of CGO linker flags on Darwin systems. CGO enables Go packages to call C code, requiring interaction with the system's C compiler and linker. When building Go modules that utilize CGO, the Go toolchain processes #cgo LDFLAGS directives that specify linker flags.
On macOS, Apple's linker supports the -lto_library flag for Link-Time Optimization (LTO). The vulnerability arises because this flag can be abused within CGO directives to specify arbitrary library paths, leading to the loading and execution of malicious code during the link phase of compilation.
The local attack vector means an attacker must have some level of access to introduce malicious Go modules into a build environment, but this is common in supply chain attack scenarios where developers clone and build third-party code.
Root Cause
The root cause lies in insufficient validation and sanitization of the -lto_library flag when processed through CGO's LDFLAGS directive on Darwin systems. The Go toolchain did not adequately restrict or validate the paths specified via this flag, allowing an attacker to point to a malicious library that gets loaded during the linking phase.
This represents an input validation vulnerability where untrusted input (the -lto_library path in a module's CGO directive) is passed to a security-sensitive operation (the linker) without proper sanitization.
Attack Vector
The attack leverages the build process as the execution vector. An attacker crafts a malicious Go module containing a #cgo LDFLAGS directive that specifies the -lto_library flag pointing to attacker-controlled code. When a victim attempts to build this module on a Darwin system using Apple's linker, the malicious library is loaded and executed with the privileges of the user running the build.
This attack is particularly dangerous in scenarios involving:
- Developers building third-party Go modules
- CI/CD pipelines that automatically build Go dependencies
- Development environments that process untrusted code
The vulnerability mechanism involves the -lto_library linker flag being processed without adequate path restrictions. When a malicious Go module includes a CGO directive such as #cgo LDFLAGS: -lto_library=/path/to/malicious/library, the Apple linker loads and executes code from the specified path during the build process. Technical details are available in the Go.dev Issue Tracker and the Go.dev Change List.
Detection Methods for CVE-2024-24787
Indicators of Compromise
- Unexpected -lto_library flags in Go module source files or build logs
- Suspicious paths referenced in #cgo LDFLAGS directives pointing to non-standard locations
- Build processes attempting to load libraries from temporary or user-writable directories
- Unusual network activity or file system modifications during Go build operations
Detection Strategies
- Audit Go modules for suspicious #cgo LDFLAGS directives containing -lto_library flags
- Implement source code scanning to detect potentially malicious CGO directives before building
- Monitor build logs for unusual linker flag usage, particularly on Darwin systems
- Use SentinelOne's endpoint detection to identify anomalous process behavior during compilation
Monitoring Recommendations
- Enable detailed logging for Go build processes to capture linker flag usage
- Implement file integrity monitoring on development systems and CI/CD build agents
- Deploy behavioral analysis to detect code execution originating from build processes
- Monitor for attempts to write or modify files in locations specified by -lto_library flags
How to Mitigate CVE-2024-24787
Immediate Actions Required
- Update Go to the latest patched version that addresses CVE-2024-24787
- Audit existing Go modules and dependencies for suspicious CGO directives
- Implement code review policies requiring inspection of CGO flags in third-party modules
- Consider using isolated build environments (containers, VMs) for building untrusted code
Patch Information
The Go team has released a fix for this vulnerability. The patch addresses the improper handling of the -lto_library flag in CGO directives on Darwin systems. Details about the fix can be found in the Go.dev Change List and the official Go.dev Vulnerability Report. Additional security information is available from the NetApp Security Advisory.
Administrators should update their Go installations immediately and rebuild any modules that may have been built with vulnerable versions.
Workarounds
- Avoid building untrusted Go modules containing CGO on Darwin systems until patched
- Use the -ldflags build flag to explicitly override linker settings when building suspicious modules
- Build Go modules in isolated environments such as Docker containers to limit potential impact
- Review and whitelist acceptable CGO directives in your development policies
# Configuration example
# Verify your Go version includes the security patch
go version
# Update Go to the latest version (example using Homebrew on macOS)
brew upgrade go
# For CI/CD environments, ensure pinned Go version includes the fix
# Check the Go vulnerability database for patched versions
go run golang.org/x/vuln/cmd/govulncheck@latest ./...
Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

