Commit 3473249
committed
bpf-tools: Add new feature(leaksanitizer) on BPF CO-RE
Add leaksanitizer(lsan) feature on BPF CO-RE
lsan feature originally comes from llvm-project
https://github.com/llvm/llvm-project
cvector.h comes from c-vector project
https://github.com/eteran/c-vector
uthash.h comes from uthash project
https://github.com/troydhanson/uthash
This tool detect and report dangling pointers periodically
Usage: lsan [OPTION...]
Detect memory leak resulting from dangling pointers.
Either -c or -p is a mandatory option
EXAMPLES:
lsan -p 1234 # Detect leaks on process id 1234
lsan -c a.out # Detect leaks on a.out
lsan -c 'a.out arg' # Detect leaks on a.out with argument
lsan -c "a.out arg" # Detect leaks on a.out with argument
-c, --command=COMMAND Execute and trace the specified command
-i, --interval=INTERVAL Set interval in second to detect leak
-p, --pid=PID Set pid
-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 world 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 example:
$ sudo ./lsan -c a.out -s suppr.txt
Info: Execute child process: a.out
Info: execute command: a.out(pid 8335)
[2022-07-19 16:07:26] Print leaks:
Could not open [uprobes]
4 bytes direct leak found in 1 allocations from stack id(19863)
#1 0x00564465ed71bf foo
#2 0x00564465ed721b main
#3 0x007fc0a33f7d90 __libc_init_first
[2022-07-19 16:07:36] Print leaks:
8 bytes direct leak found in 2 allocations from stack id(19863)
#1 0x00564465ed71bf foo
#2 0x00564465ed721b main
#3 0x007fc0a33f7d90 __libc_init_first
[2022-07-19 16:07:46] Print leaks:
12 bytes direct leak found in 3 allocations from stack id(19863)
#1 0x00564465ed71bf foo
#2 0x00564465ed721b main
#3 0x007fc0a33f7d90 __libc_init_first
Source code of test program:
\#include <stdio.h>
\#include <stdlib.h>
\#include <unistd.h>
int* foo() {
int *tmp = malloc(sizeof(int));
*tmp = 99;
return tmp;
}
int* bar() {
int *tmp = malloc(sizeof(int));
*tmp = 22;
return tmp;
}
int main() {
int *a = NULL;
while (1) {
a = foo();
printf("%d\n", *a);
a = bar();
free(a);
sleep(10);
}
}1 parent 9a5a22b commit 3473249
6 files changed
Lines changed: 2953 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
0 commit comments