bpf/test_run: fix unkillable BPF_PROG_TEST_RUN
authorStanislav Fomichev <sdf@google.com>
Tue, 12 Feb 2019 23:42:38 +0000 (15:42 -0800)
committerDaniel Borkmann <daniel@iogearbox.net>
Mon, 18 Feb 2019 23:17:03 +0000 (00:17 +0100)
commitdf1a2cb7c74b3d3abc8d8c2d690f82c8ebc3490a
tree21336c0eca9c46abc9ad23bbd9813663dd120522
parent21d2cb491b9e10bfdf10424673b43cd9eddc2da1
bpf/test_run: fix unkillable BPF_PROG_TEST_RUN

Syzbot found out that running BPF_PROG_TEST_RUN with repeat=0xffffffff
makes process unkillable. The problem is that when CONFIG_PREEMPT is
enabled, we never see need_resched() return true. This is due to the
fact that preempt_enable() (which we do in bpf_test_run_one on each
iteration) now handles resched if it's needed.

Let's disable preemption for the whole run, not per test. In this case
we can properly see whether resched is needed.
Let's also properly return -EINTR to the userspace in case of a signal
interrupt.

See recent discussion:
http://lore.kernel.org/netdev/CAH3MdRWHr4N8jei8jxDppXjmw-Nw=puNDLbu1dQOFQHxfU2onA@mail.gmail.com

I'll follow up with the same fix bpf_prog_test_run_flow_dissector in
bpf-next.

Reported-by: syzbot <syzkaller@googlegroups.com>
Signed-off-by: Stanislav Fomichev <sdf@google.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
net/bpf/test_run.c