1 // SPDX-License-Identifier: GPL-2.0 2 /* Copyright (c) 2022 Meta Platforms, Inc. and affiliates. */ 3 4 #include <linux/bpf.h> 5 #include <bpf/bpf_helpers.h> 6 #include <bpf/bpf_core_read.h> 7 8 struct task_struct___bad { 9 int pid; 10 int fake_field; 11 void *fake_field_subprog; 12 } __attribute__((preserve_access_index)); 13 14 SEC("?raw_tp/sys_enter") 15 int bad_relo(const void *ctx) 16 { 17 static struct task_struct___bad *t; 18 19 return bpf_core_field_size(t->fake_field); 20 } 21 22 static __noinline int bad_subprog(void) 23 { 24 static struct task_struct___bad *t; 25 26 /* ugliness below is a field offset relocation */ 27 return (void *)&t->fake_field_subprog - (void *)t; 28 } 29 30 SEC("?raw_tp/sys_enter") 31 int bad_relo_subprog(const void *ctx) 32 { 33 static struct task_struct___bad *t; 34 35 return bad_subprog() + bpf_core_field_size(t->pid); 36 } 37 38 char _license[] SEC("license") = "GPL"; 39