bpf: fix null pointer deref in bpf_prog_test_run_xdp
authorDaniel Borkmann <daniel@iogearbox.net>
Wed, 31 Jan 2018 11:58:56 +0000 (12:58 +0100)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 1 Feb 2018 15:43:56 +0000 (07:43 -0800)
commit65073a67331de3d2cce35607807ddec284e75e81
treeaa39697a25f7b47548ca227b13d866558c9b98ce
parent62a06994ced17f295fc51ea0815580ee7ccb668d
bpf: fix null pointer deref in bpf_prog_test_run_xdp

syzkaller was able to generate the following XDP program ...

  (18) r0 = 0x0
  (61) r5 = *(u32 *)(r1 +12)
  (04) (u32) r0 += (u32) 0
  (95) exit

... and trigger a NULL pointer dereference in ___bpf_prog_run()
via bpf_prog_test_run_xdp() where this was attempted to run.

Reason is that recent xdp_rxq_info addition to XDP programs
updated all drivers, but not bpf_prog_test_run_xdp(), where
xdp_buff is set up. Thus when context rewriter does the deref
on the netdev it's NULL at runtime. Fix it by using xdp_rxq
from loopback dev. __netif_get_rx_queue() helper can also be
reused in various other locations later on.

Fixes: 02dd3291b2f0 ("bpf: finally expose xdp_rxq_info to XDP bpf-programs")
Reported-by: syzbot+1eb094057b338eb1fc00@syzkaller.appspotmail.com
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Cc: Jesper Dangaard Brouer <brouer@redhat.com>
Acked-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
include/linux/netdevice.h
net/bpf/test_run.c
tools/testing/selftests/bpf/test_verifier.c