cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

test_attach_probe.c (1673B)


      1// SPDX-License-Identifier: GPL-2.0
      2// Copyright (c) 2017 Facebook
      3
      4#include <linux/ptrace.h>
      5#include <linux/bpf.h>
      6#include <bpf/bpf_helpers.h>
      7#include <bpf/bpf_tracing.h>
      8#include "bpf_misc.h"
      9
     10int kprobe_res = 0;
     11int kprobe2_res = 0;
     12int kretprobe_res = 0;
     13int kretprobe2_res = 0;
     14int uprobe_res = 0;
     15int uretprobe_res = 0;
     16int uprobe_byname_res = 0;
     17int uretprobe_byname_res = 0;
     18int uprobe_byname2_res = 0;
     19int uretprobe_byname2_res = 0;
     20
     21SEC("kprobe")
     22int handle_kprobe(struct pt_regs *ctx)
     23{
     24	kprobe_res = 1;
     25	return 0;
     26}
     27
     28SEC("kprobe/" SYS_PREFIX "sys_nanosleep")
     29int BPF_KPROBE(handle_kprobe_auto)
     30{
     31	kprobe2_res = 11;
     32	return 0;
     33}
     34
     35SEC("kretprobe")
     36int handle_kretprobe(struct pt_regs *ctx)
     37{
     38	kretprobe_res = 2;
     39	return 0;
     40}
     41
     42SEC("kretprobe/" SYS_PREFIX "sys_nanosleep")
     43int BPF_KRETPROBE(handle_kretprobe_auto)
     44{
     45	kretprobe2_res = 22;
     46	return 0;
     47}
     48
     49SEC("uprobe")
     50int handle_uprobe(struct pt_regs *ctx)
     51{
     52	uprobe_res = 3;
     53	return 0;
     54}
     55
     56SEC("uretprobe")
     57int handle_uretprobe(struct pt_regs *ctx)
     58{
     59	uretprobe_res = 4;
     60	return 0;
     61}
     62
     63SEC("uprobe")
     64int handle_uprobe_byname(struct pt_regs *ctx)
     65{
     66	uprobe_byname_res = 5;
     67	return 0;
     68}
     69
     70/* use auto-attach format for section definition. */
     71SEC("uretprobe//proc/self/exe:trigger_func2")
     72int handle_uretprobe_byname(struct pt_regs *ctx)
     73{
     74	uretprobe_byname_res = 6;
     75	return 0;
     76}
     77
     78SEC("uprobe")
     79int handle_uprobe_byname2(struct pt_regs *ctx)
     80{
     81	unsigned int size = PT_REGS_PARM1(ctx);
     82
     83	/* verify malloc size */
     84	if (size == 1)
     85		uprobe_byname2_res = 7;
     86	return 0;
     87}
     88
     89SEC("uretprobe")
     90int handle_uretprobe_byname2(struct pt_regs *ctx)
     91{
     92	uretprobe_byname2_res = 8;
     93	return 0;
     94}
     95
     96char _license[] SEC("license") = "GPL";