]> git.baikalelectronics.ru Git - kernel.git/commit
samples/bpf: Add test/example of using bpf_probe_write_user bpf helper
authorSargun Dhillon <sargun@sargun.me>
Mon, 25 Jul 2016 12:55:02 +0000 (05:55 -0700)
committerDavid S. Miller <davem@davemloft.net>
Tue, 26 Jul 2016 01:07:48 +0000 (18:07 -0700)
commit118c2b71cc14a64b5e5e426afd08985f73ae8727
tree17cb747b81a9fce3a7052efc639bbb83488df191
parent046d6594bbf1c945b840dfe6aa2c49b98a56862d
samples/bpf: Add test/example of using bpf_probe_write_user bpf helper

This example shows using a kprobe to act as a dnat mechanism to divert
traffic for arbitrary endpoints. It rewrite the arguments to a syscall
while they're still in userspace, and before the syscall has a chance
to copy the argument into kernel space.

Although this is an example, it also acts as a test because the mapped
address is 255.255.255.255:555 -> real address, and that's not a legal
address to connect to. If the helper is broken, the example will fail
on the intermediate steps, as well as the final step to verify the
rewrite of userspace memory succeeded.

Signed-off-by: Sargun Dhillon <sargun@sargun.me>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
samples/bpf/Makefile
samples/bpf/test_probe_write_user_kern.c [new file with mode: 0644]
samples/bpf/test_probe_write_user_user.c [new file with mode: 0644]