diff --git a/0001-Enable-go-plugin-support-for-riscv64.patch b/0001-Enable-go-plugin-support-for-riscv64.patch new file mode 100644 index 0000000000000000000000000000000000000000..38912e9ae99feb1240ffca270ebf2b456aab0ef3 --- /dev/null +++ b/0001-Enable-go-plugin-support-for-riscv64.patch @@ -0,0 +1,40 @@ +From 019ec52ee5e7dec0c3a7937025948a742822a052 Mon Sep 17 00:00:00 2001 +From: misaka00251 +Date: Mon, 27 Mar 2023 10:27:38 +0800 +Subject: [PATCH] Enable go plugin support for riscv64 (based on work by + yangjinghua) + +--- + src/cmd/internal/sys/supported.go | 2 +- + src/cmd/link/internal/ld/config.go | 2 +- + 2 files changed, 2 insertions(+), 2 deletions(-) + +diff --git a/src/cmd/internal/sys/supported.go b/src/cmd/internal/sys/supported.go +index 1d74f6b..4fa8ed6 100644 +--- a/src/cmd/internal/sys/supported.go ++++ b/src/cmd/internal/sys/supported.go +@@ -142,7 +142,7 @@ func BuildModeSupported(compiler, buildmode, goos, goarch string) bool { + + case "plugin": + switch platform { +- case "linux/amd64", "linux/arm", "linux/arm64", "linux/386", "linux/s390x", "linux/ppc64le", ++ case "linux/amd64", "linux/arm", "linux/arm64", "linux/riscv64", "linux/386", "linux/s390x", "linux/ppc64le", + "android/amd64", "android/arm", "android/arm64", "android/386", + "darwin/amd64", "darwin/arm64", + "freebsd/amd64": +diff --git a/src/cmd/link/internal/ld/config.go b/src/cmd/link/internal/ld/config.go +index 4dd43a1..af5d8c5 100644 +--- a/src/cmd/link/internal/ld/config.go ++++ b/src/cmd/link/internal/ld/config.go +@@ -95,7 +95,7 @@ func (mode *BuildMode) Set(s string) error { + switch buildcfg.GOOS { + case "linux": + switch buildcfg.GOARCH { +- case "386", "amd64", "arm", "arm64", "s390x", "ppc64le": ++ case "386", "amd64", "arm", "arm64", "riscv64", "s390x", "ppc64le": + default: + return badmode() + } +-- +2.37.1 (Apple Git-137.1) + diff --git a/0002-runtime-support-riscv64-SV57-mode.patch b/0002-runtime-support-riscv64-SV57-mode.patch new file mode 100644 index 0000000000000000000000000000000000000000..445761efe7592edb4a006792050d07b233bbfe47 --- /dev/null +++ b/0002-runtime-support-riscv64-SV57-mode.patch @@ -0,0 +1,61 @@ +From 1e3c19f3fee12e5e2b7802a54908a4d4d03960da Mon Sep 17 00:00:00 2001 +From: Dmitry Vyukov +Date: Fri, 27 May 2022 18:55:35 +0200 +Subject: [PATCH] runtime: support riscv64 SV57 mode + +riscv64 has SV57 mode when user-space VA is 56 bits. +Linux kernel recently got support for this mode and Go binaries started crashing as: + +runtime: lfstack.push invalid packing: node=0xffffff5908a940 cnt=0x1 +packed=0xffff5908a9400001 -> node=0xffff5908a940 + +Adjust lfstack code to use only 8 top bits of pointers on riscv64. + +For context see: +https://groups.google.com/g/syzkaller-bugs/c/lU0GQTZoNQQ/m/O_c3vmE3AAAJ + +Update #54104 + +Change-Id: Ib5d3d6a79c0c6eddf11618d73fcc8bc1832a9c25 +Reviewed-on: https://go-review.googlesource.com/c/go/+/409055 +Reviewed-by: Joel Sing +Reviewed-by: Meng Zhuo +Reviewed-by: Michael Knyszek +Reviewed-by: Cherry Mui +--- + +diff --git a/src/runtime/lfstack_64bit.go b/src/runtime/lfstack_64bit.go +index 154130c..88cbd3b 100644 +--- a/src/runtime/lfstack_64bit.go ++++ b/src/runtime/lfstack_64bit.go +@@ -36,12 +36,21 @@ + // We use one bit to distinguish between the two ranges. + aixAddrBits = 57 + aixCntBits = 64 - aixAddrBits + 3 ++ ++ // riscv64 SV57 mode gives 56 bits of userspace VA. ++ // lfstack code supports it, but broader support for SV57 mode is incomplete, ++ // and there may be other issues (see #54104). ++ riscv64AddrBits = 56 ++ riscv64CntBits = 64 - riscv64AddrBits + 3 + ) + + func lfstackPack(node *lfnode, cnt uintptr) uint64 { + if GOARCH == "ppc64" && GOOS == "aix" { + return uint64(uintptr(unsafe.Pointer(node)))<<(64-aixAddrBits) | uint64(cnt&(1<> aixCntBits << 3) | 0xa<<56))) + } ++ if GOARCH == "riscv64" { ++ return (*lfnode)(unsafe.Pointer(uintptr(val >> riscv64CntBits << 3))) ++ } + return (*lfnode)(unsafe.Pointer(uintptr(val >> cntBits << 3))) + } diff --git a/0003-release-branch.go1.19-go-scanner-reject-large-line.patch b/0003-release-branch.go1.19-go-scanner-reject-large-line.patch new file mode 100644 index 0000000000000000000000000000000000000000..86875be643fb37b5d4063d0485072c44949fcc9e --- /dev/null +++ b/0003-release-branch.go1.19-go-scanner-reject-large-line.patch @@ -0,0 +1,91 @@ +From 126a1d02da82f93ede7ce0bd8d3c51ef627f2104 Mon Sep 17 00:00:00 2001 +From: Damien Neil +Date: Wed, 22 Mar 2023 09:33:22 -0700 +Subject: [PATCH] [release-branch.go1.19] go/scanner: reject large line and + column numbers in //line directives + +Setting a large line or column number using a //line directive can cause +integer overflow even in small source files. + +Limit line and column numbers in //line directives to 2^30-1, which +is small enough to avoid int32 overflow on all reasonbly-sized files. + +Fixes CVE-2023-24537 +Fixes #59273 +For #59180 + +Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/1802456 +Reviewed-by: Julie Qiu +Reviewed-by: Roland Shoemaker +Run-TryBot: Damien Neil +Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/1802611 +Reviewed-by: Damien Neil +Change-Id: Ifdfa192d54f722d781a4d8c5f35b5fb72d122168 +Reviewed-on: https://go-review.googlesource.com/c/go/+/481986 +Reviewed-by: Matthew Dempsky +TryBot-Result: Gopher Robot +Run-TryBot: Michael Knyszek +Auto-Submit: Michael Knyszek +--- + src/go/parser/parser_test.go | 16 ++++++++++++++++ + src/go/scanner/scanner.go | 7 +++++-- + 2 files changed, 21 insertions(+), 2 deletions(-) + +diff --git a/src/go/parser/parser_test.go b/src/go/parser/parser_test.go +index 0c278924c9..15b265ffc3 100644 +--- a/src/go/parser/parser_test.go ++++ b/src/go/parser/parser_test.go +@@ -742,3 +742,19 @@ func TestScopeDepthLimit(t *testing.T) { + } + } + } ++ ++// TestIssue59180 tests that line number overflow doesn't cause an infinite loop. ++func TestIssue59180(t *testing.T) { ++ testcases := []string{ ++ "package p\n//line :9223372036854775806\n\n//", ++ "package p\n//line :1:9223372036854775806\n\n//", ++ "package p\n//line file:9223372036854775806\n\n//", ++ } ++ ++ for _, src := range testcases { ++ _, err := ParseFile(token.NewFileSet(), "", src, ParseComments) ++ if err == nil { ++ t.Errorf("ParseFile(%s) succeeded unexpectedly", src) ++ } ++ } ++} +diff --git a/src/go/scanner/scanner.go b/src/go/scanner/scanner.go +index 07e07581f7..6a7e30bb2f 100644 +--- a/src/go/scanner/scanner.go ++++ b/src/go/scanner/scanner.go +@@ -246,13 +246,16 @@ func (s *Scanner) updateLineInfo(next, offs int, text []byte) { + return + } + ++ // Put a cap on the maximum size of line and column numbers. ++ // 30 bits allows for some additional space before wrapping an int32. ++ const maxLineCol = 1<<30 - 1 + var line, col int + i2, n2, ok2 := trailingDigits(text[:i-1]) + if ok2 { + //line filename:line:col + i, i2 = i2, i + line, col = n2, n +- if col == 0 { ++ if col == 0 || col > maxLineCol { + s.error(offs+i2, "invalid column number: "+string(text[i2:])) + return + } +@@ -262,7 +265,7 @@ func (s *Scanner) updateLineInfo(next, offs int, text []byte) { + line = n + } + +- if line == 0 { ++ if line == 0 || line > maxLineCol { + s.error(offs+i, "invalid line number: "+string(text[i:])) + return + } +-- +2.33.0 + diff --git a/golang.spec b/golang.spec index 5e8e36eb32c4e309caaabb9fd9d8c4226e8ab274..fb952987fe1906c7590726e641502791ec708441 100644 --- a/golang.spec +++ b/golang.spec @@ -62,11 +62,14 @@ Name: golang Version: 1.19.4 -Release: 1 +Release: 3 Summary: The Go Programming Language License: BSD and Public Domain URL: https://golang.org/ Source0: https://dl.google.com/go/go1.19.4.src.tar.gz +Patch0: 0001-Enable-go-plugin-support-for-riscv64.patch +Patch1: 0002-runtime-support-riscv64-SV57-mode.patch +Patch2: 0003-release-branch.go1.19-go-scanner-reject-large-line.patch %if !%{golang_bootstrap} BuildRequires: gcc-go >= 5 @@ -387,6 +390,12 @@ fi %files devel -f go-tests.list -f go-misc.list -f go-src.list %changelog +* Thu Apr 20 2023 sunchendong - 1.19.4-3 +- fix CVE-2023-24537 + +* Mon Apr 03 2023 misaka00251 - 1.19.4-2 +- Enable go plugin support for riscv64 (based on work by yangjinghua) +- Backport upstream sv57 enablement for riscv64 * Tue Jan 10 2023 hanchao - 1.19.4-1 - upgrade to 1.19.4