aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/networking/filter.txt14
-rw-r--r--drivers/isdn/i4l/isdn_ppp.c4
-rw-r--r--drivers/net/ppp/ppp_generic.c4
-rw-r--r--drivers/net/team/team_mode_loadbalance.c10
-rw-r--r--include/linux/filter.h5
-rw-r--r--lib/test_bpf.c482
-rw-r--r--net/core/filter.c195
-rw-r--r--net/core/ptp_classifier.c2
-rw-r--r--net/netfilter/xt_bpf.c5
-rw-r--r--net/sched/cls_bpf.c4
10 files changed, 457 insertions, 268 deletions
diff --git a/Documentation/networking/filter.txt b/Documentation/networking/filter.txt
index 748fd385535d..dc7dcc8c8184 100644
--- a/Documentation/networking/filter.txt
+++ b/Documentation/networking/filter.txt
@@ -833,6 +833,20 @@ loops and other CFG validation; second step starts from the first insn and
833descends all possible paths. It simulates execution of every insn and observes 833descends all possible paths. It simulates execution of every insn and observes
834the state change of registers and stack. 834the state change of registers and stack.
835 835
836Testing
837-------
838
839Next to the BPF toolchain, the kernel also ships a test module that contains
840various test cases for classic and internal BPF that can be executed against
841the BPF interpreter and JIT compiler. It can be found in lib/test_bpf.c and
842enabled via Kconfig:
843
844 CONFIG_TEST_BPF=m
845
846After the module has been built and installed, the test suite can be executed
847via insmod or modprobe against 'test_bpf' module. Results of the test cases
848including timings in nsec can be found in the kernel log (dmesg).
849
836Misc 850Misc
837---- 851----
838 852
diff --git a/drivers/isdn/i4l/isdn_ppp.c b/drivers/isdn/i4l/isdn_ppp.c
index a5da511e3c9a..61ac63237446 100644
--- a/drivers/isdn/i4l/isdn_ppp.c
+++ b/drivers/isdn/i4l/isdn_ppp.c
@@ -634,7 +634,7 @@ isdn_ppp_ioctl(int min, struct file *file, unsigned int cmd, unsigned long arg)
634#ifdef CONFIG_IPPP_FILTER 634#ifdef CONFIG_IPPP_FILTER
635 case PPPIOCSPASS: 635 case PPPIOCSPASS:
636 { 636 {
637 struct sock_fprog fprog; 637 struct sock_fprog_kern fprog;
638 struct sock_filter *code; 638 struct sock_filter *code;
639 int err, len = get_filter(argp, &code); 639 int err, len = get_filter(argp, &code);
640 640
@@ -653,7 +653,7 @@ isdn_ppp_ioctl(int min, struct file *file, unsigned int cmd, unsigned long arg)
653 } 653 }
654 case PPPIOCSACTIVE: 654 case PPPIOCSACTIVE:
655 { 655 {
656 struct sock_fprog fprog; 656 struct sock_fprog_kern fprog;
657 struct sock_filter *code; 657 struct sock_filter *code;
658 int err, len = get_filter(argp, &code); 658 int err, len = get_filter(argp, &code);
659 659
diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
index e3923ebb693f..91d6c1272fcf 100644
--- a/drivers/net/ppp/ppp_generic.c
+++ b/drivers/net/ppp/ppp_generic.c
@@ -757,7 +757,7 @@ static long ppp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
757 757
758 err = get_filter(argp, &code); 758 err = get_filter(argp, &code);
759 if (err >= 0) { 759 if (err >= 0) {
760 struct sock_fprog fprog = { 760 struct sock_fprog_kern fprog = {
761 .len = err, 761 .len = err,
762 .filter = code, 762 .filter = code,
763 }; 763 };
@@ -778,7 +778,7 @@ static long ppp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
778 778
779 err = get_filter(argp, &code); 779 err = get_filter(argp, &code);
780 if (err >= 0) { 780 if (err >= 0) {
781 struct sock_fprog fprog = { 781 struct sock_fprog_kern fprog = {
782 .len = err, 782 .len = err,
783 .filter = code, 783 .filter = code,
784 }; 784 };
diff --git a/drivers/net/team/team_mode_loadbalance.c b/drivers/net/team/team_mode_loadbalance.c
index dbde3412ee5e..0a6ee07bf0af 100644
--- a/drivers/net/team/team_mode_loadbalance.c
+++ b/drivers/net/team/team_mode_loadbalance.c
@@ -49,7 +49,7 @@ struct lb_port_mapping {
49struct lb_priv_ex { 49struct lb_priv_ex {
50 struct team *team; 50 struct team *team;
51 struct lb_port_mapping tx_hash_to_port_mapping[LB_TX_HASHTABLE_SIZE]; 51 struct lb_port_mapping tx_hash_to_port_mapping[LB_TX_HASHTABLE_SIZE];
52 struct sock_fprog *orig_fprog; 52 struct sock_fprog_kern *orig_fprog;
53 struct { 53 struct {
54 unsigned int refresh_interval; /* in tenths of second */ 54 unsigned int refresh_interval; /* in tenths of second */
55 struct delayed_work refresh_dw; 55 struct delayed_work refresh_dw;
@@ -241,10 +241,10 @@ static int lb_bpf_func_get(struct team *team, struct team_gsetter_ctx *ctx)
241 return 0; 241 return 0;
242} 242}
243 243
244static int __fprog_create(struct sock_fprog **pfprog, u32 data_len, 244static int __fprog_create(struct sock_fprog_kern **pfprog, u32 data_len,
245 const void *data) 245 const void *data)
246{ 246{
247 struct sock_fprog *fprog; 247 struct sock_fprog_kern *fprog;
248 struct sock_filter *filter = (struct sock_filter *) data; 248 struct sock_filter *filter = (struct sock_filter *) data;
249 249
250 if (data_len % sizeof(struct sock_filter)) 250 if (data_len % sizeof(struct sock_filter))
@@ -262,7 +262,7 @@ static int __fprog_create(struct sock_fprog **pfprog, u32 data_len,
262 return 0; 262 return 0;
263} 263}
264 264
265static void __fprog_destroy(struct sock_fprog *fprog) 265static void __fprog_destroy(struct sock_fprog_kern *fprog)
266{ 266{
267 kfree(fprog->filter); 267 kfree(fprog->filter);
268 kfree(fprog); 268 kfree(fprog);
@@ -273,7 +273,7 @@ static int lb_bpf_func_set(struct team *team, struct team_gsetter_ctx *ctx)
273 struct lb_priv *lb_priv = get_lb_priv(team); 273 struct lb_priv *lb_priv = get_lb_priv(team);
274 struct sk_filter *fp = NULL; 274 struct sk_filter *fp = NULL;
275 struct sk_filter *orig_fp; 275 struct sk_filter *orig_fp;
276 struct sock_fprog *fprog = NULL; 276 struct sock_fprog_kern *fprog = NULL;
277 int err; 277 int err;
278 278
279 if (ctx->data.bin_val.len) { 279 if (ctx->data.bin_val.len) {
diff --git a/include/linux/filter.h b/include/linux/filter.h
index 7977b3958e25..625f4de9bdf2 100644
--- a/include/linux/filter.h
+++ b/include/linux/filter.h
@@ -37,9 +37,6 @@
37#define BPF_CALL 0x80 /* function call */ 37#define BPF_CALL 0x80 /* function call */
38#define BPF_EXIT 0x90 /* function return */ 38#define BPF_EXIT 0x90 /* function return */
39 39
40/* Placeholder/dummy for 0 */
41#define BPF_0 0
42
43/* Register numbers */ 40/* Register numbers */
44enum { 41enum {
45 BPF_REG_0 = 0, 42 BPF_REG_0 = 0,
@@ -191,7 +188,7 @@ int sk_convert_filter(struct sock_filter *prog, int len,
191 struct sock_filter_int *new_prog, int *new_len); 188 struct sock_filter_int *new_prog, int *new_len);
192 189
193int sk_unattached_filter_create(struct sk_filter **pfp, 190int sk_unattached_filter_create(struct sk_filter **pfp,
194 struct sock_fprog *fprog); 191 struct sock_fprog_kern *fprog);
195void sk_unattached_filter_destroy(struct sk_filter *fp); 192void sk_unattached_filter_destroy(struct sk_filter *fp);
196 193
197int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk); 194int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk);
diff --git a/lib/test_bpf.c b/lib/test_bpf.c
index 3d80adbdb559..af677cb718f5 100644
--- a/lib/test_bpf.c
+++ b/lib/test_bpf.c
@@ -22,12 +22,14 @@
22#include <linux/netdevice.h> 22#include <linux/netdevice.h>
23#include <linux/if_vlan.h> 23#include <linux/if_vlan.h>
24 24
25/* General test specific settings */
25#define MAX_SUBTESTS 3 26#define MAX_SUBTESTS 3
27#define MAX_TESTRUNS 10000
26#define MAX_DATA 128 28#define MAX_DATA 128
27#define MAX_INSNS 512 29#define MAX_INSNS 512
28#define MAX_K 0xffffFFFF 30#define MAX_K 0xffffFFFF
29 31
30/* define few constants used to init test 'skb' */ 32/* Few constants used to init test 'skb' */
31#define SKB_TYPE 3 33#define SKB_TYPE 3
32#define SKB_MARK 0x1234aaaa 34#define SKB_MARK 0x1234aaaa
33#define SKB_HASH 0x1234aaab 35#define SKB_HASH 0x1234aaab
@@ -36,18 +38,29 @@
36#define SKB_DEV_IFINDEX 577 38#define SKB_DEV_IFINDEX 577
37#define SKB_DEV_TYPE 588 39#define SKB_DEV_TYPE 588
38 40
39/* redefine REGs to make tests less verbose */ 41/* Redefine REGs to make tests less verbose */
40#define R0 BPF_REG_0 42#define R0 BPF_REG_0
41#define R1 BPF_REG_1 43#define R1 BPF_REG_1
42#define R2 BPF_REG_2 44#define R2 BPF_REG_2
43#define R3 BPF_REG_3 45#define R3 BPF_REG_3
44#define R4 BPF_REG_4 46#define R4 BPF_REG_4
45#define R5 BPF_REG_5 47#define R5 BPF_REG_5
46#define R6 BPF_REG_6 48#define R6 BPF_REG_6
47#define R7 BPF_REG_7 49#define R7 BPF_REG_7
48#define R8 BPF_REG_8 50#define R8 BPF_REG_8
49#define R9 BPF_REG_9 51#define R9 BPF_REG_9
50#define R10 BPF_REG_10 52#define R10 BPF_REG_10
53
54/* Flags that can be passed to test cases */
55#define FLAG_NO_DATA BIT(0)
56#define FLAG_EXPECTED_FAIL BIT(1)
57
58enum {
59 CLASSIC = BIT(6), /* Old BPF instructions only. */
60 INTERNAL = BIT(7), /* Extended instruction set. */
61};
62
63#define TEST_TYPE_MASK (CLASSIC | INTERNAL)
51 64
52struct bpf_test { 65struct bpf_test {
53 const char *descr; 66 const char *descr;
@@ -55,12 +68,7 @@ struct bpf_test {
55 struct sock_filter insns[MAX_INSNS]; 68 struct sock_filter insns[MAX_INSNS];
56 struct sock_filter_int insns_int[MAX_INSNS]; 69 struct sock_filter_int insns_int[MAX_INSNS];
57 } u; 70 } u;
58 enum { 71 __u8 aux;
59 NO_DATA,
60 EXPECTED_FAIL,
61 SKB,
62 SKB_INT
63 } data_type;
64 __u8 data[MAX_DATA]; 72 __u8 data[MAX_DATA];
65 struct { 73 struct {
66 int data_size; 74 int data_size;
@@ -84,7 +92,7 @@ static struct bpf_test tests[] = {
84 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 1), 92 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 1),
85 BPF_STMT(BPF_RET | BPF_A, 0) 93 BPF_STMT(BPF_RET | BPF_A, 0)
86 }, 94 },
87 SKB, 95 CLASSIC,
88 { 10, 20, 30, 40, 50 }, 96 { 10, 20, 30, 40, 50 },
89 { { 2, 10 }, { 3, 20 }, { 4, 30 } }, 97 { { 2, 10 }, { 3, 20 }, { 4, 30 } },
90 }, 98 },
@@ -96,7 +104,7 @@ static struct bpf_test tests[] = {
96 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 104 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
97 BPF_STMT(BPF_RET | BPF_A, 0) /* A == len * 2 */ 105 BPF_STMT(BPF_RET | BPF_A, 0) /* A == len * 2 */
98 }, 106 },
99 SKB, 107 CLASSIC,
100 { 10, 20, 30, 40, 50 }, 108 { 10, 20, 30, 40, 50 },
101 { { 1, 2 }, { 3, 6 }, { 4, 8 } }, 109 { { 1, 2 }, { 3, 6 }, { 4, 8 } },
102 }, 110 },
@@ -111,7 +119,7 @@ static struct bpf_test tests[] = {
111 BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 3), 119 BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 3),
112 BPF_STMT(BPF_RET | BPF_A, 0) 120 BPF_STMT(BPF_RET | BPF_A, 0)
113 }, 121 },
114 0, 122 CLASSIC | FLAG_NO_DATA,
115 { }, 123 { },
116 { { 0, 0xfffffffd } } 124 { { 0, 0xfffffffd } }
117 }, 125 },
@@ -129,7 +137,7 @@ static struct bpf_test tests[] = {
129 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 137 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
130 BPF_STMT(BPF_RET | BPF_A, 0) 138 BPF_STMT(BPF_RET | BPF_A, 0)
131 }, 139 },
132 0, 140 CLASSIC | FLAG_NO_DATA,
133 { }, 141 { },
134 { { 0, 0x40000001 } } 142 { { 0, 0x40000001 } }
135 }, 143 },
@@ -145,7 +153,7 @@ static struct bpf_test tests[] = {
145 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 153 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
146 BPF_STMT(BPF_RET | BPF_A, 0) 154 BPF_STMT(BPF_RET | BPF_A, 0)
147 }, 155 },
148 0, 156 CLASSIC | FLAG_NO_DATA,
149 { }, 157 { },
150 { { 0, 0x800000ff }, { 1, 0x800000ff } }, 158 { { 0, 0x800000ff }, { 1, 0x800000ff } },
151 }, 159 },
@@ -156,7 +164,7 @@ static struct bpf_test tests[] = {
156 BPF_STMT(BPF_LD | BPF_H | BPF_IND, MAX_K), 164 BPF_STMT(BPF_LD | BPF_H | BPF_IND, MAX_K),
157 BPF_STMT(BPF_RET | BPF_K, 1) 165 BPF_STMT(BPF_RET | BPF_K, 1)
158 }, 166 },
159 SKB, 167 CLASSIC,
160 { }, 168 { },
161 { { 1, 0 }, { 10, 0 }, { 60, 0 } }, 169 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
162 }, 170 },
@@ -166,7 +174,7 @@ static struct bpf_test tests[] = {
166 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 1000), 174 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 1000),
167 BPF_STMT(BPF_RET | BPF_K, 1) 175 BPF_STMT(BPF_RET | BPF_K, 1)
168 }, 176 },
169 SKB, 177 CLASSIC,
170 { }, 178 { },
171 { { 1, 0 }, { 10, 0 }, { 60, 0 } }, 179 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
172 }, 180 },
@@ -179,7 +187,7 @@ static struct bpf_test tests[] = {
179 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 187 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
180 BPF_STMT(BPF_RET | BPF_A, 0) 188 BPF_STMT(BPF_RET | BPF_A, 0)
181 }, 189 },
182 SKB, 190 CLASSIC,
183 { 1, 2, 3 }, 191 { 1, 2, 3 },
184 { { 1, 0 }, { 2, 3 } }, 192 { { 1, 0 }, { 2, 3 } },
185 }, 193 },
@@ -193,7 +201,7 @@ static struct bpf_test tests[] = {
193 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0), 201 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
194 BPF_STMT(BPF_RET | BPF_A, 0) 202 BPF_STMT(BPF_RET | BPF_A, 0)
195 }, 203 },
196 SKB, 204 CLASSIC,
197 { 1, 2, 3, 0xff }, 205 { 1, 2, 3, 0xff },
198 { { 1, 1 }, { 3, 3 }, { 4, 0xff } }, 206 { { 1, 1 }, { 3, 3 }, { 4, 0xff } },
199 }, 207 },
@@ -206,7 +214,7 @@ static struct bpf_test tests[] = {
206 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 214 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
207 BPF_STMT(BPF_RET | BPF_A, 0) 215 BPF_STMT(BPF_RET | BPF_A, 0)
208 }, 216 },
209 SKB, 217 CLASSIC,
210 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 }, 218 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
211 { { 15, 0 }, { 16, 3 } }, 219 { { 15, 0 }, { 16, 3 } },
212 }, 220 },
@@ -220,7 +228,7 @@ static struct bpf_test tests[] = {
220 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0), 228 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
221 BPF_STMT(BPF_RET | BPF_A, 0) 229 BPF_STMT(BPF_RET | BPF_A, 0)
222 }, 230 },
223 SKB, 231 CLASSIC,
224 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 }, 232 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
225 { { 14, 0 }, { 15, 1 }, { 17, 3 } }, 233 { { 14, 0 }, { 15, 1 }, { 17, 3 } },
226 }, 234 },
@@ -241,7 +249,7 @@ static struct bpf_test tests[] = {
241 BPF_STMT(BPF_RET | BPF_K, 1), 249 BPF_STMT(BPF_RET | BPF_K, 1),
242 BPF_STMT(BPF_RET | BPF_A, 0) 250 BPF_STMT(BPF_RET | BPF_A, 0)
243 }, 251 },
244 SKB, 252 CLASSIC,
245 { }, 253 { },
246 { { 1, 3 }, { 10, 3 } }, 254 { { 1, 3 }, { 10, 3 } },
247 }, 255 },
@@ -252,7 +260,7 @@ static struct bpf_test tests[] = {
252 SKF_AD_OFF + SKF_AD_MARK), 260 SKF_AD_OFF + SKF_AD_MARK),
253 BPF_STMT(BPF_RET | BPF_A, 0) 261 BPF_STMT(BPF_RET | BPF_A, 0)
254 }, 262 },
255 SKB, 263 CLASSIC,
256 { }, 264 { },
257 { { 1, SKB_MARK}, { 10, SKB_MARK} }, 265 { { 1, SKB_MARK}, { 10, SKB_MARK} },
258 }, 266 },
@@ -263,7 +271,7 @@ static struct bpf_test tests[] = {
263 SKF_AD_OFF + SKF_AD_RXHASH), 271 SKF_AD_OFF + SKF_AD_RXHASH),
264 BPF_STMT(BPF_RET | BPF_A, 0) 272 BPF_STMT(BPF_RET | BPF_A, 0)
265 }, 273 },
266 SKB, 274 CLASSIC,
267 { }, 275 { },
268 { { 1, SKB_HASH}, { 10, SKB_HASH} }, 276 { { 1, SKB_HASH}, { 10, SKB_HASH} },
269 }, 277 },
@@ -274,7 +282,7 @@ static struct bpf_test tests[] = {
274 SKF_AD_OFF + SKF_AD_QUEUE), 282 SKF_AD_OFF + SKF_AD_QUEUE),
275 BPF_STMT(BPF_RET | BPF_A, 0) 283 BPF_STMT(BPF_RET | BPF_A, 0)
276 }, 284 },
277 SKB, 285 CLASSIC,
278 { }, 286 { },
279 { { 1, SKB_QUEUE_MAP }, { 10, SKB_QUEUE_MAP } }, 287 { { 1, SKB_QUEUE_MAP }, { 10, SKB_QUEUE_MAP } },
280 }, 288 },
@@ -293,7 +301,7 @@ static struct bpf_test tests[] = {
293 BPF_STMT(BPF_MISC | BPF_TXA, 0), 301 BPF_STMT(BPF_MISC | BPF_TXA, 0),
294 BPF_STMT(BPF_RET | BPF_A, 0) 302 BPF_STMT(BPF_RET | BPF_A, 0)
295 }, 303 },
296 SKB, 304 CLASSIC,
297 { 10, 20, 30 }, 305 { 10, 20, 30 },
298 { { 10, ETH_P_IP }, { 100, ETH_P_IP } }, 306 { { 10, ETH_P_IP }, { 100, ETH_P_IP } },
299 }, 307 },
@@ -304,7 +312,7 @@ static struct bpf_test tests[] = {
304 SKF_AD_OFF + SKF_AD_VLAN_TAG), 312 SKF_AD_OFF + SKF_AD_VLAN_TAG),
305 BPF_STMT(BPF_RET | BPF_A, 0) 313 BPF_STMT(BPF_RET | BPF_A, 0)
306 }, 314 },
307 SKB, 315 CLASSIC,
308 { }, 316 { },
309 { 317 {
310 { 1, SKB_VLAN_TCI & ~VLAN_TAG_PRESENT }, 318 { 1, SKB_VLAN_TCI & ~VLAN_TAG_PRESENT },
@@ -318,7 +326,7 @@ static struct bpf_test tests[] = {
318 SKF_AD_OFF + SKF_AD_VLAN_TAG_PRESENT), 326 SKF_AD_OFF + SKF_AD_VLAN_TAG_PRESENT),
319 BPF_STMT(BPF_RET | BPF_A, 0) 327 BPF_STMT(BPF_RET | BPF_A, 0)
320 }, 328 },
321 SKB, 329 CLASSIC,
322 { }, 330 { },
323 { 331 {
324 { 1, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) }, 332 { 1, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) },
@@ -332,7 +340,7 @@ static struct bpf_test tests[] = {
332 SKF_AD_OFF + SKF_AD_IFINDEX), 340 SKF_AD_OFF + SKF_AD_IFINDEX),
333 BPF_STMT(BPF_RET | BPF_A, 0) 341 BPF_STMT(BPF_RET | BPF_A, 0)
334 }, 342 },
335 SKB, 343 CLASSIC,
336 { }, 344 { },
337 { { 1, SKB_DEV_IFINDEX }, { 10, SKB_DEV_IFINDEX } }, 345 { { 1, SKB_DEV_IFINDEX }, { 10, SKB_DEV_IFINDEX } },
338 }, 346 },
@@ -343,7 +351,7 @@ static struct bpf_test tests[] = {
343 SKF_AD_OFF + SKF_AD_HATYPE), 351 SKF_AD_OFF + SKF_AD_HATYPE),
344 BPF_STMT(BPF_RET | BPF_A, 0) 352 BPF_STMT(BPF_RET | BPF_A, 0)
345 }, 353 },
346 SKB, 354 CLASSIC,
347 { }, 355 { },
348 { { 1, SKB_DEV_TYPE }, { 10, SKB_DEV_TYPE } }, 356 { { 1, SKB_DEV_TYPE }, { 10, SKB_DEV_TYPE } },
349 }, 357 },
@@ -358,7 +366,7 @@ static struct bpf_test tests[] = {
358 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0), 366 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
359 BPF_STMT(BPF_RET | BPF_A, 0) 367 BPF_STMT(BPF_RET | BPF_A, 0)
360 }, 368 },
361 SKB, 369 CLASSIC,
362 { }, 370 { },
363 { { 1, 0 }, { 10, 0 } }, 371 { { 1, 0 }, { 10, 0 } },
364 }, 372 },
@@ -372,7 +380,7 @@ static struct bpf_test tests[] = {
372 SKF_AD_OFF + SKF_AD_NLATTR), 380 SKF_AD_OFF + SKF_AD_NLATTR),
373 BPF_STMT(BPF_RET | BPF_A, 0) 381 BPF_STMT(BPF_RET | BPF_A, 0)
374 }, 382 },
375 SKB, 383 CLASSIC,
376 { 0xff, 4, 0, 2, 0, 4, 0, 3, 0 }, 384 { 0xff, 4, 0, 2, 0, 4, 0, 3, 0 },
377 { { 4, 0 }, { 20, 5 } }, 385 { { 4, 0 }, { 20, 5 } },
378 }, 386 },
@@ -406,7 +414,7 @@ static struct bpf_test tests[] = {
406 SKF_AD_OFF + SKF_AD_NLATTR_NEST), 414 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
407 BPF_STMT(BPF_RET | BPF_A, 0) 415 BPF_STMT(BPF_RET | BPF_A, 0)
408 }, 416 },
409 SKB, 417 CLASSIC,
410 { 0xff, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3, 0 }, 418 { 0xff, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3, 0 },
411 { { 4, 0 }, { 20, 9 } }, 419 { { 4, 0 }, { 20, 9 } },
412 }, 420 },
@@ -425,7 +433,7 @@ static struct bpf_test tests[] = {
425 SKF_AD_OFF + SKF_AD_PAY_OFFSET), 433 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
426 BPF_STMT(BPF_RET | BPF_A, 0) 434 BPF_STMT(BPF_RET | BPF_A, 0)
427 }, 435 },
428 SKB, 436 CLASSIC,
429 /* 00:00:00:00:00:00 > 00:00:00:00:00:00, ethtype IPv4 (0x0800), 437 /* 00:00:00:00:00:00 > 00:00:00:00:00:00, ethtype IPv4 (0x0800),
430 * length 98: 127.0.0.1 > 127.0.0.1: ICMP echo request, 438 * length 98: 127.0.0.1 > 127.0.0.1: ICMP echo request,
431 * id 9737, seq 1, length 64 439 * id 9737, seq 1, length 64
@@ -446,7 +454,7 @@ static struct bpf_test tests[] = {
446 SKF_AD_OFF + SKF_AD_ALU_XOR_X), 454 SKF_AD_OFF + SKF_AD_ALU_XOR_X),
447 BPF_STMT(BPF_RET | BPF_A, 0) 455 BPF_STMT(BPF_RET | BPF_A, 0)
448 }, 456 },
449 SKB, 457 CLASSIC,
450 { }, 458 { },
451 { { 4, 10 ^ 300 }, { 20, 10 ^ 300 } }, 459 { { 4, 10 ^ 300 }, { 20, 10 ^ 300 } },
452 }, 460 },
@@ -468,7 +476,7 @@ static struct bpf_test tests[] = {
468 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0), 476 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
469 BPF_STMT(BPF_RET | BPF_A, 0) 477 BPF_STMT(BPF_RET | BPF_A, 0)
470 }, 478 },
471 SKB, 479 CLASSIC,
472 { }, 480 { },
473 { { 1, 0x80000001 }, { 2, 0x80000002 }, { 60, 0x80000000 ^ 60 } } 481 { { 1, 0x80000001 }, { 2, 0x80000002 }, { 60, 0x80000000 ^ 60 } }
474 }, 482 },
@@ -481,7 +489,7 @@ static struct bpf_test tests[] = {
481 BPF_STMT(BPF_RET | BPF_K, 1), 489 BPF_STMT(BPF_RET | BPF_K, 1),
482 BPF_STMT(BPF_RET | BPF_K, MAX_K) 490 BPF_STMT(BPF_RET | BPF_K, MAX_K)
483 }, 491 },
484 SKB, 492 CLASSIC,
485 { 3, 3, 3, 3, 3 }, 493 { 3, 3, 3, 3, 3 },
486 { { 1, 0 }, { 3, 1 }, { 4, MAX_K } }, 494 { { 1, 0 }, { 3, 1 }, { 4, MAX_K } },
487 }, 495 },
@@ -494,7 +502,7 @@ static struct bpf_test tests[] = {
494 BPF_STMT(BPF_RET | BPF_K, 1), 502 BPF_STMT(BPF_RET | BPF_K, 1),
495 BPF_STMT(BPF_RET | BPF_K, MAX_K) 503 BPF_STMT(BPF_RET | BPF_K, MAX_K)
496 }, 504 },
497 SKB, 505 CLASSIC,
498 { 4, 4, 4, 3, 3 }, 506 { 4, 4, 4, 3, 3 },
499 { { 2, 0 }, { 3, 1 }, { 4, MAX_K } }, 507 { { 2, 0 }, { 3, 1 }, { 4, MAX_K } },
500 }, 508 },
@@ -513,7 +521,7 @@ static struct bpf_test tests[] = {
513 BPF_STMT(BPF_RET | BPF_K, 40), 521 BPF_STMT(BPF_RET | BPF_K, 40),
514 BPF_STMT(BPF_RET | BPF_K, MAX_K) 522 BPF_STMT(BPF_RET | BPF_K, MAX_K)
515 }, 523 },
516 SKB, 524 CLASSIC,
517 { 1, 2, 3, 4, 5 }, 525 { 1, 2, 3, 4, 5 },
518 { { 1, 20 }, { 3, 40 }, { 5, MAX_K } }, 526 { { 1, 20 }, { 3, 40 }, { 5, MAX_K } },
519 }, 527 },
@@ -545,7 +553,7 @@ static struct bpf_test tests[] = {
545 BPF_STMT(BPF_RET | BPF_K, 30), 553 BPF_STMT(BPF_RET | BPF_K, 30),
546 BPF_STMT(BPF_RET | BPF_K, MAX_K) 554 BPF_STMT(BPF_RET | BPF_K, MAX_K)
547 }, 555 },
548 SKB, 556 CLASSIC,
549 { 0, 0xAA, 0x55, 1 }, 557 { 0, 0xAA, 0x55, 1 },
550 { { 4, 10 }, { 5, 20 }, { 6, MAX_K } }, 558 { { 4, 10 }, { 5, 20 }, { 6, MAX_K } },
551 }, 559 },
@@ -577,7 +585,7 @@ static struct bpf_test tests[] = {
577 { 0x06, 0, 0, 0x0000ffff }, 585 { 0x06, 0, 0, 0x0000ffff },
578 { 0x06, 0, 0, 0x00000000 }, 586 { 0x06, 0, 0, 0x00000000 },
579 }, 587 },
580 SKB, 588 CLASSIC,
581 /* 3c:07:54:43:e5:76 > 10:bf:48:d6:43:d6, ethertype IPv4(0x0800) 589 /* 3c:07:54:43:e5:76 > 10:bf:48:d6:43:d6, ethertype IPv4(0x0800)
582 * length 114: 10.1.1.149.49700 > 10.1.2.10.22: Flags [P.], 590 * length 114: 10.1.1.149.49700 > 10.1.2.10.22: Flags [P.],
583 * seq 1305692979:1305693027, ack 3650467037, win 65535, 591 * seq 1305692979:1305693027, ack 3650467037, win 65535,
@@ -635,7 +643,7 @@ static struct bpf_test tests[] = {
635 { 0x06, 0, 0, 0x0000ffff }, 643 { 0x06, 0, 0, 0x0000ffff },
636 { 0x06, 0, 0, 0x00000000 }, 644 { 0x06, 0, 0, 0x00000000 },
637 }, 645 },
638 SKB, 646 CLASSIC,
639 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6, 647 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
640 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76, 648 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
641 0x08, 0x00, 649 0x08, 0x00,
@@ -654,8 +662,8 @@ static struct bpf_test tests[] = {
654 BPF_STMT(BPF_MISC | BPF_TXA, 0), 662 BPF_STMT(BPF_MISC | BPF_TXA, 0),
655 BPF_STMT(BPF_RET | BPF_A, 0) 663 BPF_STMT(BPF_RET | BPF_A, 0)
656 }, 664 },
657 SKB, 665 CLASSIC,
658 {}, 666 { },
659 { {1, 0}, {2, 0} }, 667 { {1, 0}, {2, 0} },
660 }, 668 },
661 { 669 {
@@ -670,7 +678,7 @@ static struct bpf_test tests[] = {
670 BPF_ALU64_REG(BPF_MOV, R0, R1), 678 BPF_ALU64_REG(BPF_MOV, R0, R1),
671 BPF_EXIT_INSN(), 679 BPF_EXIT_INSN(),
672 }, 680 },
673 SKB_INT, 681 INTERNAL,
674 { }, 682 { },
675 { { 0, 0xfffffffd } } 683 { { 0, 0xfffffffd } }
676 }, 684 },
@@ -686,7 +694,7 @@ static struct bpf_test tests[] = {
686 BPF_ALU64_IMM(BPF_MOV, R0, 1), 694 BPF_ALU64_IMM(BPF_MOV, R0, 1),
687 BPF_EXIT_INSN(), 695 BPF_EXIT_INSN(),
688 }, 696 },
689 SKB_INT, 697 INTERNAL,
690 { }, 698 { },
691 { { 0, 1 } } 699 { { 0, 1 } }
692 }, 700 },
@@ -703,7 +711,7 @@ static struct bpf_test tests[] = {
703 BPF_ALU32_IMM(BPF_MOV, R0, 1), 711 BPF_ALU32_IMM(BPF_MOV, R0, 1),
704 BPF_EXIT_INSN(), 712 BPF_EXIT_INSN(),
705 }, 713 },
706 SKB_INT, 714 INTERNAL,
707 { }, 715 { },
708 { { 0, 1 } } 716 { { 0, 1 } }
709 }, 717 },
@@ -720,7 +728,7 @@ static struct bpf_test tests[] = {
720 BPF_ALU32_IMM(BPF_MOV, R0, 1), 728 BPF_ALU32_IMM(BPF_MOV, R0, 1),
721 BPF_EXIT_INSN(), 729 BPF_EXIT_INSN(),
722 }, 730 },
723 SKB_INT, 731 INTERNAL,
724 { }, 732 { },
725 { { 0, 1 } } 733 { { 0, 1 } }
726 }, 734 },
@@ -882,7 +890,7 @@ static struct bpf_test tests[] = {
882 BPF_ALU64_REG(BPF_MOV, R0, R9), 890 BPF_ALU64_REG(BPF_MOV, R0, R9),
883 BPF_EXIT_INSN(), 891 BPF_EXIT_INSN(),
884 }, 892 },
885 SKB_INT, 893 INTERNAL,
886 { }, 894 { },
887 { { 0, 2957380 } } 895 { { 0, 2957380 } }
888 }, 896 },
@@ -1028,7 +1036,7 @@ static struct bpf_test tests[] = {
1028 BPF_ALU32_REG(BPF_MOV, R0, R9), 1036 BPF_ALU32_REG(BPF_MOV, R0, R9),
1029 BPF_EXIT_INSN(), 1037 BPF_EXIT_INSN(),
1030 }, 1038 },
1031 SKB_INT, 1039 INTERNAL,
1032 { }, 1040 { },
1033 { { 0, 2957380 } } 1041 { { 0, 2957380 } }
1034 }, 1042 },
@@ -1161,7 +1169,7 @@ static struct bpf_test tests[] = {
1161 BPF_ALU64_REG(BPF_SUB, R0, R9), 1169 BPF_ALU64_REG(BPF_SUB, R0, R9),
1162 BPF_EXIT_INSN(), 1170 BPF_EXIT_INSN(),
1163 }, 1171 },
1164 SKB_INT, 1172 INTERNAL,
1165 { }, 1173 { },
1166 { { 0, 11 } } 1174 { { 0, 11 } }
1167 }, 1175 },
@@ -1227,7 +1235,7 @@ static struct bpf_test tests[] = {
1227 BPF_ALU64_IMM(BPF_MOV, R0, 1), 1235 BPF_ALU64_IMM(BPF_MOV, R0, 1),
1228 BPF_EXIT_INSN(), 1236 BPF_EXIT_INSN(),
1229 }, 1237 },
1230 SKB_INT, 1238 INTERNAL,
1231 { }, 1239 { },
1232 { { 0, 1 } } 1240 { { 0, 1 } }
1233 }, 1241 },
@@ -1289,7 +1297,7 @@ static struct bpf_test tests[] = {
1289 BPF_ALU64_REG(BPF_MOV, R0, R2), 1297 BPF_ALU64_REG(BPF_MOV, R0, R2),
1290 BPF_EXIT_INSN(), 1298 BPF_EXIT_INSN(),
1291 }, 1299 },
1292 SKB_INT, 1300 INTERNAL,
1293 { }, 1301 { },
1294 { { 0, 0x35d97ef2 } } 1302 { { 0, 0x35d97ef2 } }
1295 }, 1303 },
@@ -1309,7 +1317,7 @@ static struct bpf_test tests[] = {
1309 BPF_ALU64_IMM(BPF_MOV, R0, -1), 1317 BPF_ALU64_IMM(BPF_MOV, R0, -1),
1310 BPF_EXIT_INSN(), 1318 BPF_EXIT_INSN(),
1311 }, 1319 },
1312 SKB_INT, 1320 INTERNAL,
1313 { }, 1321 { },
1314 { { 0, -1 } } 1322 { { 0, -1 } }
1315 }, 1323 },
@@ -1326,7 +1334,7 @@ static struct bpf_test tests[] = {
1326 BPF_LD_IND(BPF_B, R8, -70), 1334 BPF_LD_IND(BPF_B, R8, -70),
1327 BPF_EXIT_INSN(), 1335 BPF_EXIT_INSN(),
1328 }, 1336 },
1329 SKB_INT, 1337 INTERNAL,
1330 { 10, 20, 30, 40, 50 }, 1338 { 10, 20, 30, 40, 50 },
1331 { { 4, 0 }, { 5, 10 } } 1339 { { 4, 0 }, { 5, 10 } }
1332 }, 1340 },
@@ -1339,7 +1347,7 @@ static struct bpf_test tests[] = {
1339 BPF_ALU32_REG(BPF_DIV, R0, R7), 1347 BPF_ALU32_REG(BPF_DIV, R0, R7),
1340 BPF_EXIT_INSN(), 1348 BPF_EXIT_INSN(),
1341 }, 1349 },
1342 SKB_INT, 1350 INTERNAL,
1343 { 10, 20, 30, 40, 50 }, 1351 { 10, 20, 30, 40, 50 },
1344 { { 3, 0 }, { 4, 0 } } 1352 { { 3, 0 }, { 4, 0 } }
1345 }, 1353 },
@@ -1348,7 +1356,7 @@ static struct bpf_test tests[] = {
1348 .u.insns = { 1356 .u.insns = {
1349 BPF_STMT(BPF_LD | BPF_IMM, 1), 1357 BPF_STMT(BPF_LD | BPF_IMM, 1),
1350 }, 1358 },
1351 EXPECTED_FAIL, 1359 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
1352 { }, 1360 { },
1353 { } 1361 { }
1354 }, 1362 },
@@ -1358,7 +1366,7 @@ static struct bpf_test tests[] = {
1358 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0), 1366 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0),
1359 BPF_STMT(BPF_RET | BPF_K, 0) 1367 BPF_STMT(BPF_RET | BPF_K, 0)
1360 }, 1368 },
1361 EXPECTED_FAIL, 1369 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
1362 { }, 1370 { },
1363 { } 1371 { }
1364 }, 1372 },
@@ -1369,7 +1377,7 @@ static struct bpf_test tests[] = {
1369 BPF_STMT(BPF_LDX | BPF_W | BPF_ABS, 0), 1377 BPF_STMT(BPF_LDX | BPF_W | BPF_ABS, 0),
1370 BPF_STMT(BPF_RET | BPF_K, 0) 1378 BPF_STMT(BPF_RET | BPF_K, 0)
1371 }, 1379 },
1372 EXPECTED_FAIL, 1380 CLASSIC | FLAG_EXPECTED_FAIL,
1373 { }, 1381 { },
1374 { } 1382 { }
1375 }, 1383 },
@@ -1379,26 +1387,109 @@ static struct bpf_test tests[] = {
1379 BPF_STMT(BPF_STX, 16), 1387 BPF_STMT(BPF_STX, 16),
1380 BPF_STMT(BPF_RET | BPF_K, 0) 1388 BPF_STMT(BPF_RET | BPF_K, 0)
1381 }, 1389 },
1382 EXPECTED_FAIL, 1390 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
1383 { }, 1391 { },
1384 { } 1392 { }
1385 }, 1393 },
1394 {
1395 "JUMPS + HOLES",
1396 .u.insns = {
1397 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1398 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 15),
1399 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1400 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1401 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1402 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1403 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1404 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1405 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1406 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1407 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1408 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1409 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1410 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1411 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1412 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 3, 4),
1413 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1414 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 1, 2),
1415 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1416 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
1417 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
1418 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1419 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1420 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1421 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1422 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1423 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1424 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1425 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1426 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1427 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1428 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1429 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1430 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1431 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 2, 3),
1432 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 1, 2),
1433 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1434 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
1435 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
1436 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1437 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1438 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1439 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1440 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1441 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1442 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1443 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1444 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1445 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1446 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1447 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1448 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1449 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 2, 3),
1450 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 1, 2),
1451 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1452 BPF_STMT(BPF_RET | BPF_A, 0),
1453 BPF_STMT(BPF_RET | BPF_A, 0),
1454 },
1455 CLASSIC,
1456 { 0x00, 0x1b, 0x21, 0x3c, 0x9d, 0xf8, 0x90, 0xe2,
1457 0xba, 0x0a, 0x56, 0xb4, 0x08, 0x00, 0x45, 0x00,
1458 0x00, 0x28, 0x00, 0x00, 0x20, 0x00, 0x40, 0x11,
1459 0x00, 0x00, 0xc0, 0xa8, 0x33, 0x01, 0xc0, 0xa8,
1460 0x33, 0x02, 0xbb, 0xb6, 0xa9, 0xfa, 0x00, 0x14,
1461 0x00, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1462 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1463 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1464 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1465 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1466 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc },
1467 { { 88, 0x001b } }
1468 },
1469 {
1470 "check: RET X",
1471 .u.insns = {
1472 BPF_STMT(BPF_RET | BPF_X, 0),
1473 },
1474 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
1475 { },
1476 { },
1477 },
1478 {
1479 "check: LDX + RET X",
1480 .u.insns = {
1481 BPF_STMT(BPF_LDX | BPF_IMM, 42),
1482 BPF_STMT(BPF_RET | BPF_X, 0),
1483 },
1484 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
1485 { },
1486 { },
1487 },
1386}; 1488};
1387 1489
1388static int get_length(struct sock_filter *fp) 1490static struct net_device dev;
1389{
1390 int len = 0;
1391
1392 while (fp->code != 0 || fp->k != 0) {
1393 fp++;
1394 len++;
1395 }
1396
1397 return len;
1398}
1399 1491
1400struct net_device dev; 1492static struct sk_buff *populate_skb(char *buf, int size)
1401struct sk_buff *populate_skb(char *buf, int size)
1402{ 1493{
1403 struct sk_buff *skb; 1494 struct sk_buff *skb;
1404 1495
@@ -1410,6 +1501,8 @@ struct sk_buff *populate_skb(char *buf, int size)
1410 return NULL; 1501 return NULL;
1411 1502
1412 memcpy(__skb_put(skb, size), buf, size); 1503 memcpy(__skb_put(skb, size), buf, size);
1504
1505 /* Initialize a fake skb with test pattern. */
1413 skb_reset_mac_header(skb); 1506 skb_reset_mac_header(skb);
1414 skb->protocol = htons(ETH_P_IP); 1507 skb->protocol = htons(ETH_P_IP);
1415 skb->pkt_type = SKB_TYPE; 1508 skb->pkt_type = SKB_TYPE;
@@ -1425,43 +1518,149 @@ struct sk_buff *populate_skb(char *buf, int size)
1425 return skb; 1518 return skb;
1426} 1519}
1427 1520
1428static int run_one(struct sk_filter *fp, struct bpf_test *t) 1521static void *generate_test_data(struct bpf_test *test, int sub)
1429{ 1522{
1430 u64 start, finish, res, cnt = 100000; 1523 if (test->aux & FLAG_NO_DATA)
1431 int err_cnt = 0, err, i, j; 1524 return NULL;
1432 u32 ret = 0;
1433 void *data;
1434 1525
1435 for (i = 0; i < MAX_SUBTESTS; i++) { 1526 /* Test case expects an skb, so populate one. Various
1436 if (t->test[i].data_size == 0 && 1527 * subtests generate skbs of different sizes based on
1437 t->test[i].result == 0) 1528 * the same data.
1438 break; 1529 */
1439 if (t->data_type == SKB || 1530 return populate_skb(test->data, test->test[sub].data_size);
1440 t->data_type == SKB_INT) { 1531}
1441 data = populate_skb(t->data, t->test[i].data_size); 1532
1442 if (!data) 1533static void release_test_data(const struct bpf_test *test, void *data)
1443 return -ENOMEM; 1534{
1444 } else { 1535 if (test->aux & FLAG_NO_DATA)
1445 data = NULL; 1536 return;
1537
1538 kfree_skb(data);
1539}
1540
1541static int probe_filter_length(struct sock_filter *fp)
1542{
1543 int len = 0;
1544
1545 while (fp->code != 0 || fp->k != 0) {
1546 fp++;
1547 len++;
1548 }
1549
1550 return len;
1551}
1552
1553static struct sk_filter *generate_filter(int which, int *err)
1554{
1555 struct sk_filter *fp;
1556 struct sock_fprog_kern fprog;
1557 unsigned int flen = probe_filter_length(tests[which].u.insns);
1558 __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
1559
1560 switch (test_type) {
1561 case CLASSIC:
1562 fprog.filter = tests[which].u.insns;
1563 fprog.len = flen;
1564
1565 *err = sk_unattached_filter_create(&fp, &fprog);
1566 if (tests[which].aux & FLAG_EXPECTED_FAIL) {
1567 if (*err == -EINVAL) {
1568 pr_cont("PASS\n");
1569 /* Verifier rejected filter as expected. */
1570 *err = 0;
1571 return NULL;
1572 } else {
1573 pr_cont("UNEXPECTED_PASS\n");
1574 /* Verifier didn't reject the test that's
1575 * bad enough, just return!
1576 */
1577 *err = -EINVAL;
1578 return NULL;
1579 }
1580 }
1581 /* We don't expect to fail. */
1582 if (*err) {
1583 pr_cont("FAIL to attach err=%d len=%d\n",
1584 *err, fprog.len);
1585 return NULL;
1446 } 1586 }
1587 break;
1447 1588
1448 start = ktime_to_us(ktime_get()); 1589 case INTERNAL:
1449 for (j = 0; j < cnt; j++) 1590 fp = kzalloc(sk_filter_size(flen), GFP_KERNEL);
1450 ret = SK_RUN_FILTER(fp, data); 1591 if (fp == NULL) {
1451 finish = ktime_to_us(ktime_get()); 1592 pr_cont("UNEXPECTED_FAIL no memory left\n");
1593 *err = -ENOMEM;
1594 return NULL;
1595 }
1596
1597 fp->len = flen;
1598 memcpy(fp->insnsi, tests[which].u.insns_int,
1599 fp->len * sizeof(struct sock_filter_int));
1452 1600
1453 res = (finish - start) * 1000; 1601 sk_filter_select_runtime(fp);
1454 do_div(res, cnt); 1602 break;
1603 }
1455 1604
1456 err = ret != t->test[i].result; 1605 *err = 0;
1457 if (!err) 1606 return fp;
1458 pr_cont("%lld ", res); 1607}
1459 1608
1460 if (t->data_type == SKB || t->data_type == SKB_INT) 1609static void release_filter(struct sk_filter *fp, int which)
1461 kfree_skb(data); 1610{
1611 __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
1462 1612
1463 if (err) { 1613 switch (test_type) {
1464 pr_cont("ret %d != %d ", ret, t->test[i].result); 1614 case CLASSIC:
1615 sk_unattached_filter_destroy(fp);
1616 break;
1617 case INTERNAL:
1618 sk_filter_free(fp);
1619 break;
1620 }
1621}
1622
1623static int __run_one(const struct sk_filter *fp, const void *data,
1624 int runs, u64 *duration)
1625{
1626 u64 start, finish;
1627 int ret, i;
1628
1629 start = ktime_to_us(ktime_get());
1630
1631 for (i = 0; i < runs; i++)
1632 ret = SK_RUN_FILTER(fp, data);
1633
1634 finish = ktime_to_us(ktime_get());
1635
1636 *duration = (finish - start) * 1000ULL;
1637 do_div(*duration, runs);
1638
1639 return ret;
1640}
1641
1642static int run_one(const struct sk_filter *fp, struct bpf_test *test)
1643{
1644 int err_cnt = 0, i, runs = MAX_TESTRUNS;
1645
1646 for (i = 0; i < MAX_SUBTESTS; i++) {
1647 void *data;
1648 u64 duration;
1649 u32 ret;
1650
1651 if (test->test[i].data_size == 0 &&
1652 test->test[i].result == 0)
1653 break;
1654
1655 data = generate_test_data(test, i);
1656 ret = __run_one(fp, data, runs, &duration);
1657 release_test_data(test, data);
1658
1659 if (ret == test->test[i].result) {
1660 pr_cont("%lld ", duration);
1661 } else {
1662 pr_cont("ret %d != %d ", ret,
1663 test->test[i].result);
1465 err_cnt++; 1664 err_cnt++;
1466 } 1665 }
1467 } 1666 }
@@ -1471,65 +1670,37 @@ static int run_one(struct sk_filter *fp, struct bpf_test *t)
1471 1670
1472static __init int test_bpf(void) 1671static __init int test_bpf(void)
1473{ 1672{
1474 struct sk_filter *fp, *fp_ext = NULL; 1673 int i, err_cnt = 0, pass_cnt = 0;
1475 struct sock_fprog fprog;
1476 int err, i, err_cnt = 0;
1477 1674
1478 for (i = 0; i < ARRAY_SIZE(tests); i++) { 1675 for (i = 0; i < ARRAY_SIZE(tests); i++) {
1479 pr_info("#%d %s ", i, tests[i].descr); 1676 struct sk_filter *fp;
1677 int err;
1480 1678
1481 fprog.filter = tests[i].u.insns; 1679 pr_info("#%d %s ", i, tests[i].descr);
1482 fprog.len = get_length(fprog.filter);
1483 1680
1484 if (tests[i].data_type == SKB_INT) { 1681 fp = generate_filter(i, &err);
1485 fp_ext = kzalloc(4096, GFP_KERNEL); 1682 if (fp == NULL) {
1486 if (!fp_ext) 1683 if (err == 0) {
1487 return -ENOMEM; 1684 pass_cnt++;
1488 fp = fp_ext; 1685 continue;
1489 memcpy(fp_ext->insns, tests[i].u.insns_int,
1490 fprog.len * 8);
1491 fp->len = fprog.len;
1492 sk_filter_select_runtime(fp);
1493 } else {
1494 err = sk_unattached_filter_create(&fp, &fprog);
1495 if (tests[i].data_type == EXPECTED_FAIL) {
1496 if (err == -EINVAL) {
1497 pr_cont("PASS\n");
1498 continue;
1499 } else {
1500 pr_cont("UNEXPECTED_PASS\n");
1501 /* verifier didn't reject the test
1502 * that's bad enough, just return
1503 */
1504 return -EINVAL;
1505 }
1506 } 1686 }
1507 if (err) {
1508 pr_cont("FAIL to attach err=%d len=%d\n",
1509 err, fprog.len);
1510 return err;
1511 }
1512 }
1513 1687
1688 return err;
1689 }
1514 err = run_one(fp, &tests[i]); 1690 err = run_one(fp, &tests[i]);
1515 1691 release_filter(fp, i);
1516 if (tests[i].data_type != SKB_INT)
1517 sk_unattached_filter_destroy(fp);
1518 else
1519 sk_filter_free(fp);
1520 1692
1521 if (err) { 1693 if (err) {
1522 pr_cont("FAIL %d\n", err); 1694 pr_cont("FAIL (%d times)\n", err);
1523 err_cnt++; 1695 err_cnt++;
1524 } else { 1696 } else {
1525 pr_cont("PASS\n"); 1697 pr_cont("PASS\n");
1698 pass_cnt++;
1526 } 1699 }
1527 } 1700 }
1528 1701
1529 if (err_cnt) 1702 pr_info("Summary: %d PASSED, %d FAILED\n", pass_cnt, err_cnt);
1530 return -EINVAL; 1703 return err_cnt ? -EINVAL : 0;
1531 else
1532 return 0;
1533} 1704}
1534 1705
1535static int __init test_bpf_init(void) 1706static int __init test_bpf_init(void)
@@ -1543,4 +1714,5 @@ static void __exit test_bpf_exit(void)
1543 1714
1544module_init(test_bpf_init); 1715module_init(test_bpf_init);
1545module_exit(test_bpf_exit); 1716module_exit(test_bpf_exit);
1717
1546MODULE_LICENSE("GPL"); 1718MODULE_LICENSE("GPL");
diff --git a/net/core/filter.c b/net/core/filter.c
index 7067cb240d3e..2c2d35d9d101 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -160,95 +160,100 @@ static unsigned int __sk_run_filter(void *ctx, const struct sock_filter_int *ins
160 static const void *jumptable[256] = { 160 static const void *jumptable[256] = {
161 [0 ... 255] = &&default_label, 161 [0 ... 255] = &&default_label,
162 /* Now overwrite non-defaults ... */ 162 /* Now overwrite non-defaults ... */
163#define DL(A, B, C) [BPF_##A|BPF_##B|BPF_##C] = &&A##_##B##_##C 163 /* 32 bit ALU operations */
164 DL(ALU, ADD, X), 164 [BPF_ALU | BPF_ADD | BPF_X] = &&ALU_ADD_X,
165 DL(ALU, ADD, K), 165 [BPF_ALU | BPF_ADD | BPF_K] = &&ALU_ADD_K,
166 DL(ALU, SUB, X), 166 [BPF_ALU | BPF_SUB | BPF_X] = &&ALU_SUB_X,
167 DL(ALU, SUB, K), 167 [BPF_ALU | BPF_SUB | BPF_K] = &&ALU_SUB_K,
168 DL(ALU, AND, X), 168 [BPF_ALU | BPF_AND | BPF_X] = &&ALU_AND_X,
169 DL(ALU, AND, K), 169 [BPF_ALU | BPF_AND | BPF_K] = &&ALU_AND_K,
170 DL(ALU, OR, X), 170 [BPF_ALU | BPF_OR | BPF_X] = &&ALU_OR_X,
171 DL(ALU, OR, K), 171 [BPF_ALU | BPF_OR | BPF_K] = &&ALU_OR_K,
172 DL(ALU, LSH, X), 172 [BPF_ALU | BPF_LSH | BPF_X] = &&ALU_LSH_X,
173 DL(ALU, LSH, K), 173 [BPF_ALU | BPF_LSH | BPF_K] = &&ALU_LSH_K,
174 DL(ALU, RSH, X), 174 [BPF_ALU | BPF_RSH | BPF_X] = &&ALU_RSH_X,
175 DL(ALU, RSH, K), 175 [BPF_ALU | BPF_RSH | BPF_K] = &&ALU_RSH_K,
176 DL(ALU, XOR, X), 176 [BPF_ALU | BPF_XOR | BPF_X] = &&ALU_XOR_X,
177 DL(ALU, XOR, K), 177 [BPF_ALU | BPF_XOR | BPF_K] = &&ALU_XOR_K,
178 DL(ALU, MUL, X), 178 [BPF_ALU | BPF_MUL | BPF_X] = &&ALU_MUL_X,
179 DL(ALU, MUL, K), 179 [BPF_ALU | BPF_MUL | BPF_K] = &&ALU_MUL_K,
180 DL(ALU, MOV, X), 180 [BPF_ALU | BPF_MOV | BPF_X] = &&ALU_MOV_X,
181 DL(ALU, MOV, K), 181 [BPF_ALU | BPF_MOV | BPF_K] = &&ALU_MOV_K,
182 DL(ALU, DIV, X), 182 [BPF_ALU | BPF_DIV | BPF_X] = &&ALU_DIV_X,
183 DL(ALU, DIV, K), 183 [BPF_ALU | BPF_DIV | BPF_K] = &&ALU_DIV_K,
184 DL(ALU, MOD, X), 184 [BPF_ALU | BPF_MOD | BPF_X] = &&ALU_MOD_X,
185 DL(ALU, MOD, K), 185 [BPF_ALU | BPF_MOD | BPF_K] = &&ALU_MOD_K,
186 DL(ALU, NEG, 0), 186 [BPF_ALU | BPF_NEG] = &&ALU_NEG,
187 DL(ALU, END, TO_BE), 187 [BPF_ALU | BPF_END | BPF_TO_BE] = &&ALU_END_TO_BE,
188 DL(ALU, END, TO_LE), 188 [BPF_ALU | BPF_END | BPF_TO_LE] = &&ALU_END_TO_LE,
189 DL(ALU64, ADD, X), 189 /* 64 bit ALU operations */
190 DL(ALU64, ADD, K), 190 [BPF_ALU64 | BPF_ADD | BPF_X] = &&ALU64_ADD_X,
191 DL(ALU64, SUB, X), 191 [BPF_ALU64 | BPF_ADD | BPF_K] = &&ALU64_ADD_K,
192 DL(ALU64, SUB, K), 192 [BPF_ALU64 | BPF_SUB | BPF_X] = &&ALU64_SUB_X,
193 DL(ALU64, AND, X), 193 [BPF_ALU64 | BPF_SUB | BPF_K] = &&ALU64_SUB_K,
194 DL(ALU64, AND, K), 194 [BPF_ALU64 | BPF_AND | BPF_X] = &&ALU64_AND_X,
195 DL(ALU64, OR, X), 195 [BPF_ALU64 | BPF_AND | BPF_K] = &&ALU64_AND_K,
196 DL(ALU64, OR, K), 196 [BPF_ALU64 | BPF_OR | BPF_X] = &&ALU64_OR_X,
197 DL(ALU64, LSH, X), 197 [BPF_ALU64 | BPF_OR | BPF_K] = &&ALU64_OR_K,
198 DL(ALU64, LSH, K), 198 [BPF_ALU64 | BPF_LSH | BPF_X] = &&ALU64_LSH_X,
199 DL(ALU64, RSH, X), 199 [BPF_ALU64 | BPF_LSH | BPF_K] = &&ALU64_LSH_K,
200 DL(ALU64, RSH, K), 200 [BPF_ALU64 | BPF_RSH | BPF_X] = &&ALU64_RSH_X,
201 DL(ALU64, XOR, X), 201 [BPF_ALU64 | BPF_RSH | BPF_K] = &&ALU64_RSH_K,
202 DL(ALU64, XOR, K), 202 [BPF_ALU64 | BPF_XOR | BPF_X] = &&ALU64_XOR_X,
203 DL(ALU64, MUL, X), 203 [BPF_ALU64 | BPF_XOR | BPF_K] = &&ALU64_XOR_K,
204 DL(ALU64, MUL, K), 204 [BPF_ALU64 | BPF_MUL | BPF_X] = &&ALU64_MUL_X,
205 DL(ALU64, MOV, X), 205 [BPF_ALU64 | BPF_MUL | BPF_K] = &&ALU64_MUL_K,
206 DL(ALU64, MOV, K), 206 [BPF_ALU64 | BPF_MOV | BPF_X] = &&ALU64_MOV_X,
207 DL(ALU64, ARSH, X), 207 [BPF_ALU64 | BPF_MOV | BPF_K] = &&ALU64_MOV_K,
208 DL(ALU64, ARSH, K), 208 [BPF_ALU64 | BPF_ARSH | BPF_X] = &&ALU64_ARSH_X,
209 DL(ALU64, DIV, X), 209 [BPF_ALU64 | BPF_ARSH | BPF_K] = &&ALU64_ARSH_K,
210 DL(ALU64, DIV, K), 210 [BPF_ALU64 | BPF_DIV | BPF_X] = &&ALU64_DIV_X,
211 DL(ALU64, MOD, X), 211 [BPF_ALU64 | BPF_DIV | BPF_K] = &&ALU64_DIV_K,
212 DL(ALU64, MOD, K), 212 [BPF_ALU64 | BPF_MOD | BPF_X] = &&ALU64_MOD_X,
213 DL(ALU64, NEG, 0), 213 [BPF_ALU64 | BPF_MOD | BPF_K] = &&ALU64_MOD_K,
214 DL(JMP, CALL, 0), 214 [BPF_ALU64 | BPF_NEG] = &&ALU64_NEG,
215 DL(JMP, JA, 0), 215 /* Call instruction */
216 DL(JMP, JEQ, X), 216 [BPF_JMP | BPF_CALL] = &&JMP_CALL,
217 DL(JMP, JEQ, K), 217 /* Jumps */
218 DL(JMP, JNE, X), 218 [BPF_JMP | BPF_JA] = &&JMP_JA,
219 DL(JMP, JNE, K), 219 [BPF_JMP | BPF_JEQ | BPF_X] = &&JMP_JEQ_X,
220 DL(JMP, JGT, X), 220 [BPF_JMP | BPF_JEQ | BPF_K] = &&JMP_JEQ_K,
221 DL(JMP, JGT, K), 221 [BPF_JMP | BPF_JNE | BPF_X] = &&JMP_JNE_X,
222 DL(JMP, JGE, X), 222 [BPF_JMP | BPF_JNE | BPF_K] = &&JMP_JNE_K,
223 DL(JMP, JGE, K), 223 [BPF_JMP | BPF_JGT | BPF_X] = &&JMP_JGT_X,
224 DL(JMP, JSGT, X), 224 [BPF_JMP | BPF_JGT | BPF_K] = &&JMP_JGT_K,
225 DL(JMP, JSGT, K), 225 [BPF_JMP | BPF_JGE | BPF_X] = &&JMP_JGE_X,
226 DL(JMP, JSGE, X), 226 [BPF_JMP | BPF_JGE | BPF_K] = &&JMP_JGE_K,
227 DL(JMP, JSGE, K), 227 [BPF_JMP | BPF_JSGT | BPF_X] = &&JMP_JSGT_X,
228 DL(JMP, JSET, X), 228 [BPF_JMP | BPF_JSGT | BPF_K] = &&JMP_JSGT_K,
229 DL(JMP, JSET, K), 229 [BPF_JMP | BPF_JSGE | BPF_X] = &&JMP_JSGE_X,
230 DL(JMP, EXIT, 0), 230 [BPF_JMP | BPF_JSGE | BPF_K] = &&JMP_JSGE_K,
231 DL(STX, MEM, B), 231 [BPF_JMP | BPF_JSET | BPF_X] = &&JMP_JSET_X,
232 DL(STX, MEM, H), 232 [BPF_JMP | BPF_JSET | BPF_K] = &&JMP_JSET_K,
233 DL(STX, MEM, W), 233 /* Program return */
234 DL(STX, MEM, DW), 234 [BPF_JMP | BPF_EXIT] = &&JMP_EXIT,
235 DL(STX, XADD, W), 235 /* Store instructions */
236 DL(STX, XADD, DW), 236 [BPF_STX | BPF_MEM | BPF_B] = &&STX_MEM_B,
237 DL(ST, MEM, B), 237 [BPF_STX | BPF_MEM | BPF_H] = &&STX_MEM_H,
238 DL(ST, MEM, H), 238 [BPF_STX | BPF_MEM | BPF_W] = &&STX_MEM_W,
239 DL(ST, MEM, W), 239 [BPF_STX | BPF_MEM | BPF_DW] = &&STX_MEM_DW,
240 DL(ST, MEM, DW), 240 [BPF_STX | BPF_XADD | BPF_W] = &&STX_XADD_W,
241 DL(LDX, MEM, B), 241 [BPF_STX | BPF_XADD | BPF_DW] = &&STX_XADD_DW,
242 DL(LDX, MEM, H), 242 [BPF_ST | BPF_MEM | BPF_B] = &&ST_MEM_B,
243 DL(LDX, MEM, W), 243 [BPF_ST | BPF_MEM | BPF_H] = &&ST_MEM_H,
244 DL(LDX, MEM, DW), 244 [BPF_ST | BPF_MEM | BPF_W] = &&ST_MEM_W,
245 DL(LD, ABS, W), 245 [BPF_ST | BPF_MEM | BPF_DW] = &&ST_MEM_DW,
246 DL(LD, ABS, H), 246 /* Load instructions */
247 DL(LD, ABS, B), 247 [BPF_LDX | BPF_MEM | BPF_B] = &&LDX_MEM_B,
248 DL(LD, IND, W), 248 [BPF_LDX | BPF_MEM | BPF_H] = &&LDX_MEM_H,
249 DL(LD, IND, H), 249 [BPF_LDX | BPF_MEM | BPF_W] = &&LDX_MEM_W,
250 DL(LD, IND, B), 250 [BPF_LDX | BPF_MEM | BPF_DW] = &&LDX_MEM_DW,
251#undef DL 251 [BPF_LD | BPF_ABS | BPF_W] = &&LD_ABS_W,
252 [BPF_LD | BPF_ABS | BPF_H] = &&LD_ABS_H,
253 [BPF_LD | BPF_ABS | BPF_B] = &&LD_ABS_B,
254 [BPF_LD | BPF_IND | BPF_W] = &&LD_IND_W,
255 [BPF_LD | BPF_IND | BPF_H] = &&LD_IND_H,
256 [BPF_LD | BPF_IND | BPF_B] = &&LD_IND_B,
252 }; 257 };
253 void *ptr; 258 void *ptr;
254 int off; 259 int off;
@@ -290,10 +295,10 @@ select_insn:
290 ALU(XOR, ^) 295 ALU(XOR, ^)
291 ALU(MUL, *) 296 ALU(MUL, *)
292#undef ALU 297#undef ALU
293 ALU_NEG_0: 298 ALU_NEG:
294 A = (u32) -A; 299 A = (u32) -A;
295 CONT; 300 CONT;
296 ALU64_NEG_0: 301 ALU64_NEG:
297 A = -A; 302 A = -A;
298 CONT; 303 CONT;
299 ALU_MOV_X: 304 ALU_MOV_X:
@@ -382,7 +387,7 @@ select_insn:
382 CONT; 387 CONT;
383 388
384 /* CALL */ 389 /* CALL */
385 JMP_CALL_0: 390 JMP_CALL:
386 /* Function call scratches BPF_R1-BPF_R5 registers, 391 /* Function call scratches BPF_R1-BPF_R5 registers,
387 * preserves BPF_R6-BPF_R9, and stores return value 392 * preserves BPF_R6-BPF_R9, and stores return value
388 * into BPF_R0. 393 * into BPF_R0.
@@ -392,7 +397,7 @@ select_insn:
392 CONT; 397 CONT;
393 398
394 /* JMP */ 399 /* JMP */
395 JMP_JA_0: 400 JMP_JA:
396 insn += insn->off; 401 insn += insn->off;
397 CONT; 402 CONT;
398 JMP_JEQ_X: 403 JMP_JEQ_X:
@@ -479,7 +484,7 @@ select_insn:
479 CONT_JMP; 484 CONT_JMP;
480 } 485 }
481 CONT; 486 CONT;
482 JMP_EXIT_0: 487 JMP_EXIT:
483 return BPF_R0; 488 return BPF_R0;
484 489
485 /* STX and ST and LDX*/ 490 /* STX and ST and LDX*/
@@ -1580,7 +1585,7 @@ static struct sk_filter *__sk_prepare_filter(struct sk_filter *fp,
1580 * a negative errno code is returned. On success the return is zero. 1585 * a negative errno code is returned. On success the return is zero.
1581 */ 1586 */
1582int sk_unattached_filter_create(struct sk_filter **pfp, 1587int sk_unattached_filter_create(struct sk_filter **pfp,
1583 struct sock_fprog *fprog) 1588 struct sock_fprog_kern *fprog)
1584{ 1589{
1585 unsigned int fsize = sk_filter_proglen(fprog); 1590 unsigned int fsize = sk_filter_proglen(fprog);
1586 struct sk_filter *fp; 1591 struct sk_filter *fp;
diff --git a/net/core/ptp_classifier.c b/net/core/ptp_classifier.c
index 37d86157b76e..d3027a73fd4b 100644
--- a/net/core/ptp_classifier.c
+++ b/net/core/ptp_classifier.c
@@ -133,7 +133,7 @@ void __init ptp_classifier_init(void)
133 { 0x16, 0, 0, 0x00000000 }, 133 { 0x16, 0, 0, 0x00000000 },
134 { 0x06, 0, 0, 0x00000000 }, 134 { 0x06, 0, 0, 0x00000000 },
135 }; 135 };
136 struct sock_fprog ptp_prog = { 136 struct sock_fprog_kern ptp_prog = {
137 .len = ARRAY_SIZE(ptp_filter), .filter = ptp_filter, 137 .len = ARRAY_SIZE(ptp_filter), .filter = ptp_filter,
138 }; 138 };
139 139
diff --git a/net/netfilter/xt_bpf.c b/net/netfilter/xt_bpf.c
index 12d4da8e6c77..bbffdbdaf603 100644
--- a/net/netfilter/xt_bpf.c
+++ b/net/netfilter/xt_bpf.c
@@ -23,10 +23,11 @@ MODULE_ALIAS("ip6t_bpf");
23static int bpf_mt_check(const struct xt_mtchk_param *par) 23static int bpf_mt_check(const struct xt_mtchk_param *par)
24{ 24{
25 struct xt_bpf_info *info = par->matchinfo; 25 struct xt_bpf_info *info = par->matchinfo;
26 struct sock_fprog program; 26 struct sock_fprog_kern program;
27 27
28 program.len = info->bpf_program_num_elem; 28 program.len = info->bpf_program_num_elem;
29 program.filter = (struct sock_filter __user *) info->bpf_program; 29 program.filter = info->bpf_program;
30
30 if (sk_unattached_filter_create(&info->filter, &program)) { 31 if (sk_unattached_filter_create(&info->filter, &program)) {
31 pr_info("bpf: check failed: parse error\n"); 32 pr_info("bpf: check failed: parse error\n");
32 return -EINVAL; 33 return -EINVAL;
diff --git a/net/sched/cls_bpf.c b/net/sched/cls_bpf.c
index 16186965af97..13f64df2c710 100644
--- a/net/sched/cls_bpf.c
+++ b/net/sched/cls_bpf.c
@@ -160,7 +160,7 @@ static int cls_bpf_modify_existing(struct net *net, struct tcf_proto *tp,
160{ 160{
161 struct sock_filter *bpf_ops, *bpf_old; 161 struct sock_filter *bpf_ops, *bpf_old;
162 struct tcf_exts exts; 162 struct tcf_exts exts;
163 struct sock_fprog tmp; 163 struct sock_fprog_kern tmp;
164 struct sk_filter *fp, *fp_old; 164 struct sk_filter *fp, *fp_old;
165 u16 bpf_size, bpf_len; 165 u16 bpf_size, bpf_len;
166 u32 classid; 166 u32 classid;
@@ -191,7 +191,7 @@ static int cls_bpf_modify_existing(struct net *net, struct tcf_proto *tp,
191 memcpy(bpf_ops, nla_data(tb[TCA_BPF_OPS]), bpf_size); 191 memcpy(bpf_ops, nla_data(tb[TCA_BPF_OPS]), bpf_size);
192 192
193 tmp.len = bpf_len; 193 tmp.len = bpf_len;
194 tmp.filter = (struct sock_filter __user *) bpf_ops; 194 tmp.filter = bpf_ops;
195 195
196 ret = sk_unattached_filter_create(&fp, &tmp); 196 ret = sk_unattached_filter_create(&fp, &tmp);
197 if (ret) 197 if (ret)