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_setsockopt.c (862B)


      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
     15SEC("cgroup/setsockopt")
     16int get_retval(struct bpf_sockopt *ctx)
     17{
     18	retval_value = bpf_get_retval();
     19	__sync_fetch_and_add(&invocations, 1);
     20
     21	return 1;
     22}
     23
     24SEC("cgroup/setsockopt")
     25int set_eunatch(struct bpf_sockopt *ctx)
     26{
     27	__sync_fetch_and_add(&invocations, 1);
     28
     29	if (bpf_set_retval(-EUNATCH))
     30		assertion_error = 1;
     31
     32	return 0;
     33}
     34
     35SEC("cgroup/setsockopt")
     36int set_eisconn(struct bpf_sockopt *ctx)
     37{
     38	__sync_fetch_and_add(&invocations, 1);
     39
     40	if (bpf_set_retval(-EISCONN))
     41		assertion_error = 1;
     42
     43	return 0;
     44}
     45
     46SEC("cgroup/setsockopt")
     47int legacy_eperm(struct bpf_sockopt *ctx)
     48{
     49	__sync_fetch_and_add(&invocations, 1);
     50
     51	return 0;
     52}