linux/tools/testing/selftests/bpf/progs/test_probe_user.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0
   2
   3#include <linux/ptrace.h>
   4#include <linux/bpf.h>
   5
   6#include <netinet/in.h>
   7
   8#include <bpf/bpf_helpers.h>
   9#include <bpf/bpf_tracing.h>
  10
  11static struct sockaddr_in old;
  12
  13SEC("kprobe/__sys_connect")
  14int BPF_KPROBE(handle_sys_connect)
  15{
  16        void *ptr = (void *)PT_REGS_PARM2(ctx);
  17        struct sockaddr_in new;
  18
  19        bpf_probe_read_user(&old, sizeof(old), ptr);
  20        __builtin_memset(&new, 0xab, sizeof(new));
  21        bpf_probe_write_user(ptr, &new, sizeof(new));
  22
  23        return 0;
  24}
  25
  26char _license[] SEC("license") = "GPL";
  27