# CVE-2024-24787: Arbitrary code execution during build on Darwin in cmd/go

> Attackers can execute arbitrary code during Go module builds on Darwin by exploiting CGO linker flags, affecting developers using the Go toolchain.

- **Severity:** Medium 6.4 (`CVSS:3.1/AV:L/AC:H/PR:H/UI:N/S:U/C:H/I:H/A:H`)
- **Exploited in the wild:** Not known
- **Login needed:** An administrator
- **Attackable:** Local or same network only
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 8 May 2024
- **Updated:** 13 Feb 2025
- **Also known as:** AZL-40428, AZL-79058, AZL-98835, BIT-golang-2024-24787, GHSA-5fq7-4mxc-535h, GO-2024-2825, MINI-86x4-7r67-jvfj, MINI-hfhq-5vp3-hp27, MINI-mh8w-354f-q8v2, SUSE-SU-2024:1574-1, SUSE-SU-2024:1588-1, openSUSE-SU-2024:13941-1

## What is CVE-2024-24787?

CVE-2024-24787 is a medium-severity code injection vulnerability in cmd/go, published on 8 May 2024. It can only be exploited from the same machine or local network, with no action from the victim.

### Official description

On Darwin, building a Go module which contains CGO can trigger arbitrary code execution when using the Apple version of ld, due to usage of the -lto_library flag in a "#cgo LDFLAGS" directive.

## Which versions are affected by CVE-2024-24787?

2 open source packages ship an affected version, including golang and toolchain.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `golang` | Bitnami | All versions | 1.21.10, 1.22.3 |
| `toolchain` | Go | All versions | 1.21.10, 1.22.3 |
| `go1.21` | SUSE:Linux Enterprise High Performance Computing 15 SP4-ESPOS | All versions | 1.21.10-150000.1.33.1 |
| `go1.21` | SUSE:Linux Enterprise High Performance Computing 15 SP4-LTSS | All versions | 1.21.10-150000.1.33.1 |
| `go1.21` | SUSE:Linux Enterprise Module for Development Tools 15 SP5 | All versions | 1.21.10-150000.1.33.1 |
| `go1.21` | SUSE:Linux Enterprise Server 15 SP4-LTSS | All versions | 1.21.10-150000.1.33.1 |
| `go1.21` | SUSE:Linux Enterprise Server for SAP Applications 15 SP4 | All versions | 1.21.10-150000.1.33.1 |
| `go1.21` | SUSE:Linux Enterprise Software Development Kit 12 SP5 | All versions | 1.21.10-1.33.1 |
| `go1.21` | openSUSE:Leap 15.5 | All versions | 1.21.10-150000.1.33.1 |
| `go1.21` | openSUSE:Leap 15.6 | All versions | 1.21.10-150000.1.33.1 |
| `go1.21` | openSUSE:Tumbleweed | All versions | 1.21.10-1.1 |

## How do I fix CVE-2024-24787?

Upgrade golang to a fixed version for your release line: 1.21.10 or 1.22.3.

## Is CVE-2024-24787 being exploited?

There is no known exploitation of CVE-2024-24787 in the wild and no public exploit code.

Public exploit code:

- CVE-2024-24787 Proof of Concept (github_poc): https://github.com/LOURC0D3/CVE-2024-24787-PoC

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2024-24787 and fix it if it is affected.

What it is: CVE-2024-24787 is a medium-severity code injection vulnerability in cmd/go, published on 8 May 2024. It can only be exploited from the same machine or local network, with no action from the victim.
Exploitation: There is no known exploitation of CVE-2024-24787 in the wild and no public exploit code.

Affected packages and fixed versions:
- golang (Bitnami): affected all versions; fixed in 1.21.10, 1.22.3
- toolchain (Go): affected all versions; fixed in 1.21.10, 1.22.3

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/CVE-2024-24787/ (Markdown: https://insights.sbomify.com/CVE-2024-24787/index.md)
```

## Sources

- CVE record: https://www.cve.org/CVERecord?id=CVE-2024-24787
- NVD: https://nvd.nist.gov/vuln/detail/CVE-2024-24787
- OSV: https://osv.dev/vulnerability/CVE-2024-24787

---
From sbomify Insights: https://insights.sbomify.com/CVE-2024-24787/
Summaries are generated and may contain mistakes; the official description above is the record.
