mirror of
https://github.com/torvalds/linux.git
synced 2026-07-27 17:47:41 +02:00
selftests/bpf: Test creating dynptr from dynptr data and slice
The verifier currently does not allow creating dynptr from dynptr data or slice. Add a selftest to test this explicitly. Signed-off-by: Amery Hung <ameryhung@gmail.com> Link: https://lore.kernel.org/r/20260529014936.2811085-11-ameryhung@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
parent
2eee6fe8ac
commit
fbcc68af60
|
|
@ -705,6 +705,48 @@ int dynptr_from_mem_invalid_api(void *ctx)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* Cannot create dynptr from dynptr data */
|
||||
SEC("?raw_tp")
|
||||
__failure __msg("Unsupported reg type mem for bpf_dynptr_from_mem data")
|
||||
int dynptr_from_dynptr_data(void *ctx)
|
||||
{
|
||||
struct bpf_dynptr ptr, ptr2;
|
||||
__u8 *data;
|
||||
|
||||
if (get_map_val_dynptr(&ptr))
|
||||
return 0;
|
||||
|
||||
data = bpf_dynptr_data(&ptr, 0, sizeof(__u32));
|
||||
if (!data)
|
||||
return 0;
|
||||
|
||||
/* this should fail */
|
||||
bpf_dynptr_from_mem(data, sizeof(__u32), 0, &ptr2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Cannot create dynptr from dynptr slice */
|
||||
SEC("?tc")
|
||||
__failure __msg("Unsupported reg type mem for bpf_dynptr_from_mem data")
|
||||
int dynptr_from_dynptr_slice(struct __sk_buff *skb)
|
||||
{
|
||||
struct bpf_dynptr ptr, ptr2;
|
||||
struct ethhdr *hdr;
|
||||
char buffer[sizeof(*hdr)] = {};
|
||||
|
||||
bpf_dynptr_from_skb(skb, 0, &ptr);
|
||||
|
||||
hdr = bpf_dynptr_slice_rdwr(&ptr, 0, buffer, sizeof(buffer));
|
||||
if (!hdr)
|
||||
return SK_DROP;
|
||||
|
||||
/* this should fail */
|
||||
bpf_dynptr_from_mem(hdr, sizeof(*hdr), 0, &ptr2);
|
||||
|
||||
return SK_PASS;
|
||||
}
|
||||
|
||||
SEC("?tc")
|
||||
__failure __msg("cannot overwrite referenced dynptr") __log_level(2)
|
||||
int dynptr_pruning_overwrite(struct __sk_buff *ctx)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user