bcc/filelife and bpftrace/segfault patch
Posted rtoax
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了bcc/filelife and bpftrace/segfault patch相关的知识,希望对你有一定的参考价值。
2022-11-13
================================================================================
```
libbpf-tools: filelife: update arguments and add vfs_open()
I already open a PR for `tools/filelife.py`, i think two PR better than
single one. After all, `libbpf-tools/filelife` is compiled separately,
and `tools/filelife.py` is the python script.
Since kernel commit 6521f8917082("namei: prepare for idmapped mounts"),
the vfs_unlink() function add argument 'struct user_namespace'. And
add vfs_open() probe if 'f_mode = FMODE_CREATED'.
Link: https://github.com/iovisor/bcc/pull/4339
```
```
Attaching 3 probes...
d_alloc: 0xffff9ad511a05900
d_alloc: 0xffff9ad511a05900
d_alloc: 0xffff9ad5977e7000
d_alloc: 0xffff9ad5977e76c0
d_alloc: 0xffff9ad5977e7d80
d_alloc: 0xffff9ad5977e7240
vfs_open: comm touch, dentry 0xffff9ad5f6d6e300, (nil), 809346181
unlink: 0xffff9ad316f7ad00, 1051722
d_alloc: 0xffff9ad511a05900
d_alloc: 0xffff9ad511b16a80
d_alloc: 0xffff9ad5d7125d80
d_alloc: 0xffff9ad5d71256c0
d_alloc: 0xffff9ad422729b40
d_alloc: 0xffff9ad422729d80
d_alloc: 0xffff9ad422729840
d_alloc: 0xffff9ad422729cc0
d_alloc: 0xffff9ad422729cc0
d_alloc: 0xffff9ad422729840
d_alloc: 0xffff9ad422729d80
d_alloc: 0xffff9ad422729b40
d_alloc: 0xffff9ad5d71256c0
d_alloc: 0xffff9ad5d7125d80
d_alloc: 0xffff9ad511b16a80
d_alloc: 0xffff9ad422726840
d_alloc: 0xffff9ad422728a80
d_alloc: 0xffff9ad422728000
d_alloc: 0xffff9ad422728900
d_alloc: 0xffff9ad422728600
d_alloc: 0xffff9ad5f76be480
d_alloc: 0xffff9ad5f76be3c0
d_alloc: 0xffff9ad5f76be0c0
d_alloc: 0xffff9ad5f76becc0
d_alloc: 0xffff9ad5f76be900
d_alloc: 0xffff9ad5f76be240
d_alloc: 0xffff9ad5f76be600
d_alloc: 0xffff9ad5f76bee40
vfs_open: comm touch, dentry 0xffff9ad5f6d6e300, (nil), 809346181
unlink: 0xffff9ad316f7ad00, 1051722
d_alloc: 0xffff9ad511a05e40
vfs_open: comm touch, dentry 0xffff9ad5f6d6e300, (nil), 809346181
unlink: 0xffff9ad316f7ad00, 1051722
d_alloc: 0xffff9ad511a05e40
```
2022-11-13
================================================================================
https://github.com/iovisor/bpftrace/pull/2423
# 段错误
Fix segfault for invalid AssignVarStatement visit
When CodegenLLVM::visit calls CreateStore() with NULL expr_ as parameter,
segfault is generated, for example:
#include <linux/fs.h>
kprobe:vfs_open
$file = (struct file *)
printf("Hello\\n");
Acctually, we want to '$file = (struct file *)arg1;' here. When writing
incorrectly '$file = (struct file *)', printf() make expr_ == nullptr,
when call CreateStore(NULL, ...), segfault has occurred, and the stack
backtrace is as follows:
(gdb) bt
#0 0x00000000007098c6 in llvm::Value::getType (this=0x0) at /usr/include/llvm/IR/Value.h:255
#1 0x000000000070cc76 in llvm::IRBuilderBase::CreateAlignedStore (this=0x7fffffffbe40, Val=0x0,
Ptr=0x15e2340, Align=..., isVolatile=false) at /usr/include/llvm/IR/IRBuilder.h:1689
#2 0x000000000070cab3 in llvm::IRBuilderBase::CreateStore (this=0x7fffffffbe40, Val=0x0, Ptr=0x15e2340,
isVolatile=false) at /usr/include/llvm/IR/IRBuilder.h:1663
#3 0x00000000006f6948 in bpftrace::ast::CodegenLLVM::visit (this=0x7fffffffbe10, assignment=...)
at /home/rongtao/Git/bpftrace/src/ast/passes/codegen_llvm.cpp:2140
#4 0x0000000000751258 in bpftrace::ast::AssignVarStatement::accept (this=0x7fffe99b9a30, v=...)
at /home/rongtao/Git/bpftrace/src/ast/ast.cpp:35
#5 0x00000000006ff6ea in bpftrace::ast::CodegenLLVM::accept (this=0x7fffffffbe10, node=0x7fffe99b9a30)
at /home/rongtao/Git/bpftrace/src/ast/passes/codegen_llvm.cpp:3360
We should prompt the user for some useful information, like:
$ sudo ./sample.bt
./t3-call.bt:4:9-10: FATAL: Invalid expression for "$file"
$file = (struct file *)
~
Aborted
We can't solve this problem semantic_analyser because the syntax is
correct. Maybe in the future we can solve it by modifying parser.yy,
but this modification is not considered because it is more complicated.
In any case, the CreateStore() parameter should not be NULL during the
codegen phase.
LLVM/Clang Version: 15.0.1
(gdb) bt
#0 0x00000000007098c6 in llvm::Value::getType (this=0x0) at /usr/include/llvm/IR/Value.h:255
#1 0x000000000070cc76 in llvm::IRBuilderBase::CreateAlignedStore (this=0x7fffffffbe40, Val=0x0,
Ptr=0x15e2340, Align=..., isVolatile=false) at /usr/include/llvm/IR/IRBuilder.h:1689
#2 0x000000000070cab3 in llvm::IRBuilderBase::CreateStore (this=0x7fffffffbe40, Val=0x0, Ptr=0x15e2340,
isVolatile=false) at /usr/include/llvm/IR/IRBuilder.h:1663
#3 0x00000000006f6948 in bpftrace::ast::CodegenLLVM::visit (this=0x7fffffffbe10, assignment=...)
at /home/rongtao/Git/bpftrace/src/ast/passes/codegen_llvm.cpp:2140
#4 0x0000000000751258 in bpftrace::ast::AssignVarStatement::accept (this=0x7fffe99b9a30, v=...)
at /home/rongtao/Git/bpftrace/src/ast/ast.cpp:35
#5 0x00000000006ff6ea in bpftrace::ast::CodegenLLVM::accept (this=0x7fffffffbe10, node=0x7fffe99b9a30)
at /home/rongtao/Git/bpftrace/src/ast/passes/codegen_llvm.cpp:3360
#6 0x00000000006f7aef in bpftrace::ast::CodegenLLVM::generateProbe (this=0x7fffffffbe10, probe=...,
full_func_id="kprobe:vfs_open", section_name="kprobe:vfs_open", func_type=0x15766c0, expansion=false,
usdt_location_index=std::optional<int> [no contained value], dummy=false)
at /home/rongtao/Git/bpftrace/src/ast/passes/codegen_llvm.cpp:2361
#7 0x00000000006f7f92 in bpftrace::ast::CodegenLLVM::visit (this=0x7fffffffbe10, probe=...)
at /home/rongtao/Git/bpftrace/src/ast/passes/codegen_llvm.cpp:2447
#8 0x00000000007513b6 in bpftrace::ast::Probe::accept (this=0x7fffe804acf0, v=...)
at /home/rongtao/Git/bpftrace/src/ast/ast.cpp:42
#9 0x00000000006ff6ea in bpftrace::ast::CodegenLLVM::accept (this=0x7fffffffbe10, node=0x7fffe804acf0)
at /home/rongtao/Git/bpftrace/src/ast/passes/codegen_llvm.cpp:3360
#10 0x00000000006f8dc8 in bpftrace::ast::CodegenLLVM::visit (this=0x7fffffffbe10, program=...)
at /home/rongtao/Git/bpftrace/src/ast/passes/codegen_llvm.cpp:2580
#11 0x00000000007513e8 in bpftrace::ast::Program::accept (this=0x7fffe804aa60, v=...)
at /home/rongtao/Git/bpftrace/src/ast/ast.cpp:43
#12 0x00000000006ff6ea in bpftrace::ast::CodegenLLVM::accept (this=0x7fffffffbe10, node=0x7fffe804aa60)
at /home/rongtao/Git/bpftrace/src/ast/passes/codegen_llvm.cpp:3360
#13 0x00000000006fed1a in bpftrace::ast::CodegenLLVM::generate_ir (this=0x7fffffffbe10)
at /home/rongtao/Git/bpftrace/src/ast/passes/codegen_llvm.cpp:3216
#14 0x000000000041df47 in main (argc=3, argv=0x7fffffffe508) at /home/rongtao/Git/bpftrace/src/main.cpp:896
================================================================================
```
warning: sdist: manifest template 'MANIFEST.in' does not exist (using default file list)
warning: sdist: standard file not found: should have one of README, README.txt, README.rst
writing manifest file 'MANIFEST'
```
以上是关于bcc/filelife and bpftrace/segfault patch的主要内容,如果未能解决你的问题,请参考以下文章
bpftrace: Join broken by LLVM 14