Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /* Copyright (c) 2020 Facebook */
0003 #include "bpf_iter.h"
0004 #include <bpf/bpf_helpers.h>
0005 #include <bpf/bpf_tracing.h>
0006 
0007 char _license[] SEC("license") = "GPL";
0008 
0009 struct key_t {
0010     int a;
0011     int b;
0012     int c;
0013 };
0014 
0015 struct {
0016     __uint(type, BPF_MAP_TYPE_HASH);
0017     __uint(max_entries, 3);
0018     __type(key, struct key_t);
0019     __type(value, __u64);
0020 } hashmap1 SEC(".maps");
0021 
0022 __u32 key_sum = 0;
0023 
0024 SEC("iter/bpf_map_elem")
0025 int dump_bpf_hash_map(struct bpf_iter__bpf_map_elem *ctx)
0026 {
0027     void *key = ctx->key;
0028 
0029     if (key == (void *)0)
0030         return 0;
0031 
0032     /* out of bound access w.r.t. hashmap1 */
0033     key_sum += *(__u32 *)(key + sizeof(struct key_t));
0034     return 0;
0035 }