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

task_ls_recursion.c (1470B)


      1// SPDX-License-Identifier: GPL-2.0
      2/* Copyright (c) 2021 Facebook */
      3
      4#include "vmlinux.h"
      5#include <bpf/bpf_helpers.h>
      6#include <bpf/bpf_tracing.h>
      7
      8char _license[] SEC("license") = "GPL";
      9
     10struct {
     11	__uint(type, BPF_MAP_TYPE_TASK_STORAGE);
     12	__uint(map_flags, BPF_F_NO_PREALLOC);
     13	__type(key, int);
     14	__type(value, long);
     15} map_a SEC(".maps");
     16
     17struct {
     18	__uint(type, BPF_MAP_TYPE_TASK_STORAGE);
     19	__uint(map_flags, BPF_F_NO_PREALLOC);
     20	__type(key, int);
     21	__type(value, long);
     22} map_b SEC(".maps");
     23
     24SEC("fentry/bpf_local_storage_lookup")
     25int BPF_PROG(on_lookup)
     26{
     27	struct task_struct *task = bpf_get_current_task_btf();
     28
     29	bpf_task_storage_delete(&map_a, task);
     30	bpf_task_storage_delete(&map_b, task);
     31	return 0;
     32}
     33
     34SEC("fentry/bpf_local_storage_update")
     35int BPF_PROG(on_update)
     36{
     37	struct task_struct *task = bpf_get_current_task_btf();
     38	long *ptr;
     39
     40	ptr = bpf_task_storage_get(&map_a, task, 0,
     41				   BPF_LOCAL_STORAGE_GET_F_CREATE);
     42	if (ptr)
     43		*ptr += 1;
     44
     45	ptr = bpf_task_storage_get(&map_b, task, 0,
     46				   BPF_LOCAL_STORAGE_GET_F_CREATE);
     47	if (ptr)
     48		*ptr += 1;
     49
     50	return 0;
     51}
     52
     53SEC("tp_btf/sys_enter")
     54int BPF_PROG(on_enter, struct pt_regs *regs, long id)
     55{
     56	struct task_struct *task;
     57	long *ptr;
     58
     59	task = bpf_get_current_task_btf();
     60	ptr = bpf_task_storage_get(&map_a, task, 0,
     61				   BPF_LOCAL_STORAGE_GET_F_CREATE);
     62	if (ptr)
     63		*ptr = 200;
     64
     65	ptr = bpf_task_storage_get(&map_b, task, 0,
     66				   BPF_LOCAL_STORAGE_GET_F_CREATE);
     67	if (ptr)
     68		*ptr = 100;
     69	return 0;
     70}