aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/bpf/syscall.c
diff options
context:
space:
mode:
authorAndrey Ignatov <rdna@fb.com>2019-02-27 15:59:24 -0500
committerAlexei Starovoitov <ast@kernel.org>2019-04-12 16:54:58 -0400
commit7b146cebe30cb481b0f70d85779da938da818637 (patch)
tree11dbbeb42b32557d345e6dac2baf2881cbe5adb5 /kernel/bpf/syscall.c
parentb1cd609d9b517f01867c211bd520cc805db3068a (diff)
bpf: Sysctl hook
Containerized applications may run as root and it may create problems for whole host. Specifically such applications may change a sysctl and affect applications in other containers. Furthermore in existing infrastructure it may not be possible to just completely disable writing to sysctl, instead such a process should be gradual with ability to log what sysctl are being changed by a container, investigate, limit the set of writable sysctl to currently used ones (so that new ones can not be changed) and eventually reduce this set to zero. The patch introduces new program type BPF_PROG_TYPE_CGROUP_SYSCTL and attach type BPF_CGROUP_SYSCTL to solve these problems on cgroup basis. New program type has access to following minimal context: struct bpf_sysctl { __u32 write; }; Where @write indicates whether sysctl is being read (= 0) or written (= 1). Helpers to access sysctl name and value will be introduced separately. BPF_CGROUP_SYSCTL attach point is added to sysctl code right before passing control to ctl_table->proc_handler so that BPF program can either allow or deny access to sysctl. Suggested-by: Roman Gushchin <guro@fb.com> Signed-off-by: Andrey Ignatov <rdna@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'kernel/bpf/syscall.c')
-rw-r--r--kernel/bpf/syscall.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index d995eedfdd16..92c9b8a32b50 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -1888,6 +1888,9 @@ static int bpf_prog_attach(const union bpf_attr *attr)
1888 case BPF_FLOW_DISSECTOR: 1888 case BPF_FLOW_DISSECTOR:
1889 ptype = BPF_PROG_TYPE_FLOW_DISSECTOR; 1889 ptype = BPF_PROG_TYPE_FLOW_DISSECTOR;
1890 break; 1890 break;
1891 case BPF_CGROUP_SYSCTL:
1892 ptype = BPF_PROG_TYPE_CGROUP_SYSCTL;
1893 break;
1891 default: 1894 default:
1892 return -EINVAL; 1895 return -EINVAL;
1893 } 1896 }
@@ -1966,6 +1969,9 @@ static int bpf_prog_detach(const union bpf_attr *attr)
1966 return lirc_prog_detach(attr); 1969 return lirc_prog_detach(attr);
1967 case BPF_FLOW_DISSECTOR: 1970 case BPF_FLOW_DISSECTOR:
1968 return skb_flow_dissector_bpf_prog_detach(attr); 1971 return skb_flow_dissector_bpf_prog_detach(attr);
1972 case BPF_CGROUP_SYSCTL:
1973 ptype = BPF_PROG_TYPE_CGROUP_SYSCTL;
1974 break;
1969 default: 1975 default:
1970 return -EINVAL; 1976 return -EINVAL;
1971 } 1977 }
@@ -1999,6 +2005,7 @@ static int bpf_prog_query(const union bpf_attr *attr,
1999 case BPF_CGROUP_UDP6_SENDMSG: 2005 case BPF_CGROUP_UDP6_SENDMSG:
2000 case BPF_CGROUP_SOCK_OPS: 2006 case BPF_CGROUP_SOCK_OPS:
2001 case BPF_CGROUP_DEVICE: 2007 case BPF_CGROUP_DEVICE:
2008 case BPF_CGROUP_SYSCTL:
2002 break; 2009 break;
2003 case BPF_LIRC_MODE2: 2010 case BPF_LIRC_MODE2:
2004 return lirc_prog_query(attr, uattr); 2011 return lirc_prog_query(attr, uattr);