xref: /linux/tools/testing/selftests/bpf/progs/test_probe_user.c (revision 6ecf206d602fafd077811b6033c183deb0c0a9c8)
1 // SPDX-License-Identifier: GPL-2.0
2 #include "vmlinux.h"
3 #include <bpf/bpf_helpers.h>
4 #include <bpf/bpf_tracing.h>
5 #include <bpf/bpf_core_read.h>
6 #include "bpf_misc.h"
7 
8 static struct sockaddr_in old;
9 
10 SEC("ksyscall/connect")
11 int BPF_KSYSCALL(handle_sys_connect, int fd, struct sockaddr_in *uservaddr, int addrlen)
12 {
13 	struct sockaddr_in new;
14 
15 	bpf_probe_read_user(&old, sizeof(old), uservaddr);
16 	__builtin_memset(&new, 0xab, sizeof(new));
17 	bpf_probe_write_user(uservaddr, &new, sizeof(new));
18 
19 	return 0;
20 }
21 
22 char _license[] SEC("license") = "GPL";
23