tracex5_user.c 973 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. /* install fake seccomp program to enable seccomp code path inside the kernel,
  10. * so that our kprobe attached to seccomp_phase1() can be triggered
  11. */
  12. static void install_accept_all_seccomp(void)
  13. {
  14. struct sock_filter filter[] = {
  15. BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_ALLOW),
  16. };
  17. struct sock_fprog prog = {
  18. .len = (unsigned short)(sizeof(filter)/sizeof(filter[0])),
  19. .filter = filter,
  20. };
  21. if (prctl(PR_SET_SECCOMP, 2, &prog))
  22. perror("prctl");
  23. }
  24. int main(int ac, char **argv)
  25. {
  26. FILE *f;
  27. char filename[256];
  28. snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
  29. if (load_bpf_file(filename)) {
  30. printf("%s", bpf_log_buf);
  31. return 1;
  32. }
  33. install_accept_all_seccomp();
  34. f = popen("dd if=/dev/zero of=/dev/null count=5", "r");
  35. (void) f;
  36. read_trace_pipe();
  37. return 0;
  38. }