verifier.c (3a2f2ac9b96f9a9f5538396a212d3b9fb543bfc5) verifier.c (d5a3b1f691865be576c2bffa708549b8cdccda19)
1/* Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
2 *
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.
6 *
7 * This program is distributed in the hope that it will be useful, but
8 * WITHOUT ANY WARRANTY; without even the implied warranty of

--- 232 unchanged lines hidden (view full) ---

241
242static const struct {
243 int map_type;
244 int func_id;
245} func_limit[] = {
246 {BPF_MAP_TYPE_PROG_ARRAY, BPF_FUNC_tail_call},
247 {BPF_MAP_TYPE_PERF_EVENT_ARRAY, BPF_FUNC_perf_event_read},
248 {BPF_MAP_TYPE_PERF_EVENT_ARRAY, BPF_FUNC_perf_event_output},
1/* Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
2 *
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.
6 *
7 * This program is distributed in the hope that it will be useful, but
8 * WITHOUT ANY WARRANTY; without even the implied warranty of

--- 232 unchanged lines hidden (view full) ---

241
242static const struct {
243 int map_type;
244 int func_id;
245} func_limit[] = {
246 {BPF_MAP_TYPE_PROG_ARRAY, BPF_FUNC_tail_call},
247 {BPF_MAP_TYPE_PERF_EVENT_ARRAY, BPF_FUNC_perf_event_read},
248 {BPF_MAP_TYPE_PERF_EVENT_ARRAY, BPF_FUNC_perf_event_output},
249 {BPF_MAP_TYPE_STACK_TRACE, BPF_FUNC_get_stackid},
249};
250
251static void print_verifier_state(struct verifier_env *env)
252{
253 enum bpf_reg_type t;
254 int i;
255
256 for (i = 0; i < MAX_BPF_REG; i++) {

--- 649 unchanged lines hidden (view full) ---

906
907 for (i = 0; i < ARRAY_SIZE(func_limit); i++) {
908 bool_map = (map->map_type == func_limit[i].map_type);
909 bool_func = (func_id == func_limit[i].func_id);
910 /* only when map & func pair match it can continue.
911 * don't allow any other map type to be passed into
912 * the special func;
913 */
250};
251
252static void print_verifier_state(struct verifier_env *env)
253{
254 enum bpf_reg_type t;
255 int i;
256
257 for (i = 0; i < MAX_BPF_REG; i++) {

--- 649 unchanged lines hidden (view full) ---

907
908 for (i = 0; i < ARRAY_SIZE(func_limit); i++) {
909 bool_map = (map->map_type == func_limit[i].map_type);
910 bool_func = (func_id == func_limit[i].func_id);
911 /* only when map & func pair match it can continue.
912 * don't allow any other map type to be passed into
913 * the special func;
914 */
914 if (bool_func && bool_map != bool_func)
915 if (bool_func && bool_map != bool_func) {
916 verbose("cannot pass map_type %d into func %d\n",
917 map->map_type, func_id);
915 return -EINVAL;
918 return -EINVAL;
919 }
916 }
917
918 return 0;
919}
920
921static int check_call(struct verifier_env *env, int func_id)
922{
923 struct verifier_state *state = &env->cur_state;

--- 1153 unchanged lines hidden (view full) ---

2077 if (BPF_CLASS(insn->code) != BPF_JMP ||
2078 BPF_OP(insn->code) == BPF_CALL ||
2079 BPF_OP(insn->code) == BPF_EXIT)
2080 continue;
2081
2082 /* adjust offset of jmps if necessary */
2083 if (i < pos && i + insn->off + 1 > pos)
2084 insn->off += delta;
920 }
921
922 return 0;
923}
924
925static int check_call(struct verifier_env *env, int func_id)
926{
927 struct verifier_state *state = &env->cur_state;

--- 1153 unchanged lines hidden (view full) ---

2081 if (BPF_CLASS(insn->code) != BPF_JMP ||
2082 BPF_OP(insn->code) == BPF_CALL ||
2083 BPF_OP(insn->code) == BPF_EXIT)
2084 continue;
2085
2086 /* adjust offset of jmps if necessary */
2087 if (i < pos && i + insn->off + 1 > pos)
2088 insn->off += delta;
2085 else if (i > pos + delta && i + insn->off + 1 <= pos + delta)
2089 else if (i > pos && i + insn->off + 1 < pos)
2086 insn->off -= delta;
2087 }
2088}
2089
2090/* convert load instructions that access fields of 'struct __sk_buff'
2091 * into sequence of instructions that access fields of 'struct sk_buff'
2092 */
2093static int convert_ctx_accesses(struct verifier_env *env)

--- 208 unchanged lines hidden ---
2090 insn->off -= delta;
2091 }
2092}
2093
2094/* convert load instructions that access fields of 'struct __sk_buff'
2095 * into sequence of instructions that access fields of 'struct sk_buff'
2096 */
2097static int convert_ctx_accesses(struct verifier_env *env)

--- 208 unchanged lines hidden ---