diff options
-rw-r--r-- | net/core/filter.c | 36 |
1 files changed, 14 insertions, 22 deletions
diff --git a/net/core/filter.c b/net/core/filter.c index 6fe09e36dad9..741721233166 100644 --- a/net/core/filter.c +++ b/net/core/filter.c | |||
@@ -1093,7 +1093,6 @@ int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk) | |||
1093 | } | 1093 | } |
1094 | EXPORT_SYMBOL_GPL(sk_attach_filter); | 1094 | EXPORT_SYMBOL_GPL(sk_attach_filter); |
1095 | 1095 | ||
1096 | #ifdef CONFIG_BPF_SYSCALL | ||
1097 | int sk_attach_bpf(u32 ufd, struct sock *sk) | 1096 | int sk_attach_bpf(u32 ufd, struct sock *sk) |
1098 | { | 1097 | { |
1099 | struct sk_filter *fp, *old_fp; | 1098 | struct sk_filter *fp, *old_fp; |
@@ -1107,7 +1106,6 @@ int sk_attach_bpf(u32 ufd, struct sock *sk) | |||
1107 | return PTR_ERR(prog); | 1106 | return PTR_ERR(prog); |
1108 | 1107 | ||
1109 | if (prog->aux->prog_type != BPF_PROG_TYPE_SOCKET_FILTER) { | 1108 | if (prog->aux->prog_type != BPF_PROG_TYPE_SOCKET_FILTER) { |
1110 | /* valid fd, but invalid program type */ | ||
1111 | bpf_prog_put(prog); | 1109 | bpf_prog_put(prog); |
1112 | return -EINVAL; | 1110 | return -EINVAL; |
1113 | } | 1111 | } |
@@ -1117,8 +1115,8 @@ int sk_attach_bpf(u32 ufd, struct sock *sk) | |||
1117 | bpf_prog_put(prog); | 1115 | bpf_prog_put(prog); |
1118 | return -ENOMEM; | 1116 | return -ENOMEM; |
1119 | } | 1117 | } |
1120 | fp->prog = prog; | ||
1121 | 1118 | ||
1119 | fp->prog = prog; | ||
1122 | atomic_set(&fp->refcnt, 0); | 1120 | atomic_set(&fp->refcnt, 0); |
1123 | 1121 | ||
1124 | if (!sk_filter_charge(sk, fp)) { | 1122 | if (!sk_filter_charge(sk, fp)) { |
@@ -1136,10 +1134,8 @@ int sk_attach_bpf(u32 ufd, struct sock *sk) | |||
1136 | return 0; | 1134 | return 0; |
1137 | } | 1135 | } |
1138 | 1136 | ||
1139 | /* allow socket filters to call | 1137 | static const struct bpf_func_proto * |
1140 | * bpf_map_lookup_elem(), bpf_map_update_elem(), bpf_map_delete_elem() | 1138 | sk_filter_func_proto(enum bpf_func_id func_id) |
1141 | */ | ||
1142 | static const struct bpf_func_proto *sock_filter_func_proto(enum bpf_func_id func_id) | ||
1143 | { | 1139 | { |
1144 | switch (func_id) { | 1140 | switch (func_id) { |
1145 | case BPF_FUNC_map_lookup_elem: | 1141 | case BPF_FUNC_map_lookup_elem: |
@@ -1153,34 +1149,30 @@ static const struct bpf_func_proto *sock_filter_func_proto(enum bpf_func_id func | |||
1153 | } | 1149 | } |
1154 | } | 1150 | } |
1155 | 1151 | ||
1156 | static bool sock_filter_is_valid_access(int off, int size, enum bpf_access_type type) | 1152 | static bool sk_filter_is_valid_access(int off, int size, |
1153 | enum bpf_access_type type) | ||
1157 | { | 1154 | { |
1158 | /* skb fields cannot be accessed yet */ | 1155 | /* skb fields cannot be accessed yet */ |
1159 | return false; | 1156 | return false; |
1160 | } | 1157 | } |
1161 | 1158 | ||
1162 | static const struct bpf_verifier_ops sock_filter_ops = { | 1159 | static const struct bpf_verifier_ops sk_filter_ops = { |
1163 | .get_func_proto = sock_filter_func_proto, | 1160 | .get_func_proto = sk_filter_func_proto, |
1164 | .is_valid_access = sock_filter_is_valid_access, | 1161 | .is_valid_access = sk_filter_is_valid_access, |
1165 | }; | 1162 | }; |
1166 | 1163 | ||
1167 | static struct bpf_prog_type_list sock_filter_type __read_mostly = { | 1164 | static struct bpf_prog_type_list sk_filter_type __read_mostly = { |
1168 | .ops = &sock_filter_ops, | 1165 | .ops = &sk_filter_ops, |
1169 | .type = BPF_PROG_TYPE_SOCKET_FILTER, | 1166 | .type = BPF_PROG_TYPE_SOCKET_FILTER, |
1170 | }; | 1167 | }; |
1171 | 1168 | ||
1172 | static int __init register_sock_filter_ops(void) | 1169 | static int __init register_sk_filter_ops(void) |
1173 | { | 1170 | { |
1174 | bpf_register_prog_type(&sock_filter_type); | 1171 | bpf_register_prog_type(&sk_filter_type); |
1175 | return 0; | 1172 | return 0; |
1176 | } | 1173 | } |
1177 | late_initcall(register_sock_filter_ops); | 1174 | late_initcall(register_sk_filter_ops); |
1178 | #else | 1175 | |
1179 | int sk_attach_bpf(u32 ufd, struct sock *sk) | ||
1180 | { | ||
1181 | return -EOPNOTSUPP; | ||
1182 | } | ||
1183 | #endif | ||
1184 | int sk_detach_filter(struct sock *sk) | 1176 | int sk_detach_filter(struct sock *sk) |
1185 | { | 1177 | { |
1186 | int ret = -ENOENT; | 1178 | int ret = -ENOENT; |