diff options
| author | Daniel Borkmann <daniel@iogearbox.net> | 2016-05-13 13:08:26 -0400 |
|---|---|---|
| committer | David S. Miller <davem@davemloft.net> | 2016-05-16 13:49:31 -0400 |
| commit | 4936e3528e3e272c567fe4ff0abb7ce3e1500575 (patch) | |
| tree | fe605512827310535b99290d24ccc9fe0c57afef | |
| parent | 553eb544444e28749e2d752dee11e2ae4a3ecfb6 (diff) | |
bpf: minor cleanups in ebpf code
Besides others, remove redundant comments where the code is self
documenting enough, and properly indent various bpf_verifier_ops
and bpf_prog_type_list declarations. Moreover, remove two exports
that actually have no module user.
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
| -rw-r--r-- | kernel/bpf/core.c | 2 | ||||
| -rw-r--r-- | net/core/filter.c | 34 |
2 files changed, 15 insertions, 21 deletions
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index d781b077431f..5313d09d4b62 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c | |||
| @@ -129,14 +129,12 @@ struct bpf_prog *bpf_prog_realloc(struct bpf_prog *fp_old, unsigned int size, | |||
| 129 | 129 | ||
| 130 | return fp; | 130 | return fp; |
| 131 | } | 131 | } |
| 132 | EXPORT_SYMBOL_GPL(bpf_prog_realloc); | ||
| 133 | 132 | ||
| 134 | void __bpf_prog_free(struct bpf_prog *fp) | 133 | void __bpf_prog_free(struct bpf_prog *fp) |
| 135 | { | 134 | { |
| 136 | kfree(fp->aux); | 135 | kfree(fp->aux); |
| 137 | vfree(fp); | 136 | vfree(fp); |
| 138 | } | 137 | } |
| 139 | EXPORT_SYMBOL_GPL(__bpf_prog_free); | ||
| 140 | 138 | ||
| 141 | #ifdef CONFIG_BPF_JIT | 139 | #ifdef CONFIG_BPF_JIT |
| 142 | struct bpf_binary_header * | 140 | struct bpf_binary_header * |
diff --git a/net/core/filter.c b/net/core/filter.c index 71c2a1f473ad..ea51b479cf02 100644 --- a/net/core/filter.c +++ b/net/core/filter.c | |||
| @@ -2069,16 +2069,12 @@ tc_cls_act_func_proto(enum bpf_func_id func_id) | |||
| 2069 | 2069 | ||
| 2070 | static bool __is_valid_access(int off, int size, enum bpf_access_type type) | 2070 | static bool __is_valid_access(int off, int size, enum bpf_access_type type) |
| 2071 | { | 2071 | { |
| 2072 | /* check bounds */ | ||
| 2073 | if (off < 0 || off >= sizeof(struct __sk_buff)) | 2072 | if (off < 0 || off >= sizeof(struct __sk_buff)) |
| 2074 | return false; | 2073 | return false; |
| 2075 | 2074 | /* The verifier guarantees that size > 0. */ | |
| 2076 | /* disallow misaligned access */ | ||
| 2077 | if (off % size != 0) | 2075 | if (off % size != 0) |
| 2078 | return false; | 2076 | return false; |
| 2079 | 2077 | if (size != sizeof(__u32)) | |
| 2080 | /* all __sk_buff fields are __u32 */ | ||
| 2081 | if (size != 4) | ||
| 2082 | return false; | 2078 | return false; |
| 2083 | 2079 | ||
| 2084 | return true; | 2080 | return true; |
| @@ -2097,7 +2093,7 @@ static bool sk_filter_is_valid_access(int off, int size, | |||
| 2097 | if (type == BPF_WRITE) { | 2093 | if (type == BPF_WRITE) { |
| 2098 | switch (off) { | 2094 | switch (off) { |
| 2099 | case offsetof(struct __sk_buff, cb[0]) ... | 2095 | case offsetof(struct __sk_buff, cb[0]) ... |
| 2100 | offsetof(struct __sk_buff, cb[4]): | 2096 | offsetof(struct __sk_buff, cb[4]): |
| 2101 | break; | 2097 | break; |
| 2102 | default: | 2098 | default: |
| 2103 | return false; | 2099 | return false; |
| @@ -2278,30 +2274,30 @@ static u32 bpf_net_convert_ctx_access(enum bpf_access_type type, int dst_reg, | |||
| 2278 | } | 2274 | } |
| 2279 | 2275 | ||
| 2280 | static const struct bpf_verifier_ops sk_filter_ops = { | 2276 | static const struct bpf_verifier_ops sk_filter_ops = { |
| 2281 | .get_func_proto = sk_filter_func_proto, | 2277 | .get_func_proto = sk_filter_func_proto, |
| 2282 | .is_valid_access = sk_filter_is_valid_access, | 2278 | .is_valid_access = sk_filter_is_valid_access, |
| 2283 | .convert_ctx_access = bpf_net_convert_ctx_access, | 2279 | .convert_ctx_access = bpf_net_convert_ctx_access, |
| 2284 | }; | 2280 | }; |
| 2285 | 2281 | ||
| 2286 | static const struct bpf_verifier_ops tc_cls_act_ops = { | 2282 | static const struct bpf_verifier_ops tc_cls_act_ops = { |
| 2287 | .get_func_proto = tc_cls_act_func_proto, | 2283 | .get_func_proto = tc_cls_act_func_proto, |
| 2288 | .is_valid_access = tc_cls_act_is_valid_access, | 2284 | .is_valid_access = tc_cls_act_is_valid_access, |
| 2289 | .convert_ctx_access = bpf_net_convert_ctx_access, | 2285 | .convert_ctx_access = bpf_net_convert_ctx_access, |
| 2290 | }; | 2286 | }; |
| 2291 | 2287 | ||
| 2292 | static struct bpf_prog_type_list sk_filter_type __read_mostly = { | 2288 | static struct bpf_prog_type_list sk_filter_type __read_mostly = { |
| 2293 | .ops = &sk_filter_ops, | 2289 | .ops = &sk_filter_ops, |
| 2294 | .type = BPF_PROG_TYPE_SOCKET_FILTER, | 2290 | .type = BPF_PROG_TYPE_SOCKET_FILTER, |
| 2295 | }; | 2291 | }; |
| 2296 | 2292 | ||
| 2297 | static struct bpf_prog_type_list sched_cls_type __read_mostly = { | 2293 | static struct bpf_prog_type_list sched_cls_type __read_mostly = { |
| 2298 | .ops = &tc_cls_act_ops, | 2294 | .ops = &tc_cls_act_ops, |
| 2299 | .type = BPF_PROG_TYPE_SCHED_CLS, | 2295 | .type = BPF_PROG_TYPE_SCHED_CLS, |
| 2300 | }; | 2296 | }; |
| 2301 | 2297 | ||
| 2302 | static struct bpf_prog_type_list sched_act_type __read_mostly = { | 2298 | static struct bpf_prog_type_list sched_act_type __read_mostly = { |
| 2303 | .ops = &tc_cls_act_ops, | 2299 | .ops = &tc_cls_act_ops, |
| 2304 | .type = BPF_PROG_TYPE_SCHED_ACT, | 2300 | .type = BPF_PROG_TYPE_SCHED_ACT, |
| 2305 | }; | 2301 | }; |
| 2306 | 2302 | ||
| 2307 | static int __init register_sk_filter_ops(void) | 2303 | static int __init register_sk_filter_ops(void) |
