blob: c2317b39e0d25d5812ff6800553cd6bac9044b4c [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Alexei Starovoitov5bacd782015-05-19 16:59:05 -07002#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>
Jakub Kicinski2bf3e2e2018-05-14 22:35:02 -07008#include <bpf/bpf.h>
Alexei Starovoitov5bacd782015-05-19 16:59:05 -07009#include "bpf_load.h"
Naveen N. Rao973d94d2016-09-24 02:10:05 +053010#include <sys/resource.h>
Daniel T. Lee24a60342020-03-21 19:04:23 +090011#include "trace_helpers.h"
Alexei Starovoitov5bacd782015-05-19 16:59:05 -070012
13/* install fake seccomp program to enable seccomp code path inside the kernel,
14 * so that our kprobe attached to seccomp_phase1() can be triggered
15 */
16static void install_accept_all_seccomp(void)
17{
18 struct sock_filter filter[] = {
19 BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_ALLOW),
20 };
21 struct sock_fprog prog = {
22 .len = (unsigned short)(sizeof(filter)/sizeof(filter[0])),
23 .filter = filter,
24 };
25 if (prctl(PR_SET_SECCOMP, 2, &prog))
26 perror("prctl");
27}
28
29int main(int ac, char **argv)
30{
31 FILE *f;
32 char filename[256];
Naveen N. Rao973d94d2016-09-24 02:10:05 +053033 struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
Alexei Starovoitov5bacd782015-05-19 16:59:05 -070034
35 snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
Naveen N. Rao973d94d2016-09-24 02:10:05 +053036 setrlimit(RLIMIT_MEMLOCK, &r);
Alexei Starovoitov5bacd782015-05-19 16:59:05 -070037
38 if (load_bpf_file(filename)) {
39 printf("%s", bpf_log_buf);
40 return 1;
41 }
42
43 install_accept_all_seccomp();
44
45 f = popen("dd if=/dev/zero of=/dev/null count=5", "r");
46 (void) f;
47
48 read_trace_pipe();
49
50 return 0;
51}