1// SPDX-License-Identifier: GPL-2.0 2/* Copyright (c) 2021 Facebook */ 3 4#include <linux/bpf.h> 5#include <bpf/bpf_helpers.h> 6#include "bpf_misc.h" 7 8char _license[] SEC("license") = "GPL"; 9 10struct bpf_map; 11 12struct { 13 __uint(type, BPF_MAP_TYPE_ARRAY); 14 __type(key, __u32); 15 __type(value, __u32); 16 __uint(max_entries, 1000); 17} map_random_data SEC(".maps"); 18 19struct map_bloom_type { 20 __uint(type, BPF_MAP_TYPE_BLOOM_FILTER); 21 __type(value, __u32); 22 __uint(max_entries, 10000); 23 __uint(map_extra, 5); 24} map_bloom SEC(".maps"); 25 26struct { 27 __uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS); 28 __type(key, int); 29 __type(value, int); 30 __uint(max_entries, 1); 31 __array(values, struct map_bloom_type); 32} outer_map SEC(".maps"); 33 34struct callback_ctx { 35 struct bpf_map *map; 36}; 37 38int error = 0; 39 40static __u64 41check_elem(struct bpf_map *map, __u32 *key, __u32 *val, 42 struct callback_ctx *data) 43{ 44 int err; 45 46 err = bpf_map_peek_elem(data->map, val); 47 if (err) { 48 error |= 1; 49 return 1; /* stop the iteration */ 50 } 51 52 return 0; 53} 54 55SEC("fentry/" SYS_PREFIX "sys_getpgid") 56int inner_map(void *ctx) 57{ 58 struct bpf_map *inner_map; 59 struct callback_ctx data; 60 int key = 0; 61 62 inner_map = bpf_map_lookup_elem(&outer_map, &key); 63 if (!inner_map) { 64 error |= 2; 65 return 0; 66 } 67 68 data.map = inner_map; 69 bpf_for_each_map_elem(&map_random_data, check_elem, &data, 0); 70 71 return 0; 72} 73 74SEC("fentry/" SYS_PREFIX "sys_getpgid") 75int check_bloom(void *ctx) 76{ 77 struct callback_ctx data; 78 79 data.map = (struct bpf_map *)&map_bloom; 80 bpf_for_each_map_elem(&map_random_data, check_elem, &data, 0); 81 82 return 0; 83} 84