Skip to content
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

[Bug]: Segfault using emulation #1080

Closed
iapaddler opened this issue Aug 17, 2022 · 5 comments · Fixed by #1081
Closed

[Bug]: Segfault using emulation #1080

iapaddler opened this issue Aug 17, 2022 · 5 comments · Fixed by #1081
Assignees
Labels
bug Something isn't working
Milestone

Comments

@iapaddler
Copy link
Contributor

Steps To Reproduce

on an M1 Mac
install docker (or multipass with docker on a headless M1 Mac)
run an x86_64 Linux container on the M1
emulation will be enabled such that x86_64 code will run on the arm64 arch of the M1
install terraform (or any Go static exec)
ldscope terraform -h
it has the possibility of a segfault

Environment

- AppScope:v1.1.2
- OS:MacOS and Ubuntu
- Architecture: ARM & x86_64

Requested priority

No response

Relevant log output

No response

@iapaddler iapaddler added the bug Something isn't working label Aug 17, 2022
@iapaddler iapaddler added this to the Next Maintenance (1.1.3) milestone Aug 17, 2022
@iapaddler iapaddler self-assigned this Aug 17, 2022
@iapaddler
Copy link
Contributor Author

A call to mmap() results in the segfault.
The emulation does not appear to support mapping of a fixed address. The use of the flag MAP_FIXED causes the segfault.
mmap is documented to return the error MAP_FAILED if a fixed address can't be mapped.
The emulation layer appears to segfault as opposed to return an error.
Without this flag mmap does not segfault or return an error. However, the load address needed for loading the Go static executable is not available.

@iapaddler
Copy link
Contributor Author

The reason why mmap is failing is that the kernel is not able to able to map the address at which the static exec has been built to use.

It should NOT segfault. It should return an error. That seems to be an issue with emulation.

The address that the static exec is built for is 0x00400000. The emulator is loaded at this address. It appears to be static, not optional. From the map file:
00400000-006c3000 r-xp 00000000 08:01 75251 /usr/bin/qemu-x86_64-static

@iapaddler
Copy link
Contributor Author

Code in the static loader has been updated to remove the use of the MAP_FIXED flag. This works around the issue in the emulator that causes a segfault.

We check to see that the address that was mapped is what is expected. If not, it is an error.

The scope and ldscope commands should recognize this error and allow the static exec to run unscoped.

@iapaddler
Copy link
Contributor Author

iapaddler commented Aug 17, 2022

It works as expected without a segfault:
ldscope terraform version
Terraform v1.2.7
on linux_amd64

@iapaddler
Copy link
Contributor Author

terraform, dynamic, go 1.18, x86_64, ubuntu, M1 Mac, arm64 works

$ scope run -- ./terraform version
Terraform v1.2.1
on linux_amd64

Your version of Terraform is out of date! The latest version
is 1.2.7. You can update by downloading from https://www.terraform.io/downloads.html

$ scope events
[0] Aug 17 21:37:39 terraform fs fs.open file:/tsrc/terraform/terraform
[i7] Aug 17 21:37:39 terraform fs fs.close file:/tsrc/terraform/terraform file_read_bytes:0 file_read_ops:0 file_write_bytes:0 file_write_ops:0
[8g] Aug 17 21:37:39 terraform fs fs.open file:/root/.terraform.d
[jn] Aug 17 21:37:39 terraform fs fs.close file:/root/.terraform.d file_read_bytes:128 file_read_ops:2 file_write_bytes:0 file_write_ops:0
[5w] Aug 17 21:37:39 terraform fs fs.open file:/root/.terraform.d/checkpoint_cache
[wD] Aug 17 21:37:39 terraform fs fs.close file:/root/.terraform.d/checkpoint_cache file_read_bytes:326 file_read_ops:4 file_write_bytes:0 file_write_ops:0
[yM] Aug 17 21:37:39 terraform console stdout message:"Terraform v1.2.1 on linux_amd64 Your version of Terraform is out of date! The latest version is 1.2.7. You can update by downloading from https://www.te…"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant