Martin KaFai Lau
d623876646
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-09 19:57:22 -08:00 |
| .. |
|
bpf
|
bpf: Fix narrow load on a bpf_sock returned from sk_lookup()
|
2019-02-09 19:57:22 -08:00 |
|
cgroup
|
Merge branch 'for-4.21' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup
|
2018-12-29 10:57:20 -08:00 |
|
configs
|
kvm_config: add CONFIG_VIRTIO_MENU
|
2018-10-24 20:55:56 -04:00 |
|
debug
|
kdb: use bool for binary state indicators
|
2018-12-30 08:31:52 +00:00 |
|
dma
|
swiotlb: clear io_tlb_start and io_tlb_end in swiotlb_exit
|
2019-01-16 09:59:17 -05:00 |
|
events
|
perf core: Fix perf_proc_update_handler() bug
|
2019-01-18 11:10:38 -03:00 |
|
gcov
|
|
|
|
irq
|
genirq/irqdesc: Fix double increment in alloc_descs()
|
2019-01-18 00:43:09 +01:00 |
|
livepatch
|
livepatch: Replace synchronize_sched() with synchronize_rcu()
|
2018-12-01 12:38:50 -08:00 |
|
locking
|
locking/rwsem: Fix (possible) missed wakeup
|
2019-01-21 11:15:39 +01:00 |
|
power
|
mm: convert totalram_pages and totalhigh_pages variables to atomic
|
2018-12-28 12:11:47 -08:00 |
|
printk
|
Remove 'type' argument from access_ok() function
|
2019-01-03 18:57:57 -08:00 |
|
rcu
|
rcutorture: Don't do busted forward-progress testing
|
2018-12-01 12:45:42 -08:00 |
|
sched
|
Merge branch 'smp-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
|
2019-02-03 09:02:03 -08:00 |
|
time
|
posix-cpu-timers: Unbreak timer rearming
|
2019-01-15 16:34:37 +01:00 |
|
trace
|
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
|
2019-02-08 11:21:54 -08:00 |
|
.gitignore
|
|
|
|
acct.c
|
|
|
|
async.c
|
|
|
|
audit.c
|
audit: remove duplicated include from audit.c
|
2018-12-14 12:09:30 -05:00 |
|
audit.h
|
audit: use current whenever possible
|
2018-11-26 18:41:21 -05:00 |
|
audit_fsnotify.c
|
audit: minimize our use of audit_log_format()
|
2018-11-26 18:40:00 -05:00 |
|
audit_tree.c
|
audit: minimize our use of audit_log_format()
|
2018-11-26 18:40:00 -05:00 |
|
audit_watch.c
|
audit: minimize our use of audit_log_format()
|
2018-11-26 18:40:00 -05:00 |
|
auditfilter.c
|
|
|
|
auditsc.c
|
audit: use current whenever possible
|
2018-11-26 18:41:21 -05:00 |
|
backtracetest.c
|
|
|
|
bounds.c
|
kbuild: fix kernel/bounds.c 'W=1' warning
|
2018-10-31 08:54:14 -07:00 |
|
capability.c
|
|
|
|
compat.c
|
make 'user_access_begin()' do 'access_ok()'
|
2019-01-04 12:56:09 -08:00 |
|
configs.c
|
|
|
|
context_tracking.c
|
|
|
|
cpu.c
|
cpu/hotplug: Fix "SMT disabled by BIOS" detection for KVM
|
2019-01-30 19:27:00 +01:00 |
|
cpu_pm.c
|
|
|
|
crash_core.c
|
|
|
|
crash_dump.c
|
|
|
|
cred.c
|
cred: export get_task_cred().
|
2018-12-19 13:52:44 -05:00 |
|
delayacct.c
|
delayacct: track delays from thrashing cache pages
|
2018-10-26 16:26:32 -07:00 |
|
dma.c
|
|
|
|
elfcore.c
|
|
|
|
exec_domain.c
|
|
|
|
exit.c
|
kernel/exit.c: release ptraced tasks before zap_pid_ns_processes
|
2019-02-01 15:46:23 -08:00 |
|
extable.c
|
|
|
|
fail_function.c
|
kernel/fail_function.c: remove meaningless null pointer check before debugfs_remove_recursive
|
2018-10-31 08:54:12 -07:00 |
|
fork.c
|
Merge branch 'akpm' (patches from Andrew)
|
2019-01-08 18:58:29 -08:00 |
|
freezer.c
|
|
|
|
futex.c
|
futex: Fix (possible) missed wakeup
|
2019-01-21 11:15:38 +01:00 |
|
groups.c
|
|
|
|
hung_task.c
|
kernel/hung_task.c: break RCU locks based on jiffies
|
2019-01-04 13:13:45 -08:00 |
|
iomem.c
|
|
|
|
irq_work.c
|
|
|
|
jump_label.c
|
jump_label: move 'asm goto' support test to Kconfig
|
2019-01-06 09:46:51 +09:00 |
|
kallsyms.c
|
kallsyms: reduce size a little on 64-bit
|
2018-09-10 22:54:33 +09:00 |
|
kcmp.c
|
|
|
|
Kconfig.freezer
|
|
|
|
Kconfig.hz
|
|
|
|
Kconfig.locks
|
|
|
|
Kconfig.preempt
|
kconfig: warn no new line at end of file
|
2018-12-15 17:44:35 +09:00 |
|
kcov.c
|
kernel/kcov.c: mark write_comp_data() as notrace
|
2019-01-04 13:13:47 -08:00 |
|
kexec.c
|
|
|
|
kexec_core.c
|
mm: convert totalram_pages and totalhigh_pages variables to atomic
|
2018-12-28 12:11:47 -08:00 |
|
kexec_file.c
|
kexec_file: kexec_walk_memblock() only walks a dedicated region at kdump
|
2018-12-06 14:38:50 +00:00 |
|
kexec_internal.h
|
|
|
|
kmod.c
|
|
|
|
kprobes.c
|
Merge branch 'perf-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
|
2018-12-26 14:45:18 -08:00 |
|
ksysfs.c
|
|
|
|
kthread.c
|
|
|
|
latencytop.c
|
|
|
|
Makefile
|
kbuild: change filechk to surround the given command with { }
|
2019-01-06 09:46:51 +09:00 |
|
memremap.c
|
mm/hmm: fix memremap.h, move dev_page_fault_t callback to hmm
|
2018-12-28 12:11:52 -08:00 |
|
module-internal.h
|
|
|
|
module.c
|
jump_label: move 'asm goto' support test to Kconfig
|
2019-01-06 09:46:51 +09:00 |
|
module_signing.c
|
modsign: use all trusted keys to verify module signature
|
2018-11-07 14:41:41 +01:00 |
|
notifier.c
|
|
|
|
nsproxy.c
|
|
|
|
padata.c
|
padata: clean an indentation issue, remove extraneous space
|
2018-11-16 14:11:04 +08:00 |
|
panic.c
|
kernel/sysctl: add panic_print into sysctl
|
2019-01-04 13:13:47 -08:00 |
|
params.c
|
|
|
|
pid.c
|
Fix failure path in alloc_pid()
|
2018-12-28 12:42:30 -08:00 |
|
pid_namespace.c
|
signal: Use group_send_sig_info to kill all processes in a pid namespace
|
2018-09-16 16:08:25 +02:00 |
|
profile.c
|
mm: remove include/linux/bootmem.h
|
2018-10-31 08:54:16 -07:00 |
|
ptrace.c
|
Remove 'type' argument from access_ok() function
|
2019-01-03 18:57:57 -08:00 |
|
range.c
|
|
|
|
reboot.c
|
kernel/reboot.c: export pm_power_off_prepare
|
2018-09-11 16:13:24 +01:00 |
|
relay.c
|
relay: check return of create_buf_file() properly
|
2019-01-31 14:01:48 +01:00 |
|
resource.c
|
kernel, resource: check for IORESOURCE_SYSRAM in release_mem_region_adjustable
|
2018-12-28 12:11:49 -08:00 |
|
rseq.c
|
Remove 'type' argument from access_ok() function
|
2019-01-03 18:57:57 -08:00 |
|
seccomp.c
|
seccomp: fix UAF in user-trap code
|
2019-01-15 09:43:12 -08:00 |
|
signal.c
|
Remove 'type' argument from access_ok() function
|
2019-01-03 18:57:57 -08:00 |
|
smp.c
|
cpu/hotplug: Fix "SMT disabled by BIOS" detection for KVM
|
2019-01-30 19:27:00 +01:00 |
|
smpboot.c
|
|
|
|
smpboot.h
|
|
|
|
softirq.c
|
Merge branch 'irq-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
|
2018-10-25 11:43:47 -07:00 |
|
stackleak.c
|
stackleak: Mark stackleak_track_stack() as notrace
|
2018-12-05 19:31:44 -08:00 |
|
stacktrace.c
|
|
|
|
stop_machine.c
|
|
|
|
sys.c
|
kernel/sys.c: Clarify that UNAME26 does not generate unique versions anymore
|
2019-01-14 10:38:03 +12:00 |
|
sys_ni.c
|
y2038: socket: Add compat_sys_recvmmsg_time64
|
2018-12-18 16:13:04 +01:00 |
|
sysctl.c
|
kernel/sysctl: add panic_print into sysctl
|
2019-01-04 13:13:47 -08:00 |
|
sysctl_binary.c
|
kernel/sysctl: add panic_print into sysctl
|
2019-01-04 13:13:47 -08:00 |
|
task_work.c
|
|
|
|
taskstats.c
|
|
|
|
test_kprobes.c
|
|
|
|
torture.c
|
torture: Remove unnecessary "ret" variables
|
2018-12-01 12:45:35 -08:00 |
|
tracepoint.c
|
tracing: Replace synchronize_sched() and call_rcu_sched()
|
2018-11-27 09:21:41 -08:00 |
|
tsacct.c
|
|
|
|
ucount.c
|
|
|
|
uid16.c
|
|
|
|
uid16.h
|
|
|
|
umh.c
|
umh: add exit routine for UMH process
|
2019-01-11 18:05:40 -08:00 |
|
up.c
|
smp,cpumask: introduce on_each_cpu_cond_mask
|
2018-10-09 16:51:11 +02:00 |
|
user-return-notifier.c
|
|
|
|
user.c
|
|
|
|
user_namespace.c
|
userns: also map extents in the reverse map to kernel IDs
|
2018-11-07 23:51:16 -06:00 |
|
utsname.c
|
|
|
|
utsname_sysctl.c
|
|
|
|
watchdog.c
|
watchdog: Mark watchdog touch functions as notrace
|
2018-08-30 12:56:40 +02:00 |
|
watchdog_hld.c
|
watchdog: Mark watchdog touch functions as notrace
|
2018-08-30 12:56:40 +02:00 |
|
workqueue.c
|
psi: fix aggregation idle shut-off
|
2019-02-01 15:46:23 -08:00 |
|
workqueue_internal.h
|
psi: fix aggregation idle shut-off
|
2019-02-01 15:46:23 -08:00 |