summaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/bpf/progs/test_probe_user.c
blob: 89b3532ccc75e3f71a8b4a2516b044269e7248c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// SPDX-License-Identifier: GPL-2.0

#include <linux/ptrace.h>
#include <linux/bpf.h>

#include <netinet/in.h>

#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>

static struct sockaddr_in old;

SEC("kprobe/__sys_connect")
int BPF_KPROBE(handle_sys_connect)
{
	void *ptr = (void *)PT_REGS_PARM2(ctx);
	struct sockaddr_in new;

	bpf_probe_read_user(&old, sizeof(old), ptr);
	__builtin_memset(&new, 0xab, sizeof(new));
	bpf_probe_write_user(ptr, &new, sizeof(new));

	return 0;
}

char _license[] SEC("license") = "GPL";