]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
bpf: Allow helpers to accept pointers with a fixed size
authorMaxim Mikityanskiy <maximmi@nvidia.com>
Wed, 15 Jun 2022 13:48:43 +0000 (16:48 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 8 Sep 2022 09:23:58 +0000 (11:23 +0200)
commit840fbb6845abb5cecb0dbf417c8d265a7e791b03
tree77a356b51575d25aa8b355e4499260e36232c5ae
parentcdbaf57293f0a2b4ad1faa1ebe7dbefd5e519cf9
bpf: Allow helpers to accept pointers with a fixed size

[ Upstream commit 508362ac66b0478affb4e52cb8da98478312d72d ]

Before this commit, the BPF verifier required ARG_PTR_TO_MEM arguments
to be followed by ARG_CONST_SIZE holding the size of the memory region.
The helpers had to check that size in runtime.

There are cases where the size expected by a helper is a compile-time
constant. Checking it in runtime is an unnecessary overhead and waste of
BPF registers.

This commit allows helpers to accept pointers to memory without the
corresponding ARG_CONST_SIZE, given that they define the memory region
size in struct bpf_func_proto and use ARG_PTR_TO_FIXED_SIZE_MEM type.

arg_size is unionized with arg_btf_id to reduce the kernel image size,
and it's valid because they are used by different argument types.

Signed-off-by: Maxim Mikityanskiy <maximmi@nvidia.com>
Reviewed-by: Tariq Toukan <tariqt@nvidia.com>
Link: https://lore.kernel.org/r/20220615134847.3753567-3-maximmi@nvidia.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
include/linux/bpf.h
kernel/bpf/verifier.c