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

libbpf-tools: Add new feature ALSan #4120

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Commits on Aug 27, 2024

  1. libbpf-tools: Add submodule c-vector

    Add submodule c-vector
    https://github.com/eteran/c-vector
    
    This project is header only library project that contains interfaces
    and implementations of vector container which can be used in C
    The license of this project is MIT
    Bojun-Seo committed Aug 27, 2024
    Configuration menu
    Copy the full SHA
    72d78b7 View commit details
    Browse the repository at this point in the history
  2. libbpf-tools: Add submodule uthash

    Add submodule uthash
    https://github.com/troydhanson/uthash
    
    This project is header only library project that contains interfaces
    and implementations of hash map container which can be used in C
    The license is written on the top of the file uthash.h
    Bojun-Seo committed Aug 27, 2024
    Configuration menu
    Copy the full SHA
    76c6266 View commit details
    Browse the repository at this point in the history
  3. libbpf-tools: Add new feature ALSan on libbpf-tools

    Add ALSan(Attachable Leak Sanitizer) feature on libbpf-tools
    ALSan feature originally comes from the llvm-project lsan
    https://github.com/llvm/llvm-project
    This tool detect and report unreachable memory periodically
    
    USAGE:
    
      $ ./alsan -h
      Usage: alsan [OPTION...]
      Detect memory leak resulting from unreachable pointers.
    
      Either -c or -p is a mandatory option
      EXAMPLES:
          alsan -p 1234             # Detect leaks on process id 1234
          alsan -c a.out            # Detect leaks on a.out
          alsan -c 'a.out arg'      # Detect leaks on a.out with argument
    
        -c, --command=COMMAND      Execute and detect memory leak on the specified
                                   command
        -i, --interval=INTERVAL    Set interval in second to detect leak
        -p, --pid=PID              Detect memory leak on the specified process
        -s, --suppressions=SUPPRESSIONS
                                   Suppressions file name
        -T, --top=TOP              Report only specified amount of backtraces
        -v, --verbose              Verbose debug output
        -w, --stop-the-world       Stop the target process during tracing
        -?, --help                 Give this help list
            --usage                Give a short usage message
        -V, --version              Print program version
    
      Mandatory or optional arguments to long options are also mandatory or optional
      for any corresponding short options.
    
      Report bugs to https://github.com/iovisor/bcc/tree/master/libbpf-tools.
    
    Report example:
    
      $ sudo ./alsan -p 28346
    
      [2024-05-22 14:44:58] Print leaks:
      44 bytes direct leak found in 1 allocations from stack id(57214)
              iovisor#1 0x00583bca1b2250 baz+0x1c (/home/bojun/alsan/libbpf-tools/a.out+0x1250)
              iovisor#2 0x00583bca1b22d7 main+0x73 (/home/bojun/alsan/libbpf-tools/a.out+0x12d7)
              iovisor#3 0x007470c7c2a1ca [unknown] (/usr/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
              iovisor#4 0x007470c7c2a28b __libc_start_main+0x8b (/usr/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
              iovisor#5 0x00583bca1b2105 _start+0x25 (/home/bojun/alsan/libbpf-tools/a.out+0x1105)
    
      [2024-05-22 14:45:08] Print leaks:
      132 bytes direct leak found in 3 allocations from stack id(57214)
              iovisor#1 0x00583bca1b2250 baz+0x1c (/home/bojun/alsan/libbpf-tools/a.out+0x1250)
              iovisor#2 0x00583bca1b22d7 main+0x73 (/home/bojun/alsan/libbpf-tools/a.out+0x12d7)
              iovisor#3 0x007470c7c2a1ca [unknown] (/usr/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
              iovisor#4 0x007470c7c2a28b __libc_start_main+0x8b (/usr/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
              iovisor#5 0x00583bca1b2105 _start+0x25 (/home/bojun/alsan/libbpf-tools/a.out+0x1105)
    
    Source code of test program:
    
      $ cat leak_test.c
      #include <stdlib.h>
      #include <unistd.h>
    
      int *arr[10000];
    
      int *foo(size_t size) {
              int *tmp = malloc(size);
              *tmp = 99;
              return tmp;
      }
    
      int *bar(size_t nmemb, size_t size) {
              int *tmp = calloc(nmemb, size);
              *tmp = 22;
              return tmp;
      }
    
      int *baz(size_t size) {
              int *tmp = valloc(size);
              *tmp = 11;
              return tmp;
      }
    
      int main(int argc, char* argv[]) {
              int *a;
              int i = 0;
              while (1) {
                      a = foo(4);
                      arr[i++] = a;
                      a = bar(4, 4);
                      free(a);
                      a = baz(44);
                      sleep(5);
              }
              return 0;
      }
    Bojun-Seo committed Aug 27, 2024
    Configuration menu
    Copy the full SHA
    cedf232 View commit details
    Browse the repository at this point in the history