Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /* Copyright (c) 2020 Facebook */
0003 
0004 #include "vmlinux.h"
0005 #include <bpf/bpf_helpers.h>
0006 #include <bpf/bpf_tracing.h>
0007 #include <bpf/bpf_core_read.h>
0008 #include "../bpf_testmod/bpf_testmod.h"
0009 
0010 __u32 raw_tp_read_sz = 0;
0011 
0012 SEC("raw_tp/bpf_testmod_test_read")
0013 int BPF_PROG(handle_raw_tp,
0014          struct task_struct *task, struct bpf_testmod_test_read_ctx *read_ctx)
0015 {
0016     raw_tp_read_sz = BPF_CORE_READ(read_ctx, len);
0017     return 0;
0018 }
0019 
0020 __u32 raw_tp_bare_write_sz = 0;
0021 
0022 SEC("raw_tp/bpf_testmod_test_write_bare")
0023 int BPF_PROG(handle_raw_tp_bare,
0024          struct task_struct *task, struct bpf_testmod_test_write_ctx *write_ctx)
0025 {
0026     raw_tp_bare_write_sz = BPF_CORE_READ(write_ctx, len);
0027     return 0;
0028 }
0029 
0030 int raw_tp_writable_bare_in_val = 0;
0031 int raw_tp_writable_bare_early_ret = 0;
0032 int raw_tp_writable_bare_out_val = 0;
0033 
0034 SEC("raw_tp.w/bpf_testmod_test_writable_bare")
0035 int BPF_PROG(handle_raw_tp_writable_bare,
0036          struct bpf_testmod_test_writable_ctx *writable)
0037 {
0038     raw_tp_writable_bare_in_val = writable->val;
0039     writable->early_ret = raw_tp_writable_bare_early_ret;
0040     writable->val = raw_tp_writable_bare_out_val;
0041     return 0;
0042 }
0043 
0044 __u32 tp_btf_read_sz = 0;
0045 
0046 SEC("tp_btf/bpf_testmod_test_read")
0047 int BPF_PROG(handle_tp_btf,
0048          struct task_struct *task, struct bpf_testmod_test_read_ctx *read_ctx)
0049 {
0050     tp_btf_read_sz = read_ctx->len;
0051     return 0;
0052 }
0053 
0054 __u32 fentry_read_sz = 0;
0055 
0056 SEC("fentry/bpf_testmod_test_read")
0057 int BPF_PROG(handle_fentry,
0058          struct file *file, struct kobject *kobj,
0059          struct bin_attribute *bin_attr, char *buf, loff_t off, size_t len)
0060 {
0061     fentry_read_sz = len;
0062     return 0;
0063 }
0064 
0065 __u32 fentry_manual_read_sz = 0;
0066 
0067 SEC("fentry")
0068 int BPF_PROG(handle_fentry_manual,
0069          struct file *file, struct kobject *kobj,
0070          struct bin_attribute *bin_attr, char *buf, loff_t off, size_t len)
0071 {
0072     fentry_manual_read_sz = len;
0073     return 0;
0074 }
0075 
0076 __u32 fexit_read_sz = 0;
0077 int fexit_ret = 0;
0078 
0079 SEC("fexit/bpf_testmod_test_read")
0080 int BPF_PROG(handle_fexit,
0081          struct file *file, struct kobject *kobj,
0082          struct bin_attribute *bin_attr, char *buf, loff_t off, size_t len,
0083          int ret)
0084 {
0085     fexit_read_sz = len;
0086     fexit_ret = ret;
0087     return 0;
0088 }
0089 
0090 SEC("fexit/bpf_testmod_return_ptr")
0091 int BPF_PROG(handle_fexit_ret, int arg, struct file *ret)
0092 {
0093     long buf = 0;
0094 
0095     bpf_probe_read_kernel(&buf, 8, ret);
0096     bpf_probe_read_kernel(&buf, 8, (char *)ret + 256);
0097     *(volatile long long *)ret;
0098     *(volatile int *)&ret->f_mode;
0099     return 0;
0100 }
0101 
0102 __u32 fmod_ret_read_sz = 0;
0103 
0104 SEC("fmod_ret/bpf_testmod_test_read")
0105 int BPF_PROG(handle_fmod_ret,
0106          struct file *file, struct kobject *kobj,
0107          struct bin_attribute *bin_attr, char *buf, loff_t off, size_t len)
0108 {
0109     fmod_ret_read_sz = len;
0110     return 0; /* don't override the exit code */
0111 }
0112 
0113 char _license[] SEC("license") = "GPL";