bpf: Add bpf_dynptr_adjust
authorJoanne Koong <joannelkoong@gmail.com>
Thu, 20 Apr 2023 07:14:10 +0000 (00:14 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Thu, 27 Apr 2023 08:40:31 +0000 (10:40 +0200)
commit987d0242d189661f78b77cc4d77f843b15600fed
tree9362e9a4f66781fee9add0e84bcc6e3309775dc7
parent6e98b09da931a00bf4e0477d0fa52748bf28fcce
bpf: Add bpf_dynptr_adjust

Add a new kfunc

int bpf_dynptr_adjust(struct bpf_dynptr_kern *ptr, u32 start, u32 end);

which adjusts the dynptr to reflect the new [start, end) interval.
In particular, it advances the offset of the dynptr by "start" bytes,
and if end is less than the size of the dynptr, then this will trim the
dynptr accordingly.

Adjusting the dynptr interval may be useful in certain situations.
For example, when hashing which takes in generic dynptrs, if the dynptr
points to a struct but only a certain memory region inside the struct
should be hashed, adjust can be used to narrow in on the
specific region to hash.

Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20230420071414.570108-2-joannelkoong@gmail.com
kernel/bpf/helpers.c