Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
libbpf-tools: Add new feature doublefree
Add doublefree tool to detect double free. It could detect user level double free error currently and can be expanded to detect kernel level double free error. Followings are the usage and example. Usage: $ ./doublefree -h Usage: doublefree [OPTION...] Detect and report double free error. -c or -p is a mandatory option EXAMPLES: doublefree -p 1234 # Detect doublefree on process id 1234 doublefree -c a.out # Detect doublefree on a.out doublefree -c 'a.out arg' # Detect doublefree on a.out with argument doublefree -c "a.out arg" # Detect doublefree on a.out with argument -c, --command=COMMAND Execute and trace the specified command -p, --pid=PID Set pid -v, --verbose Verbose debug output -?, --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. Example: $ cat doublefree_generator.c #include <unistd.h> #include <stdlib.h> int* foo() { return (int*)malloc(sizeof(int)); } void bar(int* p) { free(p); } int main(int argc, char* argv[]) { sleep(10); int *val = foo(); *val = 33; bar(val); *val = 84; bar(val); return 0; } $ gcc doublefree_generator.c $ sudo ./doublefree -c a.out 2024-Jan-25 13:19:32 INFO Execute child process: a.out 2024-Jan-25 13:19:32 INFO execute command: a.out(pid 108346) Tracing doublefree... Hit Ctrl-C to stop free(): double free detected in tcache 2 Allocation: iovisor#1 0x0055f7b647f19b foo+0x12 iovisor#2 0x0055f7b647f1e3 main+0x27 iovisor#3 0x007f0ae6e29d90 First deallocation: iovisor#1 0x007f0ae6ea53e0 free+0 iovisor#2 0x0055f7b647f1fd main+0x41 iovisor#3 0x007f0ae6e29d90 Second deallocation: iovisor#1 0x007f0ae6ea53e0 free+0 iovisor#2 0x0055f7b647f213 main+0x57 iovisor#3 0x007f0ae6e29d90 ^C2024-Jan-25 13:19:32 ERROR Failed to poll perf_buffer $
- Loading branch information