Created
June 17, 2022 15:04
-
-
Save majek/209bfb85c0f4d6e4c7b6f2f0e369457d to your computer and use it in GitHub Desktop.
repro_access_to_stack_error_bpf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.PHONY: repro | |
repro: | |
$(CLANG) -Wall -Wextra -O2 --target=bpf -c -g \ | |
repro.bpf.c \ | |
-o repro.bpf.o | |
bpftool gen skeleton repro.bpf.o > repro.bpf.skel.h | |
$(CLANG) -Wall -fno-omit-frame-pointer -Wextra -O2 -g \ | |
repro.c \ | |
-lbpf \ | |
-lelf \ | |
-lz \ | |
-o repro |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stddef.h> | |
#include <string.h> | |
#include <linux/types.h> | |
#include <bpf/bpf_endian.h> | |
#include <bpf/bpf_helpers.h> | |
#include <linux/bpf.h> | |
struct { | |
__uint(type, BPF_MAP_TYPE_RINGBUF); | |
__uint(max_entries, 4 * 1024); | |
} rb SEC(".maps"); | |
struct event { | |
__u64 this_field_works_with_u32_fails_with_u64; | |
char v6[16]; | |
}; | |
SEC("sockops") | |
int bpf_testcb(struct bpf_sock_ops *skops) | |
{ | |
struct event e = {}; | |
memcpy(&e.v6, &skops->remote_ip6, 16); | |
bpf_ringbuf_output(&rb, &e, sizeof(e), 0); | |
return 1; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <errno.h> | |
#include <error.h> | |
#include <stdio.h> | |
#include "repro.bpf.skel.h" | |
int main() | |
{ | |
struct repro_bpf *skel = repro_bpf__open_and_load(); | |
if (!skel) { | |
error(1, errno, "Failed to open and load BPF skeleton\n"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Solution: