bpf: Tweak definition of KF_TRUSTED_ARGS
authorKumar Kartikeya Dwivedi <memxor@gmail.com>
Wed, 21 Sep 2022 16:48:25 +0000 (18:48 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 22 Sep 2022 02:25:26 +0000 (19:25 -0700)
commiteed807f626101f6a4227bd53942892c5983b95a7
treee58e1a0d241a69b2f9df907253064e18427730b4
parent1d8b82c613297f24354b4d750413a7456b5cd92c
bpf: Tweak definition of KF_TRUSTED_ARGS

Instead of forcing all arguments to be referenced pointers with non-zero
reg->ref_obj_id, tweak the definition of KF_TRUSTED_ARGS to mean that
only PTR_TO_BTF_ID (and socket types translated to PTR_TO_BTF_ID) have
that constraint, and require their offset to be set to 0.

The rest of pointer types are also accomodated in this definition of
trusted pointers, but with more relaxed rules regarding offsets.

The inherent meaning of setting this flag is that all kfunc pointer
arguments have a guranteed lifetime, and kernel object pointers
(PTR_TO_BTF_ID, PTR_TO_CTX) are passed in their unmodified form (with
offset 0). In general, this is not true for PTR_TO_BTF_ID as it can be
obtained using pointer walks.

Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Link: https://lore.kernel.org/r/cdede0043c47ed7a357f0a915d16f9ce06a1d589.1663778601.git.lorenzo@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Documentation/bpf/kfuncs.rst
kernel/bpf/btf.c