1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */
5 #include <bpf/bpf_helpers.h>
6 #include <bpf/bpf_tracing.h>
8 #include "bpf_experimental.h"
9 #include "bpf_arena_common.h"
11 #define ARENA_SIZE (1ull << 32)
14 __uint(type, BPF_MAP_TYPE_ARENA);
15 __uint(map_flags, BPF_F_MMAPABLE);
16 __uint(max_entries, ARENA_SIZE / PAGE_SIZE);
21 int big_alloc1(void *ctx)
23 #if defined(__BPF_FEATURE_ADDR_SPACE_CAST)
24 volatile char __arena *page1, *page2, *no_page, *page3;
27 page1 = base = bpf_arena_alloc_pages(&arena, NULL, 1, NUMA_NO_NODE, 0);
31 page2 = bpf_arena_alloc_pages(&arena, base + ARENA_SIZE - PAGE_SIZE,
36 no_page = bpf_arena_alloc_pages(&arena, base + ARENA_SIZE,
44 bpf_arena_free_pages(&arena, (void __arena *)page1, 1);
47 if (*page1 != 0) /* use-after-free should return 0 */
49 page3 = bpf_arena_alloc_pages(&arena, NULL, 1, NUMA_NO_NODE, 0);
57 if (*(page1 + PAGE_SIZE) != 0)
59 if (*(page1 - PAGE_SIZE) != 0)
61 if (*(page2 + PAGE_SIZE) != 0)
63 if (*(page2 - PAGE_SIZE) != 0)
68 char _license[] SEC("license") = "GPL";