~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/progs/verifier_arena_large.c

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 /* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */
  3 
  4 #define BPF_NO_KFUNC_PROTOTYPES
  5 #include <vmlinux.h>
  6 #include <bpf/bpf_helpers.h>
  7 #include <bpf/bpf_tracing.h>
  8 #include "bpf_misc.h"
  9 #include "bpf_experimental.h"
 10 #include "bpf_arena_common.h"
 11 
 12 #define ARENA_SIZE (1ull << 32)
 13 
 14 struct {
 15         __uint(type, BPF_MAP_TYPE_ARENA);
 16         __uint(map_flags, BPF_F_MMAPABLE);
 17         __uint(max_entries, ARENA_SIZE / PAGE_SIZE);
 18 } arena SEC(".maps");
 19 
 20 SEC("syscall")
 21 __success __retval(0)
 22 int big_alloc1(void *ctx)
 23 {
 24 #if defined(__BPF_FEATURE_ADDR_SPACE_CAST)
 25         volatile char __arena *page1, *page2, *no_page, *page3;
 26         void __arena *base;
 27 
 28         page1 = base = bpf_arena_alloc_pages(&arena, NULL, 1, NUMA_NO_NODE, 0);
 29         if (!page1)
 30                 return 1;
 31         *page1 = 1;
 32         page2 = bpf_arena_alloc_pages(&arena, base + ARENA_SIZE - PAGE_SIZE,
 33                                       1, NUMA_NO_NODE, 0);
 34         if (!page2)
 35                 return 2;
 36         *page2 = 2;
 37         no_page = bpf_arena_alloc_pages(&arena, base + ARENA_SIZE,
 38                                         1, NUMA_NO_NODE, 0);
 39         if (no_page)
 40                 return 3;
 41         if (*page1 != 1)
 42                 return 4;
 43         if (*page2 != 2)
 44                 return 5;
 45         bpf_arena_free_pages(&arena, (void __arena *)page1, 1);
 46         if (*page2 != 2)
 47                 return 6;
 48         if (*page1 != 0) /* use-after-free should return 0 */
 49                 return 7;
 50         page3 = bpf_arena_alloc_pages(&arena, NULL, 1, NUMA_NO_NODE, 0);
 51         if (!page3)
 52                 return 8;
 53         *page3 = 3;
 54         if (page1 != page3)
 55                 return 9;
 56         if (*page2 != 2)
 57                 return 10;
 58         if (*(page1 + PAGE_SIZE) != 0)
 59                 return 11;
 60         if (*(page1 - PAGE_SIZE) != 0)
 61                 return 12;
 62         if (*(page2 + PAGE_SIZE) != 0)
 63                 return 13;
 64         if (*(page2 - PAGE_SIZE) != 0)
 65                 return 14;
 66 #endif
 67         return 0;
 68 }
 69 char _license[] SEC("license") = "GPL";
 70 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php