Tested on x86-64 and Ilya was also kind enough to give it a spin on s390x, both passing with probe_user:OK there. The test is using the newly added bpf_probe_read_user() to dump sockaddr from connect call into .bss BPF map and overrides the user buffer via bpf_probe_write_user(): # ./test_progs [...] #17 pkt_md_access:OK #18 probe_user:OK #19 prog_run_xattr:OK [...] Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Tested-by: Ilya Leoshkevich <iii@linux.ibm.com> Acked-by: Andrii Nakryiko <andriin@fb.com> Link: https://lore.kernel.org/bpf/90f449d8af25354e05080e82fc6e2d3179da30ea.1572649915.git.daniel@iogearbox.net
27 lines
528 B
C
27 lines
528 B
C
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#include <linux/ptrace.h>
|
|
#include <linux/bpf.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include "bpf_helpers.h"
|
|
#include "bpf_tracing.h"
|
|
|
|
static struct sockaddr_in old;
|
|
|
|
SEC("kprobe/__sys_connect")
|
|
int handle_sys_connect(struct pt_regs *ctx)
|
|
{
|
|
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";
|