summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/bpf/progs/struct_ops_arena_member_fail__write.c
blob: ff0761980948d3b4e66d2dac3487c85db5dc921f (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
// 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_arena_common.h>
#include "bpf_misc.h"
#include "../test_kmods/bpf_testmod.h"

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

struct {
	__uint(type, BPF_MAP_TYPE_ARENA);
	__uint(map_flags, BPF_F_MMAPABLE);
	__uint(max_entries, 1);
} arena SEC(".maps");

/*
 * The kernel owns the member, a program only reads it. A struct_ops program
 * cannot store through its arguments at all, so the store is refused before
 * the tag comes into play; the exchange test reaches the arena member check.
 */
SEC("struct_ops/test_arena_member")
__failure __msg("only read is supported")
int BPF_PROG(write_member, struct bpf_testmod_arena_member_args *args)
{
	asm volatile("" :: "r"(&arena));
	args->ptr = NULL;
	return 0;
}

SEC(".struct_ops.link")
struct bpf_testmod_ops3 testmod_arena_member_fail = {
	.test_arena_member = (void *)write_member,
};