bpf, lsm: Add check for BPF LSM return value
authorXu Kuohai <xukuohai@huawei.com>
Fri, 19 Jul 2024 11:00:52 +0000 (19:00 +0800)
committerAndrii Nakryiko <andrii@kernel.org>
Mon, 29 Jul 2024 20:09:22 +0000 (13:09 -0700)
commit5d99e198be279045e6ecefe220f5c52f8ce9bfd5
tree006d24765b0fd8fdff944e4924a2f75149f78471
parent21c7063f6d08ab9afa088584939791bee0c177e5
bpf, lsm: Add check for BPF LSM return value

A bpf prog returning a positive number attached to file_alloc_security
hook makes kernel panic.

This happens because file system can not filter out the positive number
returned by the LSM prog using IS_ERR, and misinterprets this positive
number as a file pointer.

Given that hook file_alloc_security never returned positive number
before the introduction of BPF LSM, and other BPF LSM hooks may
encounter similar issues, this patch adds LSM return value check
in verifier, to ensure no unexpected value is returned.

Fixes: 520b7aa00d8c ("bpf: lsm: Initialize the BPF LSM hooks")
Reported-by: Xin Liu <liuxin350@huawei.com>
Signed-off-by: Xu Kuohai <xukuohai@huawei.com>
Acked-by: Eduard Zingerman <eddyz87@gmail.com>
Link: https://lore.kernel.org/r/20240719110059.797546-3-xukuohai@huaweicloud.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
include/linux/bpf.h
include/linux/bpf_lsm.h
kernel/bpf/bpf_lsm.c
kernel/bpf/btf.c
kernel/bpf/verifier.c