runtime: modify_ldt is optional in newer linux kernels, use set_thread_area instead #14795

Closed
minux opened this Issue Mar 12, 2016 · 6 comments

Projects

None yet

4 participants

@minux
Member
minux commented Mar 12, 2016

see https://lkml.org/lkml/2015/7/21/759

we probably need to switch to use set_thread_area(2) instead for linux/386.
(do we need to apply this Go 1.4.4 so that Go 1.4 continues to run on
newer kernels with disabled modify_ldt? tentatively labeled Go1.4.4)

According to arch_prctl(2) man page: http://man7.org/linux/man-pages/man2/arch_prctl.2.html
Context switches for 64-bit segment bases are rather expensive. As
an optimization, if a 32-bit TLS base address is used, arch_prctl(2)
may use a real TLS entry as if set_thread_area(2) had been called,
instead of manipulating the segment base register directly.

so we probably could switch to set_thread_area even on linux/amd64,
but I see that glibc still uses arch_prctl(ARCH_SET_FS), so probably
the overhead is not that big a problem.

@minux minux added this to the Go1.4.4 milestone Mar 12, 2016
@stanaka
Contributor
stanaka commented Mar 24, 2016

I've got an error, Trace/breakpoint trap with a crossbuilt 386 binary on Amazon Linux 2016.03, which is released a few days ago. This issue probably caused the error.

I've confirmed it on the following environment.

$ go version
go version go1.6 linux/amd64
$ uname -a
Linux ip-10-1-8-251 4.4.5-15.26.amzn1.x86_64 #1 SMP Wed Mar 16 17:15:34 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
@stanaka stanaka referenced this issue in mackerelio/mackerel-agent Mar 25, 2016
Merged

use GOARCH=amd64 for now #213

@djtm
djtm commented Mar 25, 2016

You can also try to echo 1 > /proc/sys/modify_ldt as workaround. But this has security implications.

@stanaka
Contributor
stanaka commented Mar 25, 2016

Unfortunately the kernel config CONFIG_MODIFY_LDT_SYSCALL of Amazon Linux 2016.03 is disabled, so /proc/sys/modify_ldt does not exist. ( /proc/sys/kernel/modify_ldt also does not exist. )

$ cat /boot/config-4.4.5-15.26.amzn1.x86_64  | grep MODIFY_LDT
# CONFIG_MODIFY_LDT_SYSCALL is not set
@stanaka
Contributor
stanaka commented Mar 26, 2016

With this patch, https://gist.github.com/stanaka/2b63a16d484692b3599f, which is based on the patch on this comment #386 (comment), linux/386 binary seems to work well on Amazon Linux 2016.03, of which kernel is 4.4.5.

@gopherbot

CL https://golang.org/cl/21190 mentions this issue.

@gopherbot gopherbot pushed a commit that closed this issue Mar 28, 2016
@stanaka @minux stanaka + minux runtime: use set_thread_area instead of modify_ldt on linux/386
linux/386 depends on modify_ldt system call, but recent Linux kernels
can disable this system call. Any Go programs built as linux/386
crash with the message 'Trace/breakpoint trap'.

The kernel config CONFIG_MODIFY_LDT_SYSCALL, which control
enable/disable modify_ldt, is disabled on Amazon Linux 2016.03.

This fixes this problem by using set_thread_area instead of modify_ldt
on linux/386.

Fixes #14795.

Change-Id: I0cc5139e40e9e5591945164156a77b6bdff2c7f1
Reviewed-on: https://go-review.googlesource.com/21190
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-by: Minux Ma <minux@golang.org>
0f86d1e
@gopherbot gopherbot closed this in 0f86d1e Mar 28, 2016
@gopherbot

CL https://golang.org/cl/31753 mentions this issue.

@gopherbot gopherbot pushed a commit that referenced this issue Oct 23, 2016
@josharian josharian runtime: use set_thread_area instead of modify_ldt on linux/386
This is a cherry-pick of https://go-review.googlesource.com/21190
to release-branch-go1.4. Diff prepared by Ian Lance Taylor.

linux/386 depends on modify_ldt system call, but recent Linux kernels
can disable this system call. Any Go programs built as linux/386
crash with the message 'Trace/breakpoint trap'.

The kernel config CONFIG_MODIFY_LDT_SYSCALL, which control
enable/disable modify_ldt, is disabled on Amazon Linux 2016.03.

This fixes this problem by using set_thread_area instead of modify_ldt
on linux/386.

Fixes #14795.

Change-Id: I22a67d6119e5d24afaa01e2c2b8174991a8a9bf4
Reviewed-on: https://go-review.googlesource.com/31753
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
09b43b7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment