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

update build dependencies #3

Merged
merged 1 commit into from
Sep 16, 2019
Merged

update build dependencies #3

merged 1 commit into from
Sep 16, 2019

Conversation

pzakha
Copy link
Contributor

@pzakha pzakha commented Sep 11, 2019

This depends on delphix/linux-pkg#54

bpftrace is now available as a package on Ubuntu 19.04, and it has the dependencies below.

Switching to llvm7/clang7 fixes bpftrace/bpftrace#76, so we should be able to remove the custom llvm5/clang5 ppa we are using in linux-pkg to build bpftrace.

Testing

ab-pre-push: http://selfservice.jenkins.delphix.com/job/devops-gate/job/master/job/appliance-build-orchestrator-pre-push/2184/ (pass)

@pzakha pzakha merged commit 4e4b1e4 into delphix:master Sep 16, 2019
delphix-devops-bot pushed a commit that referenced this pull request Jan 1, 2020
ASAN is incredibly useful to prevent entire classes of memory errors.
For example, when ASAN is enabled, it already shows us 35 memory leaks:

```
$  ~/dev/bpftrace git:(asan) ✗ sudo ./build/src/bpftrace -e 'BEGIN { printf("hi\n"); }'
[sudo] password for dxu:
Attaching 1 probe...
hi
^C

=================================================================
==758098==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 288 byte(s) in 4 object(s) allocated from:
    #0 0x7f72bbb5dcd8 in __interceptor_calloc /build/gcc/src/gcc/lib...
    #1 0x7f72b96665e5 in perf_reader_new (/usr/lib/libbcc.so.0+0x3e85e5)
    #2 0x7ffc5103b767  ([stack]+0x68767)

Direct leak of 80 byte(s) in 1 object(s) allocated from:
    #0 0x7f72bbb5f8f8 in operator new(unsigned long) /build/gcc/src/...
    #1 0x5631e1a566cd in bpftrace::Parser::parse() src/parser.yy:151
    #2 0x5631e18cae7e in bpftrace::Driver::parse() /home/dxu/dev/bpft...
    #3 0x5631e18dd8ac in main /home/dxu/dev/bpftrace/src/main.cpp:349
    #4 0x7f72b3eb5152 in __libc_start_main (/usr/lib/libc.so.6+0x27152)

Direct leak of 80 byte(s) in 1 object(s) allocated from:
    #0 0x7f72bbb5f8f8 in operator new(unsigned long) /build/gcc/src/g...
    #1 0x5631e1a566cd in bpftrace::Parser::parse() src/parser.yy:151
    #2 0x5631e18cae7e in bpftrace::Driver::parse() /home/dxu/dev/bpf...
    #3 0x5631e18df34f in main /home/dxu/dev/bpftrace/src/main.cpp:491
    #4 0x7f72b3eb5152 in __libc_start_main (/usr/lib/libc.so.6+0x27152)

[...]
```

The default is off for now b/c we have a lot of noisy leaks. Once those
are fixed, we should flip to on by default to be in preventative mode.

Note we also have to disable the rlimit protection b/c ASAN needs to
mmap a huge amount of the address space to work.
delphix-devops-bot pushed a commit that referenced this pull request Mar 21, 2020
This fixes the following error.

```
% sudo ./src/bpftrace -e 'w::0x10000000:8:: {}'
AddressSanitizer:DEADLYSIGNAL
=================================================================
==26761==ERROR: AddressSanitizer: SEGV on unknown address 0x614000010000 (pc 0x0000008dc6b6 bp 0x7ffe172080c0 sp 0x7ffe17207540 T0)
==26761==The signal is caused by a READ memory access.
    #0 0x8dc6b6 in bpftrace::ast::SemanticAnalyser::visit(bpftrace::ast::AttachPoint&) /home/ubuntu/work/bpftrace/bpftrace/build_asan/../src/ast/semantic_analyser.cpp:1684:25
    #1 0x87c3e3 in bpftrace::ast::AttachPoint::accept(bpftrace::ast::Visitor&) /home/ubuntu/work/bpftrace/bpftrace/build_asan/../src/ast/ast.cpp:323:5
    #2 0x8dd1bc in bpftrace::ast::SemanticAnalyser::visit(bpftrace::ast::Probe&) /home/ubuntu/work/bpftrace/bpftrace/build_asan/../src/ast/semantic_analyser.cpp:1737:9
    #3 0x87c603 in bpftrace::ast::Probe::accept(bpftrace::ast::Visitor&) /home/ubuntu/work/bpftrace/bpftrace/build_asan/../src/ast/ast.cpp:355:5
    #4 0x8dd2eb in bpftrace::ast::SemanticAnalyser::visit(bpftrace::ast::Program&) /home/ubuntu/work/bpftrace/bpftrace/build_asan/../src/ast/semantic_analyser.cpp:1751:12
    #5 0x87c6b3 in bpftrace::ast::Program::accept(bpftrace::ast::Visitor&) /home/ubuntu/work/bpftrace/bpftrace/build_asan/../src/ast/ast.cpp:364:5
    #6 0x8dd35a in bpftrace::ast::SemanticAnalyser::analyse() /home/ubuntu/work/bpftrace/bpftrace/build_asan/../src/ast/semantic_analyser.cpp:1760:12
    #7 0x80f63f in main /home/ubuntu/work/bpftrace/bpftrace/build_asan/../src/main.cpp:577:19
    #8 0x7fec4efa5b96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310
    #9 0x5c1e39 in _start (/home/ubuntu/work/bpftrace/bpftrace/build_asan/src/bpftrace+0x5c1e39)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /home/ubuntu/work/bpftrace/bpftrace/build_asan/../src/ast/semantic_analyser.cpp:1684:25 in bpftrace::ast::SemanticAnalyser::visit(bpftrace::ast::AttachPoint&)
==26761==ABORTING
```

This is because `ap.mode.size()` is zero (`ap.mode` is a empty string)
and `ap.mode.size() - 1` causes underflow (`size_t` is unsigned).

https://github.com/iovisor/bpftrace/blob/96b6eb83c93668fd1e54147c8e1929fedd571dac/src/ast/semantic_analyser.cpp#L1683-L1684

With this patch,

```
% sudo ./src/bpftrace -e 'w::0x10000000:8:: {}'
stdin:1:1-18: ERROR: watchpoint mode must be combination of (r,w,x)
w::0x10000000:8:: {}
~~~~~~~~~~~~~~~~
```
delphix-devops-bot pushed a commit that referenced this pull request Apr 17, 2020
Fix the following error.

```
% sudo ./src/bpftrace -e 'k:f { exit() ? 0 : 0 }'
AddressSanitizer:DEADLYSIGNAL
=================================================================
==14010==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x000000850854 bp 0x7fffffffa450 sp 0x7fffffffa180 T0)
==14010==The signal is caused by a READ memory access.
==14010==Hint: address points to the zero page.
    #0 0x850853 in bpftrace::ast::CodegenLLVM::visit(bpftrace::ast::Ternary&) /home/ubuntu/work/bpftrace/src/ast/codegen_llvm.cpp
    #1 0x861f29 in bpftrace::ast::CodegenLLVM::visit(bpftrace::ast::Probe&) /home/ubuntu/work/bpftrace/src/ast/codegen_llvm.cpp:1506:13
    #2 0x865256 in bpftrace::ast::CodegenLLVM::visit(bpftrace::ast::Program&) /home/ubuntu/work/bpftrace/src/ast/codegen_llvm.cpp:1597:12
    #3 0x86e34b in bpftrace::ast::CodegenLLVM::compile(bpftrace::DebugLevel, std::ostream&) /home/ubuntu/work/bpftrace/src/ast/codegen_llvm.cpp:2013:10
    #4 0x77623f in main /home/ubuntu/work/bpftrace/src/main.cpp:605:22
    #5 0x7fffee1451e2 in __libc_start_main /build/glibc-t7JzpG/glibc-2.30/csu/../csu/libc-start.c:308:16
    #6 0x4d1bcd in _start (/disk/work/bpftrace/build_san3/src/bpftrace+0x4d1bcd)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /home/ubuntu/work/bpftrace/src/ast/codegen_llvm.cpp in bpftrace::ast::CodegenLLVM::visit(bpftrace::ast::Ternary&)
==14010==ABORTING
```
delphix-devops-bot pushed a commit that referenced this pull request Apr 17, 2020
This prevents the error like the follwing:

```
% sudo ASAN_OPTIONS=detect_leaks=0 ./src/bpftrace -e 'BEGIN { @ = max(exit()); }'
AddressSanitizer:DEADLYSIGNAL
=================================================================
==25253==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x00000089e3dc bp 0x7fff0bf07270 sp 0x7fff0bf07270 T0)
==25253==The signal is caused by a READ memory access.
==25253==Hint: address points to the zero page.
    #0 0x89e3dc in llvm::Value::getType() const /usr/lib/llvm-10/include/llvm/IR/Value.h:246:34
    #1 0x89cd6e in llvm::IRBuilder<llvm::ConstantFolder, llvm::IRBuilderDefaultInserter>::CreateIntCast(llvm::Value*, llvm::Type*, bool, llvm::Twine const&) /usr/lib/llvm-10/include/llvm/IR/IRBuilder.h:2172:12
    #2 0x889ad5 in bpftrace::ast::CodegenLLVM::visit(bpftrace::ast::Call&) /home/ubuntu/work/bpftrace/bpftrace/src/ast/codegen_llvm.cpp:328:16
    #3 0x880160 in bpftrace::ast::Call::accept(bpftrace::ast::Visitor&) /home/ubuntu/work/bpftrace/bpftrace/src/ast/ast.cpp:129:5
    #4 0x8966c0 in bpftrace::ast::CodegenLLVM::visit(bpftrace::ast::AssignMapStatement&) /home/ubuntu/work/bpftrace/bpftrace/src/ast/codegen_llvm.cpp:1315:20
    #5 0x880fa3 in bpftrace::ast::AssignMapStatement::accept(bpftrace::ast::Visitor&) /home/ubuntu/work/bpftrace/bpftrace/src/ast/ast.cpp:284:5
    #6 0x897a70 in bpftrace::ast::CodegenLLVM::visit(bpftrace::ast::Probe&) /home/ubuntu/work/bpftrace/bpftrace/src/ast/codegen_llvm.cpp:1510:13
    #7 0x8815f3 in bpftrace::ast::Probe::accept(bpftrace::ast::Visitor&) /home/ubuntu/work/bpftrace/bpftrace/src/ast/ast.cpp:355:5
    #8 0x89895b in bpftrace::ast::CodegenLLVM::visit(bpftrace::ast::Program&) /home/ubuntu/work/bpftrace/bpftrace/src/ast/codegen_llvm.cpp:1601:12
    #9 0x8816a3 in bpftrace::ast::Program::accept(bpftrace::ast::Visitor&) /home/ubuntu/work/bpftrace/bpftrace/src/ast/ast.cpp:364:5
    #10 0x89b397 in bpftrace::ast::CodegenLLVM::compile(bpftrace::DebugLevel, std::ostream&) /home/ubuntu/work/bpftrace/bpftrace/src/ast/codegen_llvm.cpp:2019:10
    #11 0x813f3c in main /home/ubuntu/work/bpftrace/bpftrace/src/main.cpp:589:22
    #12 0x7f2794c4db96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310
    #13 0x5c64c9 in _start (/home/ubuntu/work/bpftrace/bpftrace/build_llvm10/src/bpftrace+0x5c64c9)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /usr/lib/llvm-10/include/llvm/IR/Value.h:246:34 in llvm::Value::getType() const
==25253==ABORTING
```
delphix-devops-bot pushed a commit that referenced this pull request Oct 22, 2020
The expr_ of a PositionalParameter is a pointer to a buffer, and an
offset can be added to it (e.g., `str($1 + 1)`). Cast expr_ to int so
that llvm does not complain about type mismatches when operating addition.

This fixes the following error reported by AddressSanitizer.

```
% sudo ./src/bpftrace -e 'BEGIN { printf("%s", str($1 + 1)); exit(); }' hello
AddressSanitizer:DEADLYSIGNAL
=================================================================
==3979==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000f8b (pc 0x7f1947a755ba bp 0x60700000def0 sp 0x7ffc07b486b0 T0)
==3979==The signal is caused by a READ memory access.
==3979==Hint: address points to the zero page.
    #0 0x7f1947a755ba in llvm::Constant::isNullValue() const (/usr/lib/x86_64-linux-gnu/libLLVM-10.so.1+0xa735ba)
    #1 0x7f1948826177 in llvm::LazyValueInfo::getPredicateAt(unsigned int, llvm::Value*, llvm::Constant*, llvm::Instruction*) (/usr/lib/x86_64-linux-gnu/libLLVM-10.so.1+0x1824177)
    #2 0x7f194841e4a8  (/usr/lib/x86_64-linux-gnu/libLLVM-10.so.1+0x141c4a8)
    #3 0x7f1948420049  (/usr/lib/x86_64-linux-gnu/libLLVM-10.so.1+0x141e049)
    #4 0x7f1947b13ed5 in llvm::FPPassManager::runOnFunction(llvm::Function&) (/usr/lib/x86_64-linux-gnu/libLLVM-10.so.1+0xb11ed5)
    #5 0x7f194879ca90  (/usr/lib/x86_64-linux-gnu/libLLVM-10.so.1+0x179aa90)
    #6 0x7f1947b145ff in llvm::legacy::PassManagerImpl::run(llvm::Module&) (/usr/lib/x86_64-linux-gnu/libLLVM-10.so.1+0xb125ff)
    #7 0x851bbe in bpftrace::ast::CodegenLLVM::optimize() /home/ubuntu/work/bpftrace/bpftrace/src/ast/codegen_llvm.cpp:2720:6
    #8 0x791416 in main /home/ubuntu/work/bpftrace/bpftrace/src/main.cpp:745:10
    #9 0x7f1945cc8b96 in __libc_start_main /build/glibc-2ORdQG/glibc-2.27/csu/../csu/libc-start.c:310
    #10 0x4d1c79 in _start (/home/ubuntu/work/bpftrace/bpftrace/build_dev/src/bpftrace+0x4d1c79)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/usr/lib/x86_64-linux-gnu/libLLVM-10.so.1+0xa735ba) in llvm::Constant::isNullValue() const
==3979==ABORTING
```
delphix-devops-bot pushed a commit that referenced this pull request Jan 14, 2021
I though #1572 fixes the issue of invalid tuple creation, but there is
another issue. libfuzzer found the following:

```
% sudo ./src/bpftrace -e 'BEGIN { (1, !(int1)1); }'
/disk/work/bpftrace2/src/struct.cpp:29:37: runtime error: division by zero
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /disk/work/bpftrace2/src/struct.cpp:29:37 in
AddressSanitizer:DEADLYSIGNAL
=================================================================
==46777==ERROR: AddressSanitizer: FPE on unknown address 0x00000000b6b9 (pc 0x0000009aa53c bp 0x7fffffff68d0 sp 0x7fffffff64a0 T0)
    #0 0x9aa53c in bpftrace::Tuple::Create(std::vector<bpftrace::SizedType, std::allocator<bpftrace::SizedType> >) /disk/work/bpftrace2/src/struct.cpp:29:37
    #1 0x9cb00a in bpftrace::CreateTuple(std::vector<bpftrace::SizedType, std::allocator<bpftrace::SizedType> > const&) /disk/work/bpftrace2/src/types.cpp:443:20
    #2 0xc9dd2c in bpftrace::ast::SemanticAnalyser::visit(bpftrace::ast::Tuple&) /disk/work/bpftrace2/src/ast/semantic_analyser.cpp:1994:16
    #3 0xa8048b in bpftrace::ast::Tuple::accept(bpftrace::ast::Visitor&) /disk/work/bpftrace2/src/ast/ast.cpp:31:1
    #4 0xc9e116 in bpftrace::ast::SemanticAnalyser::visit(bpftrace::ast::ExprStatement&) /disk/work/bpftrace2/src/ast/semantic_analyser.cpp:1999:14
    #5 0xa805eb in bpftrace::ast::ExprStatement::accept(bpftrace::ast::Visitor&) /disk/work/bpftrace2/src/ast/ast.cpp:32:1
    #6 0xcbb643 in bpftrace::ast::SemanticAnalyser::visit(bpftrace::ast::Probe&) /disk/work/bpftrace2/src/ast/semantic_analyser.cpp:2473:11
    #7 0xa8124b in bpftrace::ast::Probe::accept(bpftrace::ast::Visitor&) /disk/work/bpftrace2/src/ast/ast.cpp:41:1
    #8 0xcbb97d in bpftrace::ast::SemanticAnalyser::visit(bpftrace::ast::Program&) /disk/work/bpftrace2/src/ast/semantic_analyser.cpp:2481:12
    #9 0xa813ab in bpftrace::ast::Program::accept(bpftrace::ast::Visitor&) /disk/work/bpftrace2/src/ast/ast.cpp:42:1
    #10 0xcbbda0 in bpftrace::ast::SemanticAnalyser::analyse() /disk/work/bpftrace2/src/ast/semantic_analyser.cpp:2490:12
    #11 0xa474fa in main /disk/work/bpftrace2/src/main.cpp:738:19
    #12 0x7fffed57e0b2 in __libc_start_main /build/glibc-ZN95T4/glibc-2.31/csu/../csu/libc-start.c:308:16
    #13 0x4fe68d in _start (/disk/work/bpftrace2/build/src/bpftrace+0x4fe68d)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: FPE /disk/work/bpftrace2/src/struct.cpp:29:37 in bpftrace::Tuple::Create(std::vector<bpftrace::SizedType, std::allocator<bpftrace::SizedType> >)
==46777==ABORTING
```

In this case, `elem->type` is `int` because of `!`, but its size is zero
and that causes the problem. To fix issue, don't create tuple if an
elemenet size is zero.
delphix-devops-bot pushed a commit that referenced this pull request Jun 29, 2021
Not entirely sure why but for some reason the destructor deallocates
less bytes than it should:

```
==14571==ERROR: AddressSanitizer: new-delete-type-mismatch on 0x60b000003740 in thread T0:
  object passed to delete has wrong type:
  size of the allocated type:   112 bytes;
  size of the deallocated type: 104 bytes.

    #0 0x7f192d4879c8 in operator delete(void*, unsigned long) (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xe19c8)
    #1 0x5569f26b5c4c in std::default_delete<bpftrace::AttachedProbe>::operator()(bpftrace::AttachedProbe*) const /usr/include/c++/7/bits/unique_ptr.h:78
    #2 0x5569f26b1364 in std::unique_ptr<bpftrace::AttachedProbe, std::default_delete<bpftrace::AttachedProbe> >::~unique_ptr() (/home/vagrant/build/src/bpftrace+0xdd364)
    #3 0x5569f26acc41 in void std::_Destroy<std::unique_ptr<bpftrace::AttachedProbe, std::default_delete<bpftrace::AttachedProbe> > >(std::unique_ptr<bpftrace::AttachedProbe, std::default_delete<bpftrace::AttachedProbe> >*) (/home/vagrant/build/src/bpftrace+0xd8c41)
```

Removing the ifdef fixes is. Having the extra field won't hurt.

Fixes #1853
prakashsurya pushed a commit that referenced this pull request Nov 8, 2022
On older kernels that don't support BTF, BPFFeature::try_load causes a segfault
by passing in a NULL pointer to bpf_find_by_name_kind:

  Program received signal SIGSEGV, Segmentation fault.
  (gdb) bt
  #0  0x95101db8 in btf_find_by_name_kind (btf=0x0, start_id=1, [...])
  #1  0x0a74695e in bpftrace::BTF::get_btf_id
  #2  0x0a716fe8 in bpftrace::BPFfeature::try_load
  #3  0x0a717546 in bpftrace::BPFfeature::detect_prog_type
  #4  0x0a71963c in bpftrace::BPFfeature::has_prog_kfunc
  #5  0x0a7181e8 in bpftrace::BPFfeature::has_kfunc
  [...]
delphix-devops-bot pushed a commit that referenced this pull request Mar 13, 2023
The change now fixes an invalid typecast rather than variable assignment.

When CodegenLLVM::visit calls CreateStore() with NULL expr_ as parameter,
segfault is generated, for example:

  $ cat sample.bt
  #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
  ./sample.bt:4:11-26: ERROR: Cannot cast from "none" type
    $file = (struct file *)
            ~~~~~~~~~~~~~~~

LLVM/Clang Version: 15.0.1

Signed-off-by: Rong Tao <rongtao@cestc.cn>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

fix Ubuntu llvm/clang packages
2 participants