test_module_attach.c (2756B)
1// SPDX-License-Identifier: GPL-2.0 2/* Copyright (c) 2020 Facebook */ 3 4#include "vmlinux.h" 5#include <bpf/bpf_helpers.h> 6#include <bpf/bpf_tracing.h> 7#include <bpf/bpf_core_read.h> 8#include "../bpf_testmod/bpf_testmod.h" 9 10__u32 raw_tp_read_sz = 0; 11 12SEC("raw_tp/bpf_testmod_test_read") 13int BPF_PROG(handle_raw_tp, 14 struct task_struct *task, struct bpf_testmod_test_read_ctx *read_ctx) 15{ 16 raw_tp_read_sz = BPF_CORE_READ(read_ctx, len); 17 return 0; 18} 19 20__u32 raw_tp_bare_write_sz = 0; 21 22SEC("raw_tp/bpf_testmod_test_write_bare") 23int BPF_PROG(handle_raw_tp_bare, 24 struct task_struct *task, struct bpf_testmod_test_write_ctx *write_ctx) 25{ 26 raw_tp_bare_write_sz = BPF_CORE_READ(write_ctx, len); 27 return 0; 28} 29 30int raw_tp_writable_bare_in_val = 0; 31int raw_tp_writable_bare_early_ret = 0; 32int raw_tp_writable_bare_out_val = 0; 33 34SEC("raw_tp.w/bpf_testmod_test_writable_bare") 35int BPF_PROG(handle_raw_tp_writable_bare, 36 struct bpf_testmod_test_writable_ctx *writable) 37{ 38 raw_tp_writable_bare_in_val = writable->val; 39 writable->early_ret = raw_tp_writable_bare_early_ret; 40 writable->val = raw_tp_writable_bare_out_val; 41 return 0; 42} 43 44__u32 tp_btf_read_sz = 0; 45 46SEC("tp_btf/bpf_testmod_test_read") 47int BPF_PROG(handle_tp_btf, 48 struct task_struct *task, struct bpf_testmod_test_read_ctx *read_ctx) 49{ 50 tp_btf_read_sz = read_ctx->len; 51 return 0; 52} 53 54__u32 fentry_read_sz = 0; 55 56SEC("fentry/bpf_testmod_test_read") 57int BPF_PROG(handle_fentry, 58 struct file *file, struct kobject *kobj, 59 struct bin_attribute *bin_attr, char *buf, loff_t off, size_t len) 60{ 61 fentry_read_sz = len; 62 return 0; 63} 64 65__u32 fentry_manual_read_sz = 0; 66 67SEC("fentry") 68int BPF_PROG(handle_fentry_manual, 69 struct file *file, struct kobject *kobj, 70 struct bin_attribute *bin_attr, char *buf, loff_t off, size_t len) 71{ 72 fentry_manual_read_sz = len; 73 return 0; 74} 75 76__u32 fexit_read_sz = 0; 77int fexit_ret = 0; 78 79SEC("fexit/bpf_testmod_test_read") 80int BPF_PROG(handle_fexit, 81 struct file *file, struct kobject *kobj, 82 struct bin_attribute *bin_attr, char *buf, loff_t off, size_t len, 83 int ret) 84{ 85 fexit_read_sz = len; 86 fexit_ret = ret; 87 return 0; 88} 89 90SEC("fexit/bpf_testmod_return_ptr") 91int BPF_PROG(handle_fexit_ret, int arg, struct file *ret) 92{ 93 long buf = 0; 94 95 bpf_probe_read_kernel(&buf, 8, ret); 96 bpf_probe_read_kernel(&buf, 8, (char *)ret + 256); 97 *(volatile long long *)ret; 98 *(volatile int *)&ret->f_mode; 99 return 0; 100} 101 102__u32 fmod_ret_read_sz = 0; 103 104SEC("fmod_ret/bpf_testmod_test_read") 105int BPF_PROG(handle_fmod_ret, 106 struct file *file, struct kobject *kobj, 107 struct bin_attribute *bin_attr, char *buf, loff_t off, size_t len) 108{ 109 fmod_ret_read_sz = len; 110 return 0; /* don't override the exit code */ 111} 112 113char _license[] SEC("license") = "GPL";