Skip to content

Instantly share code, notes, and snippets.

@polachok
Created June 23, 2016 16:24
Show Gist options
  • Save polachok/fb9e0f9ee53816c37f075b94cd09d195 to your computer and use it in GitHub Desktop.
Save polachok/fb9e0f9ee53816c37f075b94cd09d195 to your computer and use it in GitHub Desktop.
static struct sock *cookie_v4_check_wrapper(struct sock *sk, struct sk_buff *skb) {
struct sock* (*old_func)(struct sock *sk, struct sk_buff *skb) = (void*)((unsigned long)cookie_v4_check_ptr + MCOUNT_INSN_SIZE);
tcp_synq_overflow(sk);
return old_func(sk, skb);
}
static void notrace
tcpsecrets_ftrace_handler(unsigned long ip, unsigned long parent_ip,
struct ftrace_ops *fops, struct pt_regs *regs)
{
regs->ip = (unsigned long)cookie_v4_check_wrapper;
}
static struct ftrace_ops tcpsecrets_ftrace_ops __read_mostly = {
.func = tcpsecrets_ftrace_handler,
.flags = FTRACE_OPS_FL_SAVE_REGS,
};
static void fix_cookie_v4_check(void) {
int ret;
ret = ftrace_set_filter_ip(&tcpsecrets_ftrace_ops, (unsigned long)cookie_v4_check_ptr, 0, 0);
if (ret) {
printk("cant set ftrace filter\n");
}
ret = register_ftrace_function(&tcpsecrets_ftrace_ops);
if (ret) {
printk("cant set ftrace function\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment