Skip to content

Commit c4cca68

Browse files
authoredApr 24, 2025··
Merge pull request #2850 from flatcar/chewi/golang-segfault
dev-lang/go: Sync with Gentoo to fix segfault issue

File tree

6 files changed

+239
-168
lines changed

6 files changed

+239
-168
lines changed
 

‎sdk_container/src/third_party/coreos-overlay/profiles/coreos/base/package.accept_keywords

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434
# Keep versions on both arches in sync.
3535
=app-emulation/qemu-guest-agent-9.2.0 ~arm64
3636

37-
# Needed to address CVE-2025-22871 and to bring in a patch disabling
38-
# gold linker on arm64.
39-
=dev-lang/go-1.24.2-r1 ~amd64 ~arm64
37+
# Needed to address CVE-2025-22871, bring in a patch disabling gold linker on
38+
# arm64, and fix a segfault concerning vgetrandom.
39+
=dev-lang/go-1.24.2-r2 ~amd64 ~arm64
4040

4141
# Needed to address CVE-2024-56406.
4242
=dev-lang/perl-5.40.2 ~amd64 ~arm64
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
DIST go1.23.7.src.tar.gz 28181215 BLAKE2B d3c9bff18438f90f6730e1ad9580a3f97d266f90533552cd73b63b512c694de76466435f274dc2b190c672cdbd83ffaf735e4e74c12e426cac920b81dbfd88af SHA512 79192b760ab6fcc9512fd879a9484a3566fdeec5eace36c54b728cd9cb033e7ac68065a42fc657b351a106d684b79fdbefbf682cf63209c0191e7e7c8c0a0147
21
DIST go1.23.8.src.tar.gz 28182772 BLAKE2B 568b9fcc7ed12cb19e10b458fc1890a5977c97660657e9eb7c171aa16382f6790a78cb87df99ed72ec18d5ff1654ee4d15a4d603332ad0812ee97f6500866198 SHA512 8e352a01484c168894026080ee4501180e327d734fb3d892ab17daac193964fcd5fd90033c9cf86d6ffe8b7e4da64bda83ba4501a6c05919bcefbe9e2467c771
32
DIST go1.24.2.src.tar.gz 30787666 BLAKE2B bb5f998a87e6527def304347b854c4addb0860a03da82e711f60e2af460bd43c36273b25126c643a679ae22fca226e6a4fc5ba55967d21965ffdc8f564781e35 SHA512 6366a32f6678e7908b138f62dafeed96f7144b3b93505e75fba374b33727da8b1d087c1f979f493382b319758ebfcbeb30e9d7dadcb2923b628c8abe7db41c6f
Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
From ff2636f45e0087a1c6d8e895257d9c4729710811 Mon Sep 17 00:00:00 2001
2+
From: Michael Pratt <mpratt@google.com>
3+
Date: Thu, 03 Apr 2025 03:26:25 +0000
4+
Subject: [PATCH] [release-branch.go1.24] runtime: cleanup M vgetrandom state before dropping P
5+
6+
When an M is destroyed, we put its vgetrandom state back on the shared
7+
list for another M to reuse. This list is simply a slice, so appending
8+
to the slice may allocate. Currently this operation is performed in
9+
mdestroy, after the P is released, meaning allocation is not allowed.
10+
11+
More the cleanup earlier in mdestroy when allocation is still OK.
12+
13+
Also add //go:nowritebarrierrec to mdestroy since it runs without a P,
14+
which would have caught this bug.
15+
16+
Fixes #73144.
17+
For #73141.
18+
19+
Change-Id: I6a6a636c3fbf5c6eec09d07a260e39dbb4d2db12
20+
Reviewed-on: https://go-review.googlesource.com/c/go/+/662455
21+
Reviewed-by: Jason Donenfeld <Jason@zx2c4.com>
22+
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
23+
Reviewed-by: Keith Randall <khr@golang.org>
24+
Reviewed-by: Keith Randall <khr@google.com>
25+
(cherry picked from commit 0b31e6d4cc804ab76ae8ced151ee2f50657aec14)
26+
---
27+
28+
diff --git a/src/runtime/os3_solaris.go b/src/runtime/os3_solaris.go
29+
index cf163a6..ded821b 100644
30+
--- a/src/runtime/os3_solaris.go
31+
+++ b/src/runtime/os3_solaris.go
32+
@@ -234,8 +234,11 @@
33+
getg().m.procid = 0
34+
}
35+
36+
-// Called from exitm, but not from drop, to undo the effect of thread-owned
37+
+// Called from mexit, but not from dropm, to undo the effect of thread-owned
38+
// resources in minit, semacreate, or elsewhere. Do not take locks after calling this.
39+
+//
40+
+// This always runs without a P, so //go:nowritebarrierrec is required.
41+
+//go:nowritebarrierrec
42+
func mdestroy(mp *m) {
43+
}
44+
45+
diff --git a/src/runtime/os_aix.go b/src/runtime/os_aix.go
46+
index 93464cb..1b483c2 100644
47+
--- a/src/runtime/os_aix.go
48+
+++ b/src/runtime/os_aix.go
49+
@@ -186,8 +186,11 @@
50+
getg().m.procid = 0
51+
}
52+
53+
-// Called from exitm, but not from drop, to undo the effect of thread-owned
54+
+// Called from mexit, but not from dropm, to undo the effect of thread-owned
55+
// resources in minit, semacreate, or elsewhere. Do not take locks after calling this.
56+
+//
57+
+// This always runs without a P, so //go:nowritebarrierrec is required.
58+
+//go:nowritebarrierrec
59+
func mdestroy(mp *m) {
60+
}
61+
62+
diff --git a/src/runtime/os_darwin.go b/src/runtime/os_darwin.go
63+
index 0ecbea7..6eab3b5 100644
64+
--- a/src/runtime/os_darwin.go
65+
+++ b/src/runtime/os_darwin.go
66+
@@ -344,8 +344,11 @@
67+
getg().m.procid = 0
68+
}
69+
70+
-// Called from exitm, but not from drop, to undo the effect of thread-owned
71+
+// Called from mexit, but not from dropm, to undo the effect of thread-owned
72+
// resources in minit, semacreate, or elsewhere. Do not take locks after calling this.
73+
+//
74+
+// This always runs without a P, so //go:nowritebarrierrec is required.
75+
+//go:nowritebarrierrec
76+
func mdestroy(mp *m) {
77+
}
78+
79+
diff --git a/src/runtime/os_dragonfly.go b/src/runtime/os_dragonfly.go
80+
index a02696e..9b32350 100644
81+
--- a/src/runtime/os_dragonfly.go
82+
+++ b/src/runtime/os_dragonfly.go
83+
@@ -216,8 +216,11 @@
84+
getg().m.procid = 0
85+
}
86+
87+
-// Called from exitm, but not from drop, to undo the effect of thread-owned
88+
+// Called from mexit, but not from dropm, to undo the effect of thread-owned
89+
// resources in minit, semacreate, or elsewhere. Do not take locks after calling this.
90+
+//
91+
+// This always runs without a P, so //go:nowritebarrierrec is required.
92+
+//go:nowritebarrierrec
93+
func mdestroy(mp *m) {
94+
}
95+
96+
diff --git a/src/runtime/os_linux.go b/src/runtime/os_linux.go
97+
index 8b3c4d0..fb46b81 100644
98+
--- a/src/runtime/os_linux.go
99+
+++ b/src/runtime/os_linux.go
100+
@@ -412,13 +412,12 @@
101+
getg().m.procid = 0
102+
}
103+
104+
-// Called from exitm, but not from drop, to undo the effect of thread-owned
105+
+// Called from mexit, but not from dropm, to undo the effect of thread-owned
106+
// resources in minit, semacreate, or elsewhere. Do not take locks after calling this.
107+
+//
108+
+// This always runs without a P, so //go:nowritebarrierrec is required.
109+
+//go:nowritebarrierrec
110+
func mdestroy(mp *m) {
111+
- if mp.vgetrandomState != 0 {
112+
- vgetrandomPutState(mp.vgetrandomState)
113+
- mp.vgetrandomState = 0
114+
- }
115+
}
116+
117+
// #ifdef GOARCH_386
118+
diff --git a/src/runtime/os_netbsd.go b/src/runtime/os_netbsd.go
119+
index 735ace2..a06e5fe 100644
120+
--- a/src/runtime/os_netbsd.go
121+
+++ b/src/runtime/os_netbsd.go
122+
@@ -320,8 +320,11 @@
123+
// must continue working after unminit.
124+
}
125+
126+
-// Called from exitm, but not from drop, to undo the effect of thread-owned
127+
+// Called from mexit, but not from dropm, to undo the effect of thread-owned
128+
// resources in minit, semacreate, or elsewhere. Do not take locks after calling this.
129+
+//
130+
+// This always runs without a P, so //go:nowritebarrierrec is required.
131+
+//go:nowritebarrierrec
132+
func mdestroy(mp *m) {
133+
}
134+
135+
diff --git a/src/runtime/os_openbsd.go b/src/runtime/os_openbsd.go
136+
index 574bfa8..4ce4c3c 100644
137+
--- a/src/runtime/os_openbsd.go
138+
+++ b/src/runtime/os_openbsd.go
139+
@@ -182,8 +182,11 @@
140+
getg().m.procid = 0
141+
}
142+
143+
-// Called from exitm, but not from drop, to undo the effect of thread-owned
144+
+// Called from mexit, but not from dropm, to undo the effect of thread-owned
145+
// resources in minit, semacreate, or elsewhere. Do not take locks after calling this.
146+
+//
147+
+// This always runs without a P, so //go:nowritebarrierrec is required.
148+
+//go:nowritebarrierrec
149+
func mdestroy(mp *m) {
150+
}
151+
152+
diff --git a/src/runtime/os_plan9.go b/src/runtime/os_plan9.go
153+
index 2dbb42a..3b5965a 100644
154+
--- a/src/runtime/os_plan9.go
155+
+++ b/src/runtime/os_plan9.go
156+
@@ -217,8 +217,11 @@
157+
func unminit() {
158+
}
159+
160+
-// Called from exitm, but not from drop, to undo the effect of thread-owned
161+
+// Called from mexit, but not from dropm, to undo the effect of thread-owned
162+
// resources in minit, semacreate, or elsewhere. Do not take locks after calling this.
163+
+//
164+
+// This always runs without a P, so //go:nowritebarrierrec is required.
165+
+//go:nowritebarrierrec
166+
func mdestroy(mp *m) {
167+
}
168+
169+
diff --git a/src/runtime/os_windows.go b/src/runtime/os_windows.go
170+
index 7183e79..54407a3 100644
171+
--- a/src/runtime/os_windows.go
172+
+++ b/src/runtime/os_windows.go
173+
@@ -906,9 +906,11 @@
174+
mp.procid = 0
175+
}
176+
177+
-// Called from exitm, but not from drop, to undo the effect of thread-owned
178+
+// Called from mexit, but not from dropm, to undo the effect of thread-owned
179+
// resources in minit, semacreate, or elsewhere. Do not take locks after calling this.
180+
//
181+
+// This always runs without a P, so //go:nowritebarrierrec is required.
182+
+//go:nowritebarrierrec
183+
//go:nosplit
184+
func mdestroy(mp *m) {
185+
if mp.highResTimer != 0 {
186+
diff --git a/src/runtime/proc.go b/src/runtime/proc.go
187+
index e9873e5..21bee4d 100644
188+
--- a/src/runtime/proc.go
189+
+++ b/src/runtime/proc.go
190+
@@ -1935,6 +1935,9 @@
191+
mp.gsignal = nil
192+
}
193+
194+
+ // Free vgetrandom state.
195+
+ vgetrandomDestroy(mp)
196+
+
197+
// Remove m from allm.
198+
lock(&sched.lock)
199+
for pprev := &allm; *pprev != nil; pprev = &(*pprev).alllink {
200+
diff --git a/src/runtime/vgetrandom_linux.go b/src/runtime/vgetrandom_linux.go
201+
index a6ec4b7..40be022 100644
202+
--- a/src/runtime/vgetrandom_linux.go
203+
+++ b/src/runtime/vgetrandom_linux.go
204+
@@ -73,9 +73,16 @@
205+
return state
206+
}
207+
208+
-func vgetrandomPutState(state uintptr) {
209+
+// Free vgetrandom state from the M (if any) prior to destroying the M.
210+
+//
211+
+// This may allocate, so it must have a P.
212+
+func vgetrandomDestroy(mp *m) {
213+
+ if mp.vgetrandomState == 0 {
214+
+ return
215+
+ }
216+
+
217+
lock(&vgetrandomAlloc.statesLock)
218+
- vgetrandomAlloc.states = append(vgetrandomAlloc.states, state)
219+
+ vgetrandomAlloc.states = append(vgetrandomAlloc.states, mp.vgetrandomState)
220+
unlock(&vgetrandomAlloc.statesLock)
221+
}
222+
223+
diff --git a/src/runtime/vgetrandom_unsupported.go b/src/runtime/vgetrandom_unsupported.go
224+
index 070392c..43c53e1 100644
225+
--- a/src/runtime/vgetrandom_unsupported.go
226+
+++ b/src/runtime/vgetrandom_unsupported.go
227+
@@ -13,6 +13,6 @@
228+
return -1, false
229+
}
230+
231+
-func vgetrandomPutState(state uintptr) {}
232+
+func vgetrandomDestroy(mp *m) {}
233+
234+
func vgetrandomInit() {}

‎sdk_container/src/third_party/portage-stable/dev-lang/go/go-1.23.7.ebuild

Lines changed: 0 additions & 163 deletions
This file was deleted.

‎sdk_container/src/third_party/portage-stable/dev-lang/go/go-1.23.8.ebuild

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ case ${PV} in
2323
case ${PV} in
2424
*_beta*|*_rc*) ;;
2525
*)
26-
KEYWORDS="-* amd64 arm ~arm64 ~loong ~mips ppc64 ~riscv ~s390 x86 ~amd64-linux ~x86-linux ~x64-macos ~x64-solaris"
26+
KEYWORDS="-* amd64 arm arm64 ~loong ~mips ppc64 ~riscv ~s390 x86 ~amd64-linux ~x86-linux ~x64-macos ~x64-solaris"
2727
;;
2828
esac
2929
esac

‎sdk_container/src/third_party/portage-stable/dev-lang/go/go-1.24.2-r1.ebuild renamed to ‎sdk_container/src/third_party/portage-stable/dev-lang/go/go-1.24.2-r2.ebuild

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ go_cross_compile() {
6969

7070
PATCHES=(
7171
"${FILESDIR}"/go-1.24-skip-gdb-tests.patch
72+
"${FILESDIR}"/go-1.24-vgetrandom.patch
7273
"${FILESDIR}"/go-1.24-dont-force-gold-arm.patch
7374
"${FILESDIR}"/go-never-download-newer-toolchains.patch
7475
)

0 commit comments

Comments
 (0)
Please sign in to comment.