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 doublefree 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 -c, --command=COMMAND Execute the command and detect doublefree -p, --pid=PID Detect doublefree on the specified process -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 test.cpp #include <chrono> #include <thread> void bar(int* a) { delete a; } int* foo() { return new int; } int main() { std::this_thread::sleep_for(std::chrono::seconds(1)); auto a = foo(); bar(a); bar(a); } $ g++ test.cpp $ sudo ./doublefree -c a.out 2024-May-02 14:30:54 INFO Execute command: a.out(pid 70054) Tracing doublefree... Hit Ctrl-C to stop free(): double free detected in tcache 2 Allocation: iovisor#1 0x007148a02ae98c _Znwm+0x1c (/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.30+0xae98c) iovisor#2 0x0056166a14924c main+0x46 (/home/bojun/doublefree/libbpf-tools/a.out+0x124c) iovisor#3 0x0071489fe29d90 [unknown] (/usr/lib/x86_64-linux-gnu/libc.so.6+0x29d90) First deallocation: iovisor#1 0x0071489fea53e0 free+0x0 (/usr/lib/x86_64-linux-gnu/libc.so.6+0xa53e0) iovisor#2 0x0056166a14925c main+0x56 (/home/bojun/doublefree/libbpf-tools/a.out+0x125c) iovisor#3 0x0071489fe29d90 [unknown] (/usr/lib/x86_64-linux-gnu/libc.so.6+0x29d90) Second deallocation: iovisor#1 0x0071489fea53e0 free+0x0 (/usr/lib/x86_64-linux-gnu/libc.so.6+0xa53e0) iovisor#2 0x0056166a149268 main+0x62 (/home/bojun/doublefree/libbpf-tools/a.out+0x1268) iovisor#3 0x0071489fe29d90 [unknown] (/usr/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
- Loading branch information