I am debugging a program that makes use of libnetfilter_queue
. The documentation states that a userspace queue-handling application needs the CAP_NET_ADMIN
capability to function. I have done this using the setcap
utility as follows:
$ sudo setcap cap_net_raw,cap_net_admin=eip ./a.out
I have verified that the capabilities are applied correctly as a) the program works and b) getcap
returns the following output:
$ getcap ./a.out
./a.out = cap_net_admin,cap_net_raw+eip
However, when I attempt to debug this program using gdb
(e.g. $ gdb ./a.out
) from the command line, it fails on account of not having the correct permissions set. The debugging functionality of gdb
works perfectly otherwise and debugs as per normal.
I have even attempted to apply these capabilities to the gdb
binary itself to no avail. I did this as it seemed (as documented by the manpages that the "i
" flag might allowed the debugee to inherit the capability from the debugger.
Is there something trivial I am missing or can this really not be done?
To exit GDB, use the quit command (abbreviated q ), or type an end-of-file character (usually C-d ). If you do not supply expression , GDB will terminate normally; otherwise it will terminate using the result of expression as the error code.
To stop your program while it is running, type "(ctrl) + c" (hold down the ctrl key and press c). gdb will stop your program at whatever line it has just executed. From here you can examine variables and move through your program.
Setting a New Breakpoint c file listed in Example 7.1, “Compiling a C Program With Debugging Information” with debugging information, you can set a new breakpoint at line 10 by running the following command: (gdb) break 10 Breakpoint 1 at 0x4004e5: file fibonacci. c, line 10.
I run into same problem and at beginning I thought the same as above that maybe gdb is ignoring the executable's capability due to security reason. However, reading source code and even using eclipse debugging gdb itself when it is debugging my ext2fs-prog which opens /dev/sda1
, I realize that:
/bin/bash
in my case.So, the solution is very simple, apart from adding cap_net_admin,cap_net_raw+eip
to gdb, you have also apply this to your shell. i.e. setcap cap_net_admin,cap_net_raw+eip /bin/bash
The reason that you have also to do this to gdb is because gdb is parent process of /bin/bash
before create debugged process.
The true executable command line inside gdb is like following:
/bin/bash exec /my/executable/program/path
And this is parameter to vfork inside gdb.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With