Martin KaFai Lau
5f4566498d
bpf: Fix narrow load on a bpf_sock returned from sk_lookup()
By adding this test to test_verifier:
{
"reference tracking: access sk->src_ip4 (narrow load)",
.insns = {
BPF_SK_LOOKUP,
BPF_MOV64_REG(BPF_REG_6, BPF_REG_0),
BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 3),
BPF_LDX_MEM(BPF_H, BPF_REG_2, BPF_REG_0, offsetof(struct bpf_sock, src_ip4) + 2),
BPF_MOV64_REG(BPF_REG_1, BPF_REG_6),
BPF_EMIT_CALL(BPF_FUNC_sk_release),
BPF_EXIT_INSN(),
},
.prog_type = BPF_PROG_TYPE_SCHED_CLS,
.result = ACCEPT,
},
The above test loads 2 bytes from sk->src_ip4 where
sk is obtained by bpf_sk_lookup_tcp().
It hits an internal verifier error from convert_ctx_accesses():
[root@arch-fb-vm1 bpf]# ./test_verifier 665 665
Failed to load prog 'Invalid argument'!
0: (b7) r2 = 0
1: (63) *(u32 *)(r10 -8) = r2
2: (7b) *(u64 *)(r10 -16) = r2
3: (7b) *(u64 *)(r10 -24) = r2
4: (7b) *(u64 *)(r10 -32) = r2
5: (7b) *(u64 *)(r10 -40) = r2
6: (7b) *(u64 *)(r10 -48) = r2
7: (bf) r2 = r10
8: (07) r2 += -48
9: (b7) r3 = 36
10: (b7) r4 = 0
11: (b7) r5 = 0
12: (85) call bpf_sk_lookup_tcp#84
13: (bf) r6 = r0
14: (15) if r0 == 0x0 goto pc+3
R0=sock(id=1,off=0,imm=0) R6=sock(id=1,off=0,imm=0) R10=fp0,call_-1 fp-8=????0000 fp-16=0000mmmm fp-24=mmmmmmmm fp-32=mmmmmmmm fp-40=mmmmmmmm fp-48=mmmmmmmm refs=1
15: (69) r2 = *(u16 *)(r0 +26)
16: (bf) r1 = r6
17: (85) call bpf_sk_release#86
18: (95) exit
from 14 to 18: safe
processed 20 insns (limit 131072), stack depth 48
bpf verifier is misconfigured
Summary: 0 PASSED, 0 SKIPPED, 1 FAILED
The bpf_sock_is_valid_access() is expecting src_ip4 can be narrowly
loaded (meaning load any 1 or 2 bytes of the src_ip4) by
marking info->ctx_field_size. However, this marked
ctx_field_size is not used. This patch fixes it.
Due to the recent refactoring in test_verifier,
this new test will be added to the bpf-next branch
(together with the bpf_tcp_sock patchset)
to avoid merge conflict.
Fixes: c64b798328
("bpf: Add PTR_TO_SOCKET verifier type")
Cc: Joe Stringer <joe@wand.net.nz>
Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Acked-by: Joe Stringer <joe@wand.net.nz>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-02-10 19:37:41 -08:00
..
2019-02-10 19:37:41 -08:00
2019-01-31 10:32:01 +01:00
2018-10-24 20:55:56 -04:00
2018-12-30 08:31:52 +00:00
2019-01-16 09:59:17 -05:00
2019-01-03 18:57:57 -08:00
2018-06-08 18:56:02 +09:00
2019-01-18 00:43:09 +01:00
2018-12-01 12:38:50 -08:00
2019-01-21 11:15:39 +01:00
2018-12-28 12:11:47 -08:00
2019-01-03 18:57:57 -08:00
2018-12-01 12:45:42 -08:00
2019-01-21 11:15:37 +01:00
2019-01-15 16:34:37 +01:00
2019-01-15 11:33:45 -05:00
2018-02-06 18:32:44 -08:00
2018-11-26 18:40:00 -05:00
2018-11-26 18:40:00 -05:00
2018-11-26 18:40:00 -05:00
2018-12-14 12:09:30 -05:00
2018-11-26 18:41:21 -05:00
2018-06-19 10:39:54 -04:00
2018-11-26 18:41:21 -05:00
2018-10-31 08:54:14 -07:00
2019-01-04 12:56:09 -08:00
2018-11-28 11:57:07 +01:00
2018-08-22 10:52:47 -07:00
2018-12-19 13:52:44 -05:00
2018-10-26 16:26:32 -07:00
2018-05-16 07:23:35 +02:00
2018-05-16 07:23:35 +02:00
2019-01-21 11:15:36 +01:00
2018-02-21 16:54:06 +01:00
2018-10-31 08:54:12 -07:00
2019-01-08 18:58:29 -08:00
2018-08-06 12:35:20 +02:00
2019-01-21 11:15:38 +01:00
2019-01-04 13:13:45 -08:00
2018-05-15 23:08:33 -07:00
2019-01-06 09:46:51 +09:00
2018-09-10 22:54:33 +09:00
2019-02-01 20:55:38 +01:00
2018-12-15 17:44:35 +09:00
2019-01-04 13:13:47 -08:00
2018-12-28 12:11:47 -08:00
2018-12-06 14:38:50 +00:00
2018-07-16 12:31:57 -07:00
2018-12-26 14:45:18 -08:00
2018-08-13 11:25:07 -07:00
2019-01-06 09:46:51 +09:00
2018-12-28 12:11:52 -08:00
2018-11-07 14:41:41 +01:00
2018-07-02 11:36:17 +02:00
2019-01-06 09:46:51 +09:00
2018-11-16 14:11:04 +08:00
2019-01-04 13:13:47 -08:00
2018-04-11 10:28:37 -07:00
2018-09-16 16:08:25 +02:00
2018-12-28 12:42:30 -08:00
2018-10-31 08:54:16 -07:00
2019-01-03 18:57:57 -08:00
2018-09-11 16:13:24 +01:00
2018-06-15 07:55:24 +09:00
2018-12-28 12:11:49 -08:00
2019-01-03 18:57:57 -08:00
2019-01-15 09:43:12 -08:00
2019-01-03 18:57:57 -08:00
2018-10-09 16:51:11 +02:00
2018-07-03 09:20:44 +02:00
2018-10-25 11:43:47 -07:00
2018-12-05 19:31:44 -08:00
2018-08-13 11:25:07 -07:00
2018-12-18 16:13:04 +01:00
2019-01-14 10:38:03 +12:00
2019-01-04 13:13:47 -08:00
2019-01-04 13:13:47 -08:00
2018-02-06 18:32:46 -08:00
2018-06-21 12:33:05 +02:00
2018-12-01 12:45:35 -08:00
2018-11-27 09:21:41 -08: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
2019-01-11 18:05:40 -08:00
2018-10-09 16:51:11 +02:00
2018-11-07 23:51:16 -06: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
2018-08-30 12:56:40 +02:00
2018-05-18 08:47:13 -07:00
2018-11-27 09:21:44 -08:00