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_uprobe_autoattach.c (1649B)


      1// SPDX-License-Identifier: GPL-2.0
      2/* Copyright (c) 2022, Oracle and/or its affiliates. */
      3
      4#include "vmlinux.h"
      5
      6#include <bpf/bpf_core_read.h>
      7#include <bpf/bpf_helpers.h>
      8#include <bpf/bpf_tracing.h>
      9
     10int uprobe_byname_parm1 = 0;
     11int uprobe_byname_ran = 0;
     12int uretprobe_byname_rc = 0;
     13int uretprobe_byname_ran = 0;
     14size_t uprobe_byname2_parm1 = 0;
     15int uprobe_byname2_ran = 0;
     16char *uretprobe_byname2_rc = NULL;
     17int uretprobe_byname2_ran = 0;
     18
     19int test_pid;
     20
     21/* This program cannot auto-attach, but that should not stop other
     22 * programs from attaching.
     23 */
     24SEC("uprobe")
     25int handle_uprobe_noautoattach(struct pt_regs *ctx)
     26{
     27	return 0;
     28}
     29
     30SEC("uprobe//proc/self/exe:autoattach_trigger_func")
     31int handle_uprobe_byname(struct pt_regs *ctx)
     32{
     33	uprobe_byname_parm1 = PT_REGS_PARM1_CORE(ctx);
     34	uprobe_byname_ran = 1;
     35	return 0;
     36}
     37
     38SEC("uretprobe//proc/self/exe:autoattach_trigger_func")
     39int handle_uretprobe_byname(struct pt_regs *ctx)
     40{
     41	uretprobe_byname_rc = PT_REGS_RC_CORE(ctx);
     42	uretprobe_byname_ran = 2;
     43	return 0;
     44}
     45
     46
     47SEC("uprobe/libc.so.6:malloc")
     48int handle_uprobe_byname2(struct pt_regs *ctx)
     49{
     50	int pid = bpf_get_current_pid_tgid() >> 32;
     51
     52	/* ignore irrelevant invocations */
     53	if (test_pid != pid)
     54		return 0;
     55	uprobe_byname2_parm1 = PT_REGS_PARM1_CORE(ctx);
     56	uprobe_byname2_ran = 3;
     57	return 0;
     58}
     59
     60SEC("uretprobe/libc.so.6:malloc")
     61int handle_uretprobe_byname2(struct pt_regs *ctx)
     62{
     63	int pid = bpf_get_current_pid_tgid() >> 32;
     64
     65	/* ignore irrelevant invocations */
     66	if (test_pid != pid)
     67		return 0;
     68	uretprobe_byname2_rc = (char *)PT_REGS_RC_CORE(ctx);
     69	uretprobe_byname2_ran = 4;
     70	return 0;
     71}
     72
     73char _license[] SEC("license") = "GPL";