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_skeleton.c (1372B)


      1// SPDX-License-Identifier: GPL-2.0
      2/* Copyright (c) 2019 Facebook */
      3
      4#include <stdbool.h>
      5#include <linux/bpf.h>
      6#include <bpf/bpf_helpers.h>
      7
      8#define __read_mostly SEC(".data.read_mostly")
      9
     10struct s {
     11	int a;
     12	long long b;
     13} __attribute__((packed));
     14
     15/* .data section */
     16int in1 = -1;
     17long long in2 = -1;
     18
     19/* .bss section */
     20char in3 = '\0';
     21long long in4 __attribute__((aligned(64))) = 0;
     22struct s in5 = {};
     23
     24/* .rodata section */
     25const volatile struct {
     26	const int in6;
     27} in = {};
     28
     29/* .data section */
     30int out1 = -1;
     31long long out2 = -1;
     32
     33/* .bss section */
     34char out3 = 0;
     35long long out4 = 0;
     36int out6 = 0;
     37
     38extern bool CONFIG_BPF_SYSCALL __kconfig;
     39extern int LINUX_KERNEL_VERSION __kconfig;
     40bool bpf_syscall = 0;
     41int kern_ver = 0;
     42
     43struct s out5 = {};
     44
     45
     46const volatile int in_dynarr_sz SEC(".rodata.dyn");
     47const volatile int in_dynarr[4] SEC(".rodata.dyn") = { -1, -2, -3, -4 };
     48
     49int out_dynarr[4] SEC(".data.dyn") = { 1, 2, 3, 4 };
     50
     51int read_mostly_var __read_mostly;
     52int out_mostly_var;
     53
     54SEC("raw_tp/sys_enter")
     55int handler(const void *ctx)
     56{
     57	int i;
     58
     59	out1 = in1;
     60	out2 = in2;
     61	out3 = in3;
     62	out4 = in4;
     63	out5 = in5;
     64	out6 = in.in6;
     65
     66	bpf_syscall = CONFIG_BPF_SYSCALL;
     67	kern_ver = LINUX_KERNEL_VERSION;
     68
     69	for (i = 0; i < in_dynarr_sz; i++)
     70		out_dynarr[i] = in_dynarr[i];
     71
     72	out_mostly_var = read_mostly_var;
     73
     74	return 0;
     75}
     76
     77char _license[] SEC("license") = "GPL";