Daniel Borkmann
f70280ee89
bpf: Fix passing modified ctx to ld/abs/ind instruction
...
commit 6d4f151acf9a4f6fab09b615f246c717ddedcf0c upstream.
Anatoly has been fuzzing with kBdysch harness and reported a KASAN
slab oob in one of the outcomes:
[...]
[ 77.359642] BUG: KASAN: slab-out-of-bounds in bpf_skb_load_helper_8_no_cache+0x71/0x130
[ 77.360463] Read of size 4 at addr ffff8880679bac68 by task bpf/406
[ 77.361119]
[ 77.361289] CPU: 2 PID: 406 Comm: bpf Not tainted 5.5.0-rc2-xfstests-00157-g2187f215eba #1
[ 77.362134] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.12.0-1 04/01/2014
[ 77.362984] Call Trace:
[ 77.363249] dump_stack+0x97/0xe0
[ 77.363603] print_address_description.constprop.0+0x1d/0x220
[ 77.364251] ? bpf_skb_load_helper_8_no_cache+0x71/0x130
[ 77.365030] ? bpf_skb_load_helper_8_no_cache+0x71/0x130
[ 77.365860] __kasan_report.cold+0x37/0x7b
[ 77.366365] ? bpf_skb_load_helper_8_no_cache+0x71/0x130
[ 77.366940] kasan_report+0xe/0x20
[ 77.367295] bpf_skb_load_helper_8_no_cache+0x71/0x130
[ 77.367821] ? bpf_skb_load_helper_8+0xf0/0xf0
[ 77.368278] ? mark_lock+0xa3/0x9b0
[ 77.368641] ? kvm_sched_clock_read+0x14/0x30
[ 77.369096] ? sched_clock+0x5/0x10
[ 77.369460] ? sched_clock_cpu+0x18/0x110
[ 77.369876] ? bpf_skb_load_helper_8+0xf0/0xf0
[ 77.370330] ___bpf_prog_run+0x16c0/0x28f0
[ 77.370755] __bpf_prog_run32+0x83/0xc0
[ 77.371153] ? __bpf_prog_run64+0xc0/0xc0
[ 77.371568] ? match_held_lock+0x1b/0x230
[ 77.371984] ? rcu_read_lock_held+0xa1/0xb0
[ 77.372416] ? rcu_is_watching+0x34/0x50
[ 77.372826] sk_filter_trim_cap+0x17c/0x4d0
[ 77.373259] ? sock_kzfree_s+0x40/0x40
[ 77.373648] ? __get_filter+0x150/0x150
[ 77.374059] ? skb_copy_datagram_from_iter+0x80/0x280
[ 77.374581] ? do_raw_spin_unlock+0xa5/0x140
[ 77.375025] unix_dgram_sendmsg+0x33a/0xa70
[ 77.375459] ? do_raw_spin_lock+0x1d0/0x1d0
[ 77.375893] ? unix_peer_get+0xa0/0xa0
[ 77.376287] ? __fget_light+0xa4/0xf0
[ 77.376670] __sys_sendto+0x265/0x280
[ 77.377056] ? __ia32_sys_getpeername+0x50/0x50
[ 77.377523] ? lock_downgrade+0x350/0x350
[ 77.377940] ? __sys_setsockopt+0x2a6/0x2c0
[ 77.378374] ? sock_read_iter+0x240/0x240
[ 77.378789] ? __sys_socketpair+0x22a/0x300
[ 77.379221] ? __ia32_sys_socket+0x50/0x50
[ 77.379649] ? mark_held_locks+0x1d/0x90
[ 77.380059] ? trace_hardirqs_on_thunk+0x1a/0x1c
[ 77.380536] __x64_sys_sendto+0x74/0x90
[ 77.380938] do_syscall_64+0x68/0x2a0
[ 77.381324] entry_SYSCALL_64_after_hwframe+0x49/0xbe
[ 77.381878] RIP: 0033:0x44c070
[...]
After further debugging, turns out while in case of other helper functions
we disallow passing modified ctx, the special case of ld/abs/ind instruction
which has similar semantics (except r6 being the ctx argument) is missing
such check. Modified ctx is impossible here as bpf_skb_load_helper_8_no_cache()
and others are expecting skb fields in original position, hence, add
check_ctx_reg() to reject any modified ctx. Issue was first introduced back
in f1174f77b50c ("bpf/verifier: rework value tracking").
Fixes: f1174f77b50c ("bpf/verifier: rework value tracking")
Reported-by: Anatoly Trosinenko <anatoly.trosinenko@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20200106215157.3553-1-daniel@iogearbox.net
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-01-12 12:17:04 +01:00
..
2020-01-12 12:17:04 +01:00
2019-12-17 20:34:56 +01:00
2018-06-15 07:15:28 +09:00
2019-02-12 19:47:19 +01:00
2020-01-04 19:12:43 +01:00
2019-12-13 08:51:04 +01:00
2018-06-08 18:56:02 +09:00
2019-12-01 09:17:13 +01:00
2019-10-07 18:57:10 +02:00
2019-10-11 18:21:06 +02:00
2020-01-09 10:18:58 +01:00
2019-12-01 09:16:14 +01:00
2019-05-31 06:46:30 -07:00
2019-12-31 16:36:22 +01:00
2020-01-04 19:13:35 +01:00
2020-01-09 10:19:03 +01:00
2019-05-31 06:46:05 -07:00
2018-02-06 18:32:44 -08:00
2018-05-18 14:58:22 +02:00
2019-12-13 08:51:11 +01:00
2019-12-13 08:51:02 +01:00
2018-07-17 14:45:08 -04:00
2018-02-23 11:22:22 -05:00
2019-05-31 06:46:17 -07:00
2019-12-01 09:17:17 +01:00
2018-11-13 11:08:47 -08:00
2017-11-02 11:10:55 +01:00
2018-06-24 14:39:47 +02:00
2019-11-24 08:20:18 +01:00
2018-08-22 10:52:47 -07:00
2020-01-09 10:19:00 +01:00
2018-04-27 14:34:51 +02:00
2018-05-16 07:23:35 +02:00
2019-10-11 18:21:23 +02:00
2018-05-16 07:23:35 +02:00
2020-01-09 10:19:02 +01:00
2018-02-21 16:54:06 +01:00
2018-06-21 12:33:19 +02:00
2019-12-05 09:21:04 +01:00
2018-08-06 12:35:20 +02:00
2019-12-01 09:17:38 +01:00
2017-12-14 16:00:49 -08:00
2019-04-20 09:16:02 +02:00
2018-05-15 23:08:33 -07:00
2019-05-31 06:46:19 -07:00
2019-06-04 08:02:34 +02:00
2019-09-21 07:17:02 +02:00
2017-11-02 11:10:55 +01:00
2018-08-02 08:06:54 +09:00
2019-02-12 19:47:20 +01:00
2019-11-24 08:20:29 +01:00
2018-06-12 16:19:22 -07:00
2017-11-02 11:10:55 +01:00
2018-07-16 12:31:57 -07:00
2019-12-05 09:20:26 +01:00
2018-08-13 11:25:07 -07:00
2019-12-01 09:17:38 +01:00
2019-01-13 09:51:04 +01:00
2018-07-02 11:36:17 +02:00
2018-07-02 11:36:17 +02:00
2019-12-17 20:35:57 +01:00
2019-07-26 09:14:25 +02:00
2019-12-01 09:17:10 +01:00
2018-04-11 10:28:37 -07:00
2019-07-26 09:14:01 +02:00
2019-01-13 09:51:06 +01:00
2019-07-10 09:53:41 +02:00
2017-11-02 11:10:55 +01:00
2018-08-06 12:35:20 +02:00
2019-03-13 14:02:35 -07:00
2019-09-16 08:22:20 +02:00
2018-07-10 22:18:52 +02:00
2018-06-06 16:34:00 -07:00
2019-11-20 18:46:21 +01:00
2019-02-12 19:47:25 +01:00
2018-07-03 09:20:44 +02:00
2017-11-02 11:10:55 +01:00
2018-08-03 15:52:10 +02:00
2018-08-13 11:25:07 -07:00
2018-06-10 10:17:09 -07:00
2019-06-15 11:54:01 +02:00
2018-04-16 11:26:49 +02:00
2020-01-04 19:13:17 +01:00
2017-12-17 13:57:15 +01:00
2020-01-09 10:18:59 +01:00
2018-06-21 12:33:05 +02:00
2018-06-25 11:30:10 -07:00
2018-10-17 15:35:29 -04:00
2018-04-05 21:36:27 -07:00
2018-04-02 20:15:59 +02:00
2018-04-02 20:15:30 +02:00
2018-06-07 16:56:28 -04:00
2018-11-13 11:09:00 -08:00
2018-08-22 10:52:47 -07:00
2018-08-11 02:05:53 -05:00
2018-04-11 10:28:35 -07:00
2018-08-30 12:56:40 +02:00
2019-04-03 06:26:29 +02:00
2018-05-18 08:47:13 -07:00
2019-12-17 20:35:50 +01:00