New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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.

@stanaka

This comment has been minimized.

Show comment
Hide comment
@stanaka

stanaka Mar 24, 2016

Contributor

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
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
@djtm

This comment has been minimized.

Show comment
Hide comment
@djtm

djtm Mar 25, 2016

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

djtm commented Mar 25, 2016

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

@stanaka

This comment has been minimized.

Show comment
Hide comment
@stanaka

stanaka Mar 25, 2016

Contributor

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
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

This comment has been minimized.

Show comment
Hide comment
@stanaka

stanaka Mar 26, 2016

Contributor

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.

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

This comment has been minimized.

Show comment
Hide comment

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

@gopherbot

This comment has been minimized.

Show comment
Hide comment

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

gopherbot pushed a commit that referenced this issue Oct 23, 2016

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>

@golang golang locked and limited conversation to collaborators Oct 23, 2017

wheatman added a commit to wheatman/go-akaros that referenced this issue Jun 25, 2018

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>

wheatman added a commit to wheatman/go-akaros that referenced this issue Jun 26, 2018

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>

wheatman added a commit to wheatman/go-akaros that referenced this issue Jul 9, 2018

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>

wheatman added a commit to wheatman/go-akaros that referenced this issue Jul 20, 2018

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>

wheatman added a commit to wheatman/go-akaros that referenced this issue Jul 30, 2018

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>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.