Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /* Copyright (c) 2022 Meta Platforms, Inc. and affiliates. */
0003 
0004 #include <linux/bpf.h>
0005 #include <bpf/bpf_helpers.h>
0006 #include <bpf/bpf_core_read.h>
0007 
0008 struct task_struct___bad {
0009     int pid;
0010     int fake_field;
0011     void *fake_field_subprog;
0012 } __attribute__((preserve_access_index));
0013 
0014 SEC("?raw_tp/sys_enter")
0015 int bad_relo(const void *ctx)
0016 {
0017     static struct task_struct___bad *t;
0018 
0019     return bpf_core_field_size(t->fake_field);
0020 }
0021 
0022 static __noinline int bad_subprog(void)
0023 {
0024     static struct task_struct___bad *t;
0025 
0026     /* ugliness below is a field offset relocation */
0027     return (void *)&t->fake_field_subprog - (void *)t;
0028 }
0029 
0030 SEC("?raw_tp/sys_enter")
0031 int bad_relo_subprog(const void *ctx)
0032 {
0033     static struct task_struct___bad *t;
0034 
0035     return bad_subprog() + bpf_core_field_size(t->pid);
0036 }
0037 
0038 struct {
0039     __uint(type, BPF_MAP_TYPE_ARRAY);
0040     __uint(max_entries, 1);
0041     __type(key, int);
0042     __type(value, int);
0043 } existing_map SEC(".maps");
0044 
0045 struct {
0046     __uint(type, BPF_MAP_TYPE_ARRAY);
0047     __uint(max_entries, 1);
0048     __type(key, int);
0049     __type(value, int);
0050 } missing_map SEC(".maps");
0051 
0052 SEC("?raw_tp/sys_enter")
0053 int use_missing_map(const void *ctx)
0054 {
0055     int zero = 0, *value;
0056 
0057     value = bpf_map_lookup_elem(&existing_map, &zero);
0058 
0059     value = bpf_map_lookup_elem(&missing_map, &zero);
0060 
0061     return value != NULL;
0062 }
0063 
0064 char _license[] SEC("license") = "GPL";