1 // SPDX-License-Identifier: GPL-2.0 2 /* Copyright (c) 2022 Meta Platforms, Inc. and affiliates. */ 3 #include <vmlinux.h> 4 #include <bpf/bpf_tracing.h> 5 #include <bpf/bpf_helpers.h> 6 7 static struct prog_test_ref_kfunc __kptr_ref *v; 8 long total_sum = -1; 9 10 extern struct prog_test_ref_kfunc *bpf_kfunc_call_test_acquire(unsigned long *sp) __ksym; 11 extern void bpf_kfunc_call_test_release(struct prog_test_ref_kfunc *p) __ksym; 12 13 SEC("tc") 14 int test_jit_probe_mem(struct __sk_buff *ctx) 15 { 16 struct prog_test_ref_kfunc *p; 17 unsigned long zero = 0, sum; 18 19 p = bpf_kfunc_call_test_acquire(&zero); 20 if (!p) 21 return 1; 22 23 p = bpf_kptr_xchg(&v, p); 24 if (p) 25 goto release_out; 26 27 /* Direct map value access of kptr, should be PTR_UNTRUSTED */ 28 p = v; 29 if (!p) 30 return 1; 31 32 asm volatile ( 33 "r9 = %[p];" 34 "%[sum] = 0;" 35 36 /* r8 = p->a */ 37 "r8 = *(u32 *)(r9 + 0);" 38 "%[sum] += r8;" 39 40 /* r8 = p->b */ 41 "r8 = *(u32 *)(r9 + 4);" 42 "%[sum] += r8;" 43 44 "r9 += 8;" 45 /* r9 = p->a */ 46 "r9 = *(u32 *)(r9 - 8);" 47 "%[sum] += r9;" 48 49 : [sum] "=r"(sum) 50 : [p] "r"(p) 51 : "r8", "r9" 52 ); 53 54 total_sum = sum; 55 return 0; 56 release_out: 57 bpf_kfunc_call_test_release(p); 58 return 1; 59 } 60 61 char _license[] SEC("license") = "GPL"; 62