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

cgroup_getset_retval_getsockopt.c (764B)


      1// SPDX-License-Identifier: GPL-2.0-only
      2
      3/*
      4 * Copyright 2021 Google LLC.
      5 */
      6
      7#include <errno.h>
      8#include <linux/bpf.h>
      9#include <bpf/bpf_helpers.h>
     10
     11__u32 invocations = 0;
     12__u32 assertion_error = 0;
     13__u32 retval_value = 0;
     14__u32 ctx_retval_value = 0;
     15
     16SEC("cgroup/getsockopt")
     17int get_retval(struct bpf_sockopt *ctx)
     18{
     19	retval_value = bpf_get_retval();
     20	ctx_retval_value = ctx->retval;
     21	__sync_fetch_and_add(&invocations, 1);
     22
     23	return 1;
     24}
     25
     26SEC("cgroup/getsockopt")
     27int set_eisconn(struct bpf_sockopt *ctx)
     28{
     29	__sync_fetch_and_add(&invocations, 1);
     30
     31	if (bpf_set_retval(-EISCONN))
     32		assertion_error = 1;
     33
     34	return 1;
     35}
     36
     37SEC("cgroup/getsockopt")
     38int clear_retval(struct bpf_sockopt *ctx)
     39{
     40	__sync_fetch_and_add(&invocations, 1);
     41
     42	ctx->retval = 0;
     43
     44	return 1;
     45}