summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/bpf/progs/verifier_mem_size_reg.c
blob: 7e24706a764e9c537f067b3f376d85751a9d9745 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// SPDX-License-Identifier: GPL-2.0

#include <vmlinux.h>
#include <bpf/bpf_helpers.h>
#include "bpf_misc.h"
#include "bpf_kfuncs.h"

char _license[] SEC("license") = "GPL";

/*
 * The __szk size of a kfunc memory/size pair must be marked precise even when
 * the nullable buffer is passed as NULL.
 */
SEC("?tc")
__success __log_level(2)
__msg("mark_precise: frame0: regs=r4 stack= before")
int dynptr_slice_null_buf_size_precise(struct __sk_buff *skb)
{
	struct bpf_dynptr dptr;
	char *p;

	bpf_dynptr_from_skb(skb, 0, &dptr);

	p = bpf_dynptr_slice(&dptr, 0, NULL, 8);
	if (p)
		return p[0];
	return 0;
}