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

Assign correct stack_type to map #1524

Merged
merged 1 commit into from
Sep 29, 2020
Merged

Assign correct stack_type to map #1524

merged 1 commit into from
Sep 29, 2020

Conversation

fbs
Copy link
Member

@fbs fbs commented Sep 19, 2020

The type of a map gets determined the first time something gets assigned
to it. As the arguments to kstack/ustack only get evaluated in the
last pass the map will be created with the default stack type, not the
one specified by the user.
Due to the way stacks work, with the hidden stack map and the user map
that holds the stack id, this only shows up when trying to print the
map. The type associated with the user map has the correct stack type,
but the original map has the default. This eventually leads to a SEGV.

Simple repro:

'i:s:1 { $a=10; @=kstack(perf); exit(); }'
Thread 1 "bpftrace" received signal SIGSEGV, Segmentation fault.
0x000000000046475a in bpftrace::BPFtrace::get_stack[abi:cxx11](...)
1680	  int err = bpf_lookup_elem(maps[stack_type].value()->mapfd_,
(gdb) p stack_type
$1 = {limit = 127, mode = bpftrace::StackMode::bpftrace}`

As this call expects literals we don't have to worry about variables and
thing that might be evaluated later, so we can just remove the
is_final_pass() check.

This fixes #1523

Checklist
  • User-visible and non-trivial changes updated in CHANGELOG.md
  • The new behaviour is covered by tests

@fbs
Copy link
Member Author

fbs commented Sep 19, 2020

bpftrace -e 'i:s:1 { @a=kstack(perf); @b=kstack(bpftrace) }'
Attaching 1 probe...
^C

@a:
	ffffffff9fca5cae native_safe_halt+14
	ffffffff9f23d7a5 arch_cpu_idle+21
	ffffffff9fca5e53 default_idle_call+35
	ffffffff9f2d8fcb do_idle+507
	ffffffff9f2d91d0 cpu_startup_entry+32
	ffffffff9fc988de rest_init+174
	ffffffffa0a99c77 arch_call_rest_init+14
	ffffffffa0a9a1fe start_kernel+1380
	ffffffffa0a9944a x86_64_start_reservations+36
	ffffffffa0a994c1 x86_64_start_kernel+117
	ffffffff9f2000d4 secondary_startup_64+164

@b:
        native_safe_halt+14
        arch_cpu_idle+21
        default_idle_call+35
        do_idle+507
        cpu_startup_entry+32
        rest_init+174
        arch_call_rest_init+14
        start_kernel+1380
        x86_64_start_reservations+36
        x86_64_start_kernel+117
        secondary_startup_64+164

@grooverdan
Copy link

worked for me. Thank you very much.

@fbs
Copy link
Member Author

fbs commented Sep 29, 2020

Ready for review. I'll fix the changelog when it has some approvals

The type of a map gets determined the first time something gets assigned
to it. As the arguments to `kstack/ustack` only get evaluated in the
last pass the map will be created with the default stack type, not the
one specified by the user.
Due to the way stacks work, with the hidden stack map and the user map
that holds the stack id, this only shows up when trying to print the
map. The type associated with the user map has the correct stack type,
but the original map has the default. This eventually leads to a SEGV.

Simple repro:

```
'i:s:1 { $a=10; @=kstack(perf); exit(); }'
```

```
Thread 1 "bpftrace" received signal SIGSEGV, Segmentation fault.
0x000000000046475a in bpftrace::BPFtrace::get_stack[abi:cxx11](...)
1680	  int err = bpf_lookup_elem(maps[stack_type].value()->mapfd_,
(gdb) p stack_type
$1 = {limit = 127, mode = bpftrace::StackMode::bpftrace}`
```

As this call expects literals we don't have to worry about variables and
thing that might be evaluated later, so we can just remove the
`is_final_pass()` check.

This fixes bpftrace#1523
@fbs fbs merged commit b26f76c into bpftrace:master Sep 29, 2020
@fbs fbs deleted the 1523_fix branch September 29, 2020 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ustack(perf) segv on bpftrace
3 participants