Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bpf: Add the missing BPF_LINK_TYPE invocation for sockmap

There is an out-of-bounds read in bpf_link_show_fdinfo() for the sockmap
link fd. Fix it by adding the missing BPF_LINK_TYPE invocation for
sockmap link

Also add comments for bpf_link_type to prevent missing updates in the
future.

Fixes: 699c23f02c65 ("bpf: Add bpf_link support for sk_msg and sk_skb progs")
Signed-off-by: Hou Tao <houtao1@huawei.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20241024013558.1135167-2-houtao@huaweicloud.com

authored by

Hou Tao and committed by
Andrii Nakryiko
c2f80305 9806f283

+7
+1
include/linux/bpf_types.h
··· 146 146 BPF_LINK_TYPE(BPF_LINK_TYPE_NETFILTER, netfilter) 147 147 BPF_LINK_TYPE(BPF_LINK_TYPE_TCX, tcx) 148 148 BPF_LINK_TYPE(BPF_LINK_TYPE_NETKIT, netkit) 149 + BPF_LINK_TYPE(BPF_LINK_TYPE_SOCKMAP, sockmap) 149 150 #endif 150 151 #ifdef CONFIG_PERF_EVENTS 151 152 BPF_LINK_TYPE(BPF_LINK_TYPE_PERF_EVENT, perf)
+3
include/uapi/linux/bpf.h
··· 1121 1121 1122 1122 #define MAX_BPF_ATTACH_TYPE __MAX_BPF_ATTACH_TYPE 1123 1123 1124 + /* Add BPF_LINK_TYPE(type, name) in bpf_types.h to keep bpf_link_type_strs[] 1125 + * in sync with the definitions below. 1126 + */ 1124 1127 enum bpf_link_type { 1125 1128 BPF_LINK_TYPE_UNSPEC = 0, 1126 1129 BPF_LINK_TYPE_RAW_TRACEPOINT = 1,
+3
tools/include/uapi/linux/bpf.h
··· 1121 1121 1122 1122 #define MAX_BPF_ATTACH_TYPE __MAX_BPF_ATTACH_TYPE 1123 1123 1124 + /* Add BPF_LINK_TYPE(type, name) in bpf_types.h to keep bpf_link_type_strs[] 1125 + * in sync with the definitions below. 1126 + */ 1124 1127 enum bpf_link_type { 1125 1128 BPF_LINK_TYPE_UNSPEC = 0, 1126 1129 BPF_LINK_TYPE_RAW_TRACEPOINT = 1,