Linux Audio

Check our new training course

Loading...
v6.13.7
 1// SPDX-License-Identifier: GPL-2.0
 2/* Copyright (c) 2020 Facebook */
 3#include <vmlinux.h>
 4#include <bpf/bpf_helpers.h>
 5#include <bpf/bpf_tracing.h>
 6
 7char _license[] SEC("license") = "GPL";
 8
 9struct key_t {
10	int a;
11	int b;
12	int c;
13};
14
15struct {
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
24SEC("iter/bpf_map_elem")
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}
v6.8
 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
 7char _license[] SEC("license") = "GPL";
 8
 9struct key_t {
10	int a;
11	int b;
12	int c;
13};
14
15struct {
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
24SEC("iter/bpf_map_elem")
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}