aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/bpf/syscall.c
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2017-02-16 19:34:01 -0500
committerDavid S. Miller <davem@davemloft.net>2017-02-16 19:34:01 -0500
commit3f64116a838e6c3468f9d5eed7f1f87cf3a2c3eb (patch)
tree388024d2ddbdcb9991ef4b472dfac31e425b807e /kernel/bpf/syscall.c
parentf3caf8618bce7e86c6f4f86785dd004c71b63a2d (diff)
parent4695daefba8df8a11fa0b0edd595eedae9ea59ae (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
Diffstat (limited to 'kernel/bpf/syscall.c')
-rw-r--r--kernel/bpf/syscall.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 08a4d287226b..f74ca17af64a 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -935,13 +935,14 @@ static int bpf_obj_get(const union bpf_attr *attr)
935 935
936#ifdef CONFIG_CGROUP_BPF 936#ifdef CONFIG_CGROUP_BPF
937 937
938#define BPF_PROG_ATTACH_LAST_FIELD attach_type 938#define BPF_PROG_ATTACH_LAST_FIELD attach_flags
939 939
940static int bpf_prog_attach(const union bpf_attr *attr) 940static int bpf_prog_attach(const union bpf_attr *attr)
941{ 941{
942 enum bpf_prog_type ptype;
942 struct bpf_prog *prog; 943 struct bpf_prog *prog;
943 struct cgroup *cgrp; 944 struct cgroup *cgrp;
944 enum bpf_prog_type ptype; 945 int ret;
945 946
946 if (!capable(CAP_NET_ADMIN)) 947 if (!capable(CAP_NET_ADMIN))
947 return -EPERM; 948 return -EPERM;
@@ -949,6 +950,9 @@ static int bpf_prog_attach(const union bpf_attr *attr)
949 if (CHECK_ATTR(BPF_PROG_ATTACH)) 950 if (CHECK_ATTR(BPF_PROG_ATTACH))
950 return -EINVAL; 951 return -EINVAL;
951 952
953 if (attr->attach_flags & ~BPF_F_ALLOW_OVERRIDE)
954 return -EINVAL;
955
952 switch (attr->attach_type) { 956 switch (attr->attach_type) {
953 case BPF_CGROUP_INET_INGRESS: 957 case BPF_CGROUP_INET_INGRESS:
954 case BPF_CGROUP_INET_EGRESS: 958 case BPF_CGROUP_INET_EGRESS:
@@ -971,10 +975,13 @@ static int bpf_prog_attach(const union bpf_attr *attr)
971 return PTR_ERR(cgrp); 975 return PTR_ERR(cgrp);
972 } 976 }
973 977
974 cgroup_bpf_update(cgrp, prog, attr->attach_type); 978 ret = cgroup_bpf_update(cgrp, prog, attr->attach_type,
979 attr->attach_flags & BPF_F_ALLOW_OVERRIDE);
980 if (ret)
981 bpf_prog_put(prog);
975 cgroup_put(cgrp); 982 cgroup_put(cgrp);
976 983
977 return 0; 984 return ret;
978} 985}
979 986
980#define BPF_PROG_DETACH_LAST_FIELD attach_type 987#define BPF_PROG_DETACH_LAST_FIELD attach_type
@@ -982,6 +989,7 @@ static int bpf_prog_attach(const union bpf_attr *attr)
982static int bpf_prog_detach(const union bpf_attr *attr) 989static int bpf_prog_detach(const union bpf_attr *attr)
983{ 990{
984 struct cgroup *cgrp; 991 struct cgroup *cgrp;
992 int ret;
985 993
986 if (!capable(CAP_NET_ADMIN)) 994 if (!capable(CAP_NET_ADMIN))
987 return -EPERM; 995 return -EPERM;
@@ -997,7 +1005,7 @@ static int bpf_prog_detach(const union bpf_attr *attr)
997 if (IS_ERR(cgrp)) 1005 if (IS_ERR(cgrp))
998 return PTR_ERR(cgrp); 1006 return PTR_ERR(cgrp);
999 1007
1000 cgroup_bpf_update(cgrp, NULL, attr->attach_type); 1008 ret = cgroup_bpf_update(cgrp, NULL, attr->attach_type, false);
1001 cgroup_put(cgrp); 1009 cgroup_put(cgrp);
1002 break; 1010 break;
1003 1011
@@ -1005,7 +1013,7 @@ static int bpf_prog_detach(const union bpf_attr *attr)
1005 return -EINVAL; 1013 return -EINVAL;
1006 } 1014 }
1007 1015
1008 return 0; 1016 return ret;
1009} 1017}
1010#endif /* CONFIG_CGROUP_BPF */ 1018#endif /* CONFIG_CGROUP_BPF */
1011 1019