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

wide_access.c (2708B)


      1#define BPF_SOCK_ADDR_STORE(field, off, res, err, flgs)	\
      2{ \
      3	"wide store to bpf_sock_addr." #field "[" #off "]", \
      4	.insns = { \
      5	BPF_MOV64_IMM(BPF_REG_0, 1), \
      6	BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_0, \
      7		    offsetof(struct bpf_sock_addr, field[off])), \
      8	BPF_EXIT_INSN(), \
      9	}, \
     10	.result = res, \
     11	.prog_type = BPF_PROG_TYPE_CGROUP_SOCK_ADDR, \
     12	.expected_attach_type = BPF_CGROUP_UDP6_SENDMSG, \
     13	.errstr = err, \
     14	.flags = flgs, \
     15}
     16
     17/* user_ip6[0] is u64 aligned */
     18BPF_SOCK_ADDR_STORE(user_ip6, 0, ACCEPT,
     19		    NULL, 0),
     20BPF_SOCK_ADDR_STORE(user_ip6, 1, REJECT,
     21		    "invalid bpf_context access off=12 size=8",
     22		    F_NEEDS_EFFICIENT_UNALIGNED_ACCESS),
     23BPF_SOCK_ADDR_STORE(user_ip6, 2, ACCEPT,
     24		    NULL, 0),
     25BPF_SOCK_ADDR_STORE(user_ip6, 3, REJECT,
     26		    "invalid bpf_context access off=20 size=8",
     27		    F_NEEDS_EFFICIENT_UNALIGNED_ACCESS),
     28
     29/* msg_src_ip6[0] is _not_ u64 aligned */
     30BPF_SOCK_ADDR_STORE(msg_src_ip6, 0, REJECT,
     31		    "invalid bpf_context access off=44 size=8",
     32		    F_NEEDS_EFFICIENT_UNALIGNED_ACCESS),
     33BPF_SOCK_ADDR_STORE(msg_src_ip6, 1, ACCEPT,
     34		    NULL, 0),
     35BPF_SOCK_ADDR_STORE(msg_src_ip6, 2, REJECT,
     36		    "invalid bpf_context access off=52 size=8",
     37		    F_NEEDS_EFFICIENT_UNALIGNED_ACCESS),
     38BPF_SOCK_ADDR_STORE(msg_src_ip6, 3, REJECT,
     39		    "invalid bpf_context access off=56 size=8", 0),
     40
     41#undef BPF_SOCK_ADDR_STORE
     42
     43#define BPF_SOCK_ADDR_LOAD(field, off, res, err, flgs)	\
     44{ \
     45	"wide load from bpf_sock_addr." #field "[" #off "]", \
     46	.insns = { \
     47	BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, \
     48		    offsetof(struct bpf_sock_addr, field[off])), \
     49	BPF_MOV64_IMM(BPF_REG_0, 1), \
     50	BPF_EXIT_INSN(), \
     51	}, \
     52	.result = res, \
     53	.prog_type = BPF_PROG_TYPE_CGROUP_SOCK_ADDR, \
     54	.expected_attach_type = BPF_CGROUP_UDP6_SENDMSG, \
     55	.errstr = err, \
     56	.flags = flgs, \
     57}
     58
     59/* user_ip6[0] is u64 aligned */
     60BPF_SOCK_ADDR_LOAD(user_ip6, 0, ACCEPT,
     61		   NULL, 0),
     62BPF_SOCK_ADDR_LOAD(user_ip6, 1, REJECT,
     63		   "invalid bpf_context access off=12 size=8",
     64		    F_NEEDS_EFFICIENT_UNALIGNED_ACCESS),
     65BPF_SOCK_ADDR_LOAD(user_ip6, 2, ACCEPT,
     66		   NULL, 0),
     67BPF_SOCK_ADDR_LOAD(user_ip6, 3, REJECT,
     68		   "invalid bpf_context access off=20 size=8",
     69		    F_NEEDS_EFFICIENT_UNALIGNED_ACCESS),
     70
     71/* msg_src_ip6[0] is _not_ u64 aligned */
     72BPF_SOCK_ADDR_LOAD(msg_src_ip6, 0, REJECT,
     73		   "invalid bpf_context access off=44 size=8",
     74		    F_NEEDS_EFFICIENT_UNALIGNED_ACCESS),
     75BPF_SOCK_ADDR_LOAD(msg_src_ip6, 1, ACCEPT,
     76		   NULL, 0),
     77BPF_SOCK_ADDR_LOAD(msg_src_ip6, 2, REJECT,
     78		   "invalid bpf_context access off=52 size=8",
     79		    F_NEEDS_EFFICIENT_UNALIGNED_ACCESS),
     80BPF_SOCK_ADDR_LOAD(msg_src_ip6, 3, REJECT,
     81		   "invalid bpf_context access off=56 size=8", 0),
     82
     83#undef BPF_SOCK_ADDR_LOAD