src/runtime/os_linux_x86.go | 35 ++++++++++++++++++++++++++++++++++- diff --git a/src/runtime/os_linux_x86.go b/src/runtime/os_linux_x86.go index d001e6ee59a505862784d8d86140e20622afb7cb..97f870707de7de08f4e28253f69442f007a98131 100644 --- a/src/runtime/os_linux_x86.go +++ b/src/runtime/os_linux_x86.go @@ -7,7 +7,10 @@ // +build 386 amd64 package runtime -import "runtime/internal/atomic" +import ( + "runtime/internal/atomic" + "unsafe" +) //go:noescape func uname(utsname *new_utsname) int @@ -53,6 +56,36 @@ major, minor, patch, ok := parseRelease(rel) if !ok { return + } + + if major == 5 && minor == 4 && patch < 2 { + // All 5.4 versions of Ubuntu are patched. + procVersion := []byte("/proc/version\000") + f := open(&procVersion[0], _O_RDONLY, 0) + if f >= 0 { + var buf [512]byte + p := noescape(unsafe.Pointer(&buf[0])) + n := read(f, p, int32(len(buf))) + closefd(f) + + needle := []byte("Ubuntu") + contains: + for i, c := range buf[:n] { + if c != needle[0] { + continue + } + if int(n)-i < len(needle) { + break + } + for j, c2 := range needle { + if c2 != buf[i+j] { + continue contains + } + } + // This is an Ubuntu system. + return + } + } } if major == 5 && (minor == 2 || minor == 3 && patch < 15 || minor == 4 && patch < 2) {