1 // SPDX-License-Identifier: GPL-2.0 2 /* Copyright (c) 2020 Facebook */ 3 #include "bpf_iter.h" 4 #include <bpf/bpf_helpers.h> 5 #include <bpf/bpf_tracing.h> 6 7 char _license[] SEC("license") = "GPL"; 8 9 struct key_t { 10 int a; 11 int b; 12 int c; 13 }; 14 15 struct { 16 __uint(type, BPF_MAP_TYPE_HASH); 17 __uint(max_entries, 3); 18 __type(key, struct key_t); 19 __type(value, __u64); 20 } hashmap1 SEC(".maps"); 21 22 __u32 key_sum = 0; 23 24 SEC("iter/bpf_map_elem") dump_bpf_hash_map(struct bpf_iter__bpf_map_elem * ctx)25int dump_bpf_hash_map(struct bpf_iter__bpf_map_elem *ctx) 26 { 27 void *key = ctx->key; 28 29 if (key == (void *)0) 30 return 0; 31 32 /* out of bound access w.r.t. hashmap1 */ 33 key_sum += *(__u32 *)(key + sizeof(struct key_t)); 34 return 0; 35 } 36