linux-stable/kernel/bpf
Stanislav Fomichev 2b41b7e9f3 bpf: Don't EFAULT for getsockopt with optval=NULL
[ Upstream commit 00e74ae086 ]

Some socket options do getsockopt with optval=NULL to estimate the size
of the final buffer (which is returned via optlen). This breaks BPF
getsockopt assumptions about permitted optval buffer size. Let's enforce
these assumptions only when non-NULL optval is provided.

Fixes: 0d01da6afc ("bpf: implement getsockopt and setsockopt hooks")
Reported-by: Martin KaFai Lau <martin.lau@kernel.org>
Signed-off-by: Stanislav Fomichev <sdf@google.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/ZD7Js4fj5YyI2oLd@google.com/T/#mb68daf700f87a9244a15d01d00c3f0e5b08f49f7
Link: https://lore.kernel.org/bpf/20230418225343.553806-2-sdf@google.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-05-11 23:11:18 +09:00
..
preload bpf: iterators: Build and use lightweight bootstrap version of bpftool 2022-07-15 12:01:30 -07:00
arraymap.c bpf: return long from bpf_map_ops funcs 2023-05-11 23:11:09 +09:00
bloom_filter.c bpf: return long from bpf_map_ops funcs 2023-05-11 23:11:09 +09:00
bpf_cgrp_storage.c bpf: return long from bpf_map_ops funcs 2023-05-11 23:11:09 +09:00
bpf_inode_storage.c bpf: return long from bpf_map_ops funcs 2023-05-11 23:11:09 +09:00
bpf_iter.c bpf: Initialize the bpf_run_ctx in bpf_iter_run_prog() 2022-08-18 17:06:13 -07:00
bpf_local_storage.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2022-11-29 13:04:52 -08:00
bpf_lru_list.c bpf_lru_list: Read double-checked variable once without lock 2021-02-10 15:54:26 -08:00
bpf_lru_list.h printk: stop including cache.h from printk.h 2022-05-13 07:20:07 -07:00
bpf_lsm.c bpf: Fix the kernel crash caused by bpf_setsockopt(). 2023-01-26 23:26:40 -08:00
bpf_struct_ops.c bpf: return long from bpf_map_ops funcs 2023-05-11 23:11:09 +09:00
bpf_struct_ops_types.h bpf: Add dummy BPF STRUCT_OPS for test purpose 2021-11-01 14:10:00 -07:00
bpf_task_storage.c bpf: return long from bpf_map_ops funcs 2023-05-11 23:11:09 +09:00
btf.c bpf: Fix race between btf_put and btf_idr walk. 2023-05-11 23:11:18 +09:00
cgroup.c bpf: Don't EFAULT for getsockopt with optval=NULL 2023-05-11 23:11:18 +09:00
cgroup_iter.c bpf: Pin the start cgroup in cgroup_iter_seq_init() 2022-11-21 17:40:42 +01:00
core.c bpf: Adjust insufficient default bpf_jit_limit 2023-03-30 12:51:19 +02:00
cpumap.c bpf: return long from bpf_map_ops funcs 2023-05-11 23:11:09 +09:00
devmap.c bpf: return long from bpf_map_ops funcs 2023-05-11 23:11:09 +09:00
disasm.c bpf: Relicense disassembler as GPL-2.0-only OR BSD-2-Clause 2021-09-02 14:49:23 +02:00
disasm.h bpf: Relicense disassembler as GPL-2.0-only OR BSD-2-Clause 2021-09-02 14:49:23 +02:00
dispatcher.c bpf: Synchronize dispatcher update with bpf_dispatcher_xdp_func 2022-12-14 12:02:14 -08:00
hashtab.c bpf: return long from bpf_map_ops funcs 2023-05-11 23:11:09 +09:00
helpers.c bpf: Add bpf_rbtree_{add,remove,first} kfuncs 2023-05-11 23:11:11 +09:00
inode.c bpf: Convert bpf_preload.ko to use light skeleton. 2022-02-10 23:31:51 +01:00
Kconfig rcu: Make the TASKS_RCU Kconfig option be selected 2022-04-20 16:52:58 -07:00
link_iter.c bpf: Add bpf_link iterator 2022-05-10 11:20:45 -07:00
local_storage.c bpf: return long from bpf_map_ops funcs 2023-05-11 23:11:09 +09:00
lpm_trie.c bpf: return long from bpf_map_ops funcs 2023-05-11 23:11:09 +09:00
Makefile bpf: Implement cgroup storage available to non-cgroup-attached bpf progs 2022-10-25 23:19:19 -07:00
map_in_map.c bpf: Add comments for map BTF matching requirement for bpf_list_head 2022-11-17 19:22:14 -08:00
map_in_map.h
map_iter.c bpf: Introduce MEM_RDONLY flag 2021-12-18 13:27:41 -08:00
memalloc.c bpf: Zeroing allocated object from slab in bpf memory allocator 2023-03-10 09:28:22 +01:00
mmap_unlock_work.h bpf: Introduce helper bpf_find_vma 2021-11-07 11:54:51 -08:00
net_namespace.c net: Add includes masked by netdevice.h including uapi/bpf.h 2021-12-29 20:03:05 -08:00
offload.c bpf: restore the ebpf program ID for BPF_AUDIT_UNLOAD and PERF_BPF_EVENT_PROG_UNLOAD 2023-01-09 19:47:58 -08:00
percpu_freelist.c bpf: Initialize same number of free nodes for each pcpu_freelist 2022-11-11 12:05:14 -08:00
percpu_freelist.h
prog_iter.c
queue_stack_maps.c bpf: return long from bpf_map_ops funcs 2023-05-11 23:11:09 +09:00
reuseport_array.c bpf: return long from bpf_map_ops funcs 2023-05-11 23:11:09 +09:00
ringbuf.c bpf: return long from bpf_map_ops funcs 2023-05-11 23:11:09 +09:00
stackmap.c bpf: return long from bpf_map_ops funcs 2023-05-11 23:11:09 +09:00
syscall.c bpf: Add basic bpf_rb_{root,node} support 2023-05-11 23:11:11 +09:00
sysfs_btf.c
task_iter.c bpf: keep a reference to the mm, in case the task is dead. 2022-12-28 14:11:48 -08:00
tnum.c bpf, tnums: Provably sound, faster, and more precise algorithm for tnum_mul 2021-06-01 13:34:15 +02:00
trampoline.c bpf: Fix panic due to wrong pageattr of im->image 2022-12-28 13:46:28 -08:00
verifier.c bpf: Fix struct_meta lookup for bpf_obj_free_fields kfunc call 2023-05-11 23:11:12 +09:00