I wrote a kernel module that sends generic Netlink multicasts, and wrote a userland client using libmnl that receives them.
That all works fine, but my client works even when it's not the root user, and I want to prevent that.
man 7 netlink says:
Only processes with an effective UID of 0 or the CAP_NET_ADMIN capability
may send or listen to a netlink multicast group.
Obviously the listen part of this is not true. I've tried CentOS 5 (2.6.18), CentOS 6 (2.6.32) and Ubuntu 14.04 (3.13).
I know that restricting receiving generic netlink commands incoming to the kernel to being only from root is possible with GENL_ADMIN_PERM flag, but is it possible to send multicasts from the kernel that can only be received by root?
EDIT: I shared some code for a kernel module that sends netlink multicasts, and client that receives them, at https://github.com/craig65535/mcast-exmpl. Build instructions are in the README.md, but I'll paste them here.
In one terminal:
$ make
$ sudo insmod mcast-exmpl.ko
$ cd client
$ make
$ ./client
genl ctrl msg
Family ID: 26
Mcast group ID: 4
(IDs may be different)
In another terminal, run a command that will do a TCP connect. mcast-exmpl hooks connects via a jprobe, so doing this will cause it to send a netlink multicast.
$ nc yahoo.com 80
^C
$
In the first terminal, you'll see a netlink multicast was received, even if you did not run client as root:
mcast-exmpl msg
SEND_NUM 55555
I'd like to modify this so the multicasts are only received when client
is running as root, or, failing that, confirmation that I've found a bug either in the Linux documentation or Linux itself.