summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/bpf/progs/struct_ops_nullable_probed__untrusted.c
blob: 9619991398411ac0dd5cee9824e0700bc77dd078 (plain) (blame)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2026 Meta Platforms, Inc. and affiliates. */

#include <vmlinux.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
#include "bpf_misc.h"
#include "../test_kmods/bpf_testmod.h"

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

struct untrusted_val {
	struct bpf_testmod_nullable_args __kptr_untrusted *args;
};

struct {
	__uint(type, BPF_MAP_TYPE_ARRAY);
	__uint(max_entries, 1);
	__type(key, int);
	__type(value, struct untrusted_val);
} untrusted_map SEC(".maps");

/*
 * Through an untrusted pointer the member is probed, which tolerates NULL, so
 * the tag asks for no check there.
 */
SEC("struct_ops/test_nullable")
__success
int BPF_PROG(unchecked_untrusted, struct bpf_testmod_nullable_args *args)
{
	struct bpf_testmod_nullable_args *u;
	struct untrusted_val *v;
	int zero = 0;

	v = bpf_map_lookup_elem(&untrusted_map, &zero);
	u = v ? v->args : NULL;
	if (!u)
		return 0;
	return u->task_or_null->pid;
}

SEC(".struct_ops.link")
struct bpf_testmod_ops3 testmod_nullable_probed = {
	.test_nullable = (void *)unchecked_untrusted,
};