1 /* Copyright (c) 2017 Facebook
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of version 2 of the GNU General Public
5 * License as published by the Free Software Foundation.
9 #include <linux/version.h>
10 #include "bpf_helpers.h"
13 int bpf_prog1(struct bpf_cgroup_dev_ctx
*ctx
)
15 short type
= ctx
->access_type
& 0xFFFF;
17 short access
= ctx
->access_type
>> 16;
18 char fmt
[] = " %d:%d \n";
21 case BPF_DEVCG_DEV_BLOCK
:
24 case BPF_DEVCG_DEV_CHAR
:
32 if (access
& BPF_DEVCG_ACC_READ
)
35 if (access
& BPF_DEVCG_ACC_WRITE
)
38 if (access
& BPF_DEVCG_ACC_MKNOD
)
41 bpf_trace_printk(fmt
, sizeof(fmt
), ctx
->major
, ctx
->minor
);
44 /* Allow access to /dev/zero and /dev/random.
45 * Forbid everything else.
47 if (ctx
->major
!= 1 || type
!= BPF_DEVCG_DEV_CHAR
)
51 case 5: /* 1:5 /dev/zero */
52 case 9: /* 1:9 /dev/urandom */
59 char _license
[] SEC("license") = "GPL";
60 __u32 _version
SEC("version") = LINUX_VERSION_CODE
;