Eyal Birger
9ef33d23f8
bpf, lwt: Fix crash when using bpf_skb_set_tunnel_key() from bpf_xmit lwt hook
[ Upstream commit b02d196c44ead1a5949729be9ff08fe781c3e48a ]
xmit_check_hhlen() observes the dst for getting the device hard header
length to make sure a modified packet can fit. When a helper which changes
the dst - such as bpf_skb_set_tunnel_key() - is called as part of the
xmit program the accessed dst is no longer valid.
This leads to the following splat:
BUG: kernel NULL pointer dereference, address: 00000000000000de
#PF: supervisor read access in kernel mode
#PF: error_code(0x0000) - not-present page
PGD 0 P4D 0
Oops: 0000 [#1] PREEMPT SMP PTI
CPU: 0 PID: 798 Comm: ping Not tainted 5.18.0-rc2+ #103
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.14.0-2 04/01/2014
RIP: 0010:bpf_xmit+0xfb/0x17f
Code: c6 c0 4d cd 8e 48 c7 c7 7d 33 f0 8e e8 42 09 fb ff 48 8b 45 58 48 8b 95 c8 00 00 00 48 2b 95 c0 00 00 00 48 83 e0 fe 48 8b 00 <0f> b7 80 de 00 00 00 39 c2 73 22 29 d0 b9 20 0a 00 00 31 d2 48 89
RSP: 0018:ffffb148c0bc7b98 EFLAGS: 00010282
RAX: 0000000000000000 RBX: 0000000000240008 RCX: 0000000000000000
RDX: 0000000000000010 RSI: 00000000ffffffea RDI: 00000000ffffffff
RBP: ffff922a828a4e00 R08: ffffffff8f1350e8 R09: 00000000ffffdfff
R10: ffffffff8f055100 R11: ffffffff8f105100 R12: 0000000000000000
R13: ffff922a828a4e00 R14: 0000000000000040 R15: 0000000000000000
FS: 00007f414e8f0080(0000) GS:ffff922afdc00000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00000000000000de CR3: 0000000002d80006 CR4: 0000000000370ef0
Call Trace:
<TASK>
lwtunnel_xmit.cold+0x71/0xc8
ip_finish_output2+0x279/0x520
? __ip_finish_output.part.0+0x21/0x130
Fix by fetching the device hard header length before running the BPF code.
Fixes: 3a0af8fd61
("bpf: BPF for lightweight tunnel infrastructure")
Signed-off-by: Eyal Birger <eyal.birger@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20220420165219.1755407-1-eyal.birger@gmail.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-05-09 09:05:02 +02:00
..
2020-09-25 13:58:01 -07:00
2021-02-17 11:02:28 +01:00
2019-03-27 13:49:44 -07:00
2020-09-28 15:00:15 -07:00
2021-03-07 12:34:07 +01:00
2022-01-27 10:54:30 +01:00
2022-01-27 10:54:34 +01:00
2022-02-23 12:01:02 +01:00
2021-12-08 09:03:22 +01:00
2021-03-30 14:32:05 +02:00
2019-04-10 22:12:26 -07:00
2019-10-04 11:10:56 -07:00
2021-12-08 09:03:21 +01:00
2022-04-13 21:01:06 +02:00
2022-04-20 09:23:11 +02:00
2021-09-18 13:40:30 +02:00
2021-01-27 11:55:23 +01:00
2020-04-28 14:39:46 -07:00
2020-11-25 11:28:12 -08:00
2019-06-09 19:40:10 -07:00
2021-08-18 08:59:13 +02:00
2022-05-09 09:05:02 +02:00
2022-01-11 15:25:00 +01:00
2019-12-12 17:07:05 -08:00
2021-12-14 11:32:43 +01:00
2022-01-27 10:54:33 +01:00
2022-02-01 17:25:44 +01:00
2022-03-16 14:16:00 +01:00
2020-02-26 20:07:25 -08:00
2019-06-19 11:23:13 -04:00
2020-04-21 15:44:30 -07:00
2019-05-30 11:26:32 -07:00
2020-11-18 11:04:11 -08:00
2020-05-09 20:59:21 -07:00
2021-05-19 10:13:17 +02:00
2021-03-07 12:34:09 +01:00
2020-08-19 16:07:49 -07:00
2019-10-13 10:13:08 -07:00
2022-04-13 21:01:00 +02:00
2020-07-13 11:03:44 -07:00
2020-05-08 15:32:17 +10:00
2022-03-08 19:09:32 +01:00
2022-04-08 14:40:21 +02:00
2020-09-30 11:50:35 -07:00
2021-12-17 10:14:41 +01:00
2021-01-23 16:03:59 +01:00
2021-11-26 10:39:14 +01:00
2021-11-18 14:04:08 +01:00
2021-11-18 14:03:42 +01:00
2019-12-25 19:51:33 -08:00
2020-06-18 20:46:23 -07:00
2020-01-24 20:54:30 +01:00
2021-04-14 08:42:09 +02:00