mirror of
https://github.com/netdata/libbpf.git
synced 2026-04-06 00:29:07 +08:00
bpf: Add dynptr data slices
This patch adds a new helper function void *bpf_dynptr_data(struct bpf_dynptr *ptr, u32 offset, u32 len); which returns a pointer to the underlying data of a dynptr. *len* must be a statically known value. The bpf program may access the returned data slice as a normal buffer (eg can do direct reads and writes), since the verifier associates the length with the returned pointer, and enforces that no out of bounds accesses occur. Signed-off-by: Joanne Koong <joannelkoong@gmail.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Acked-by: Yonghong Song <yhs@fb.com> Link: https://lore.kernel.org/bpf/20220523210712.3641569-6-joannelkoong@gmail.com
This commit is contained in:
committed by
Andrii Nakryiko
parent
7ed5bf8f4c
commit
f035838503
@@ -5238,6 +5238,17 @@ union bpf_attr {
|
|||||||
* 0 on success, -E2BIG if *offset* + *len* exceeds the length
|
* 0 on success, -E2BIG if *offset* + *len* exceeds the length
|
||||||
* of *dst*'s data, -EINVAL if *dst* is an invalid dynptr or if *dst*
|
* of *dst*'s data, -EINVAL if *dst* is an invalid dynptr or if *dst*
|
||||||
* is a read-only dynptr.
|
* is a read-only dynptr.
|
||||||
|
*
|
||||||
|
* void *bpf_dynptr_data(struct bpf_dynptr *ptr, u32 offset, u32 len)
|
||||||
|
* Description
|
||||||
|
* Get a pointer to the underlying dynptr data.
|
||||||
|
*
|
||||||
|
* *len* must be a statically known value. The returned data slice
|
||||||
|
* is invalidated whenever the dynptr is invalidated.
|
||||||
|
* Return
|
||||||
|
* Pointer to the underlying dynptr data, NULL if the dynptr is
|
||||||
|
* read-only, if the dynptr is invalid, or if the offset and length
|
||||||
|
* is out of bounds.
|
||||||
*/
|
*/
|
||||||
#define __BPF_FUNC_MAPPER(FN) \
|
#define __BPF_FUNC_MAPPER(FN) \
|
||||||
FN(unspec), \
|
FN(unspec), \
|
||||||
@@ -5443,6 +5454,7 @@ union bpf_attr {
|
|||||||
FN(ringbuf_discard_dynptr), \
|
FN(ringbuf_discard_dynptr), \
|
||||||
FN(dynptr_read), \
|
FN(dynptr_read), \
|
||||||
FN(dynptr_write), \
|
FN(dynptr_write), \
|
||||||
|
FN(dynptr_data), \
|
||||||
/* */
|
/* */
|
||||||
|
|
||||||
/* integer value in 'imm' field of BPF_CALL instruction selects which helper
|
/* integer value in 'imm' field of BPF_CALL instruction selects which helper
|
||||||
|
|||||||
Reference in New Issue
Block a user