tracex5_user.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include <stdio.h>
  2. #include <linux/bpf.h>
  3. #include <unistd.h>
  4. #include <linux/filter.h>
  5. #include <linux/seccomp.h>
  6. #include <sys/prctl.h>
  7. #include "libbpf.h"
  8. #include "bpf_load.h"
  9. #include <sys/resource.h>
  10. /* install fake seccomp program to enable seccomp code path inside the kernel,
  11. * so that our kprobe attached to seccomp_phase1() can be triggered
  12. */
  13. static void install_accept_all_seccomp(void)
  14. {
  15. struct sock_filter filter[] = {
  16. BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_ALLOW),
  17. };
  18. struct sock_fprog prog = {
  19. .len = (unsigned short)(sizeof(filter)/sizeof(filter[0])),
  20. .filter = filter,
  21. };
  22. if (prctl(PR_SET_SECCOMP, 2, &prog))
  23. perror("prctl");
  24. }
  25. int main(int ac, char **argv)
  26. {
  27. FILE *f;
  28. char filename[256];
  29. struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
  30. snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
  31. setrlimit(RLIMIT_MEMLOCK, &r);
  32. if (load_bpf_file(filename)) {
  33. printf("%s", bpf_log_buf);
  34. return 1;
  35. }
  36. install_accept_all_seccomp();
  37. f = popen("dd if=/dev/zero of=/dev/null count=5", "r");
  38. (void) f;
  39. read_trace_pipe();
  40. return 0;
  41. }