tracex5_user.c 1.1 KB

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