xref: /freebsd/contrib/netbsd-tests/net/bpfjit/t_mbuf.c (revision 1a36faad54665288ed4eb839d2a4699ae2ead45e)
1*63d1fd59SEnji Cooper /*	$NetBSD: t_mbuf.c,v 1.2 2017/01/13 21:30:42 christos Exp $	*/
257718be8SEnji Cooper 
357718be8SEnji Cooper /*-
457718be8SEnji Cooper  * Copyright (c) 2014 Alexander Nasonov.
557718be8SEnji Cooper  * All rights reserved.
657718be8SEnji Cooper  *
757718be8SEnji Cooper  * Redistribution and use in source and binary forms, with or without
857718be8SEnji Cooper  * modification, are permitted provided that the following conditions
957718be8SEnji Cooper  * are met:
1057718be8SEnji Cooper  * 1. Redistributions of source code must retain the above copyright
1157718be8SEnji Cooper  *    notice, this list of conditions and the following disclaimer.
1257718be8SEnji Cooper  * 2. Redistributions in binary form must reproduce the above copyright
1357718be8SEnji Cooper  *    notice, this list of conditions and the following disclaimer in the
1457718be8SEnji Cooper  *    documentation and/or other materials provided with the distribution.
1557718be8SEnji Cooper  *
1657718be8SEnji Cooper  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
1757718be8SEnji Cooper  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1857718be8SEnji Cooper  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1957718be8SEnji Cooper  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2057718be8SEnji Cooper  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2157718be8SEnji Cooper  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
2257718be8SEnji Cooper  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2357718be8SEnji Cooper  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2457718be8SEnji Cooper  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2557718be8SEnji Cooper  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2657718be8SEnji Cooper  * SUCH DAMAGE.
2757718be8SEnji Cooper  */
2857718be8SEnji Cooper 
2957718be8SEnji Cooper #include <sys/cdefs.h>
30*63d1fd59SEnji Cooper __RCSID("$NetBSD: t_mbuf.c,v 1.2 2017/01/13 21:30:42 christos Exp $");
3157718be8SEnji Cooper 
3257718be8SEnji Cooper #include <sys/param.h>
3357718be8SEnji Cooper #include <sys/mbuf.h>
3457718be8SEnji Cooper 
3557718be8SEnji Cooper #include <net/bpf.h>
3657718be8SEnji Cooper #include <net/bpfjit.h>
3757718be8SEnji Cooper 
3857718be8SEnji Cooper #include <stdint.h>
3957718be8SEnji Cooper #include <string.h>
4057718be8SEnji Cooper 
4157718be8SEnji Cooper #include <rump/rump.h>
4257718be8SEnji Cooper #include <rump/rump_syscalls.h>
4357718be8SEnji Cooper 
4457718be8SEnji Cooper #include "../../net/bpf/h_bpf.h"
4557718be8SEnji Cooper 
4657718be8SEnji Cooper /* XXX: atf-c.h has collisions with mbuf */
4757718be8SEnji Cooper #undef m_type
4857718be8SEnji Cooper #undef m_data
4957718be8SEnji Cooper #include <atf-c.h>
5057718be8SEnji Cooper 
51*63d1fd59SEnji Cooper #include "h_macros.h"
5257718be8SEnji Cooper 
5357718be8SEnji Cooper static bool
test_ldb_abs(size_t split)5457718be8SEnji Cooper test_ldb_abs(size_t split)
5557718be8SEnji Cooper {
5657718be8SEnji Cooper 	/* Return a product of all packet bytes. */
5757718be8SEnji Cooper 	static struct bpf_insn insns[] = {
5857718be8SEnji Cooper 		BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 1), /* X <- 1     */
5957718be8SEnji Cooper 
6057718be8SEnji Cooper 		BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 0),  /* A <- P[0]  */
6157718be8SEnji Cooper 		BPF_STMT(BPF_ALU+BPF_MUL+BPF_X, 0), /* A <- A * X */
6257718be8SEnji Cooper 		BPF_STMT(BPF_MISC+BPF_TAX, 0),      /* X <- A     */
6357718be8SEnji Cooper 
6457718be8SEnji Cooper 		BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 1),  /* A <- P[1]  */
6557718be8SEnji Cooper 		BPF_STMT(BPF_ALU+BPF_MUL+BPF_X, 0), /* A <- A * X */
6657718be8SEnji Cooper 		BPF_STMT(BPF_MISC+BPF_TAX, 0),      /* X <- A     */
6757718be8SEnji Cooper 
6857718be8SEnji Cooper 		BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 2),  /* A <- P[2]  */
6957718be8SEnji Cooper 		BPF_STMT(BPF_ALU+BPF_MUL+BPF_X, 0), /* A <- A * X */
7057718be8SEnji Cooper 		BPF_STMT(BPF_MISC+BPF_TAX, 0),      /* X <- A     */
7157718be8SEnji Cooper 
7257718be8SEnji Cooper 		BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 3),  /* A <- P[3]  */
7357718be8SEnji Cooper 		BPF_STMT(BPF_ALU+BPF_MUL+BPF_X, 0), /* A <- A * X */
7457718be8SEnji Cooper 		BPF_STMT(BPF_MISC+BPF_TAX, 0),      /* X <- A     */
7557718be8SEnji Cooper 
7657718be8SEnji Cooper 		BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 4),  /* A <- P[4]  */
7757718be8SEnji Cooper 		BPF_STMT(BPF_ALU+BPF_MUL+BPF_X, 0), /* A <- A * X */
7857718be8SEnji Cooper 		BPF_STMT(BPF_RET+BPF_A, 0),         /* ret A      */
7957718be8SEnji Cooper 	};
8057718be8SEnji Cooper 
8157718be8SEnji Cooper 	static unsigned char P[] = { 1, 2, 3, 4, 5 };
8257718be8SEnji Cooper 	const unsigned int res = 120;
8357718be8SEnji Cooper 	const size_t insn_count = sizeof(insns) / sizeof(insns[0]);
8457718be8SEnji Cooper 
8557718be8SEnji Cooper 	if (!prog_validate(insns, insn_count))
8657718be8SEnji Cooper 		return false;
8757718be8SEnji Cooper 
8857718be8SEnji Cooper 	return exec_prog_mchain2(insns, insn_count, P, sizeof(P), split) == res;
8957718be8SEnji Cooper }
9057718be8SEnji Cooper 
9157718be8SEnji Cooper static bool
test_ldh_abs(size_t split)9257718be8SEnji Cooper test_ldh_abs(size_t split)
9357718be8SEnji Cooper {
9457718be8SEnji Cooper 	static struct bpf_insn insns[] = {
9557718be8SEnji Cooper 		BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 0),  /* A <- P[0:2]  */
9657718be8SEnji Cooper 		BPF_STMT(BPF_ALU+BPF_ADD+BPF_X, 0), /* A <- A + X   */
9757718be8SEnji Cooper 		BPF_STMT(BPF_MISC+BPF_TAX, 0),      /* X <- A       */
9857718be8SEnji Cooper 
9957718be8SEnji Cooper 		BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 1),  /* A <- P[1:2]  */
10057718be8SEnji Cooper 		BPF_STMT(BPF_ALU+BPF_ADD+BPF_X, 0), /* A <- A + X   */
10157718be8SEnji Cooper 		BPF_STMT(BPF_MISC+BPF_TAX, 0),      /* X <- A       */
10257718be8SEnji Cooper 
10357718be8SEnji Cooper 		BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 2),  /* A <- P[2:2]  */
10457718be8SEnji Cooper 		BPF_STMT(BPF_ALU+BPF_ADD+BPF_X, 0), /* A <- A + X   */
10557718be8SEnji Cooper 		BPF_STMT(BPF_MISC+BPF_TAX, 0),      /* X <- A       */
10657718be8SEnji Cooper 
10757718be8SEnji Cooper 		BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 3),  /* A <- P[3:2]  */
10857718be8SEnji Cooper 		BPF_STMT(BPF_ALU+BPF_ADD+BPF_X, 0), /* A <- A + X   */
10957718be8SEnji Cooper 		BPF_STMT(BPF_RET+BPF_A, 0),         /* ret A        */
11057718be8SEnji Cooper 	};
11157718be8SEnji Cooper 
11257718be8SEnji Cooper 	static unsigned char P[] = { 1, 2, 3, 4, 5 };
11357718be8SEnji Cooper 	const unsigned int res = 0x0a0e; /* 10 14 */
11457718be8SEnji Cooper 	const size_t insn_count = sizeof(insns) / sizeof(insns[0]);
11557718be8SEnji Cooper 
11657718be8SEnji Cooper 	if (!prog_validate(insns, insn_count))
11757718be8SEnji Cooper 		return false;
11857718be8SEnji Cooper 
11957718be8SEnji Cooper 	return exec_prog_mchain2(insns, insn_count, P, sizeof(P), split) == res;
12057718be8SEnji Cooper }
12157718be8SEnji Cooper 
12257718be8SEnji Cooper static bool
test_ldw_abs(size_t split)12357718be8SEnji Cooper test_ldw_abs(size_t split)
12457718be8SEnji Cooper {
12557718be8SEnji Cooper 	static struct bpf_insn insns[] = {
12657718be8SEnji Cooper 		BPF_STMT(BPF_LD+BPF_W+BPF_ABS, 0),  /* A <- P[0:4] */
12757718be8SEnji Cooper 		BPF_STMT(BPF_ALU+BPF_ADD+BPF_X, 0), /* A <- A + X  */
12857718be8SEnji Cooper 		BPF_STMT(BPF_MISC+BPF_TAX, 0),      /* X <- A       */
12957718be8SEnji Cooper 
13057718be8SEnji Cooper 		BPF_STMT(BPF_LD+BPF_W+BPF_ABS, 1),  /* A <- P[1:4] */
13157718be8SEnji Cooper 		BPF_STMT(BPF_ALU+BPF_ADD+BPF_X, 0), /* A <- A + X  */
13257718be8SEnji Cooper 		BPF_STMT(BPF_RET+BPF_A, 0),         /* ret A       */
13357718be8SEnji Cooper 	};
13457718be8SEnji Cooper 
13557718be8SEnji Cooper 	static unsigned char P[] = { 1, 2, 3, 4, 5 };
13657718be8SEnji Cooper 	const unsigned int res = 0x03050709;
13757718be8SEnji Cooper 	const size_t insn_count = sizeof(insns) / sizeof(insns[0]);
13857718be8SEnji Cooper 
13957718be8SEnji Cooper 	if (!prog_validate(insns, insn_count))
14057718be8SEnji Cooper 		return false;
14157718be8SEnji Cooper 
14257718be8SEnji Cooper 	return exec_prog_mchain2(insns, insn_count, P, sizeof(P), split) == res;
14357718be8SEnji Cooper }
14457718be8SEnji Cooper 
14557718be8SEnji Cooper static bool
test_ldb_ind(size_t split)14657718be8SEnji Cooper test_ldb_ind(size_t split)
14757718be8SEnji Cooper {
14857718be8SEnji Cooper 	/* Return a sum of all packet bytes. */
14957718be8SEnji Cooper 	static struct bpf_insn insns[] = {
15057718be8SEnji Cooper 		BPF_STMT(BPF_LD+BPF_B+BPF_IND, 0),  /* A <- P[0+X] */
15157718be8SEnji Cooper 		BPF_STMT(BPF_ST, 0),                /* M[0] <- A   */
15257718be8SEnji Cooper 
15357718be8SEnji Cooper 		BPF_STMT(BPF_LD+BPF_B+BPF_IND, 1),  /* A <- P[1+X] */
15457718be8SEnji Cooper 		BPF_STMT(BPF_LDX+BPF_W+BPF_MEM, 0), /* X <- M[0]   */
15557718be8SEnji Cooper 		BPF_STMT(BPF_ALU+BPF_ADD+BPF_X, 0), /* A <- A + X  */
15657718be8SEnji Cooper 		BPF_STMT(BPF_ST, 0),                /* M[0] <- A   */
15757718be8SEnji Cooper 
15857718be8SEnji Cooper 		BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 1), /* X <- 1      */
15957718be8SEnji Cooper 		BPF_STMT(BPF_LD+BPF_B+BPF_IND, 1),  /* A <- P[1+X] */
16057718be8SEnji Cooper 		BPF_STMT(BPF_LDX+BPF_W+BPF_MEM, 0), /* X <- M[0]   */
16157718be8SEnji Cooper 		BPF_STMT(BPF_ALU+BPF_ADD+BPF_X, 0), /* A <- A + X  */
16257718be8SEnji Cooper 		BPF_STMT(BPF_ST, 0),                /* M[0] <- A   */
16357718be8SEnji Cooper 
16457718be8SEnji Cooper 		BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 1), /* X <- 1      */
16557718be8SEnji Cooper 		BPF_STMT(BPF_LD+BPF_B+BPF_IND, 2),  /* A <- P[2+X] */
16657718be8SEnji Cooper 		BPF_STMT(BPF_LDX+BPF_W+BPF_MEM, 0), /* X <- M[0]   */
16757718be8SEnji Cooper 		BPF_STMT(BPF_ALU+BPF_ADD+BPF_X, 0), /* A <- A + X  */
16857718be8SEnji Cooper 		BPF_STMT(BPF_ST, 0),                /* M[0] <- A   */
16957718be8SEnji Cooper 
17057718be8SEnji Cooper 		BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 1), /* X <- 1      */
17157718be8SEnji Cooper 		BPF_STMT(BPF_LD+BPF_B+BPF_IND, 3),  /* A <- P[3+X] */
17257718be8SEnji Cooper 		BPF_STMT(BPF_LDX+BPF_W+BPF_MEM, 0), /* X <- M[0]   */
17357718be8SEnji Cooper 		BPF_STMT(BPF_ALU+BPF_ADD+BPF_X, 0), /* A <- A + X  */
17457718be8SEnji Cooper 		BPF_STMT(BPF_RET+BPF_A, 0),         /* ret A       */
17557718be8SEnji Cooper 	};
17657718be8SEnji Cooper 
17757718be8SEnji Cooper 	static unsigned char P[] = { 1, 2, 3, 4, 5 };
17857718be8SEnji Cooper 	const unsigned int res = 15;
17957718be8SEnji Cooper 	const size_t insn_count = sizeof(insns) / sizeof(insns[0]);
18057718be8SEnji Cooper 
18157718be8SEnji Cooper 	if (!prog_validate(insns, insn_count))
18257718be8SEnji Cooper 		return false;
18357718be8SEnji Cooper 
18457718be8SEnji Cooper 	return exec_prog_mchain2(insns, insn_count, P, sizeof(P), split) == res;
18557718be8SEnji Cooper }
18657718be8SEnji Cooper 
18757718be8SEnji Cooper static bool
test_ldw_ind(size_t split)18857718be8SEnji Cooper test_ldw_ind(size_t split)
18957718be8SEnji Cooper {
19057718be8SEnji Cooper 	static struct bpf_insn insns[] = {
19157718be8SEnji Cooper 		BPF_STMT(BPF_LD+BPF_W+BPF_IND, 0),  /* A <- P[X+0:4] */
19257718be8SEnji Cooper 		BPF_STMT(BPF_ST, 0),                /* M[0] <- A     */
19357718be8SEnji Cooper 
19457718be8SEnji Cooper 		BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 1), /* X <- 1        */
19557718be8SEnji Cooper 		BPF_STMT(BPF_LD+BPF_W+BPF_IND, 0),  /* A <- P[X+0:4] */
19657718be8SEnji Cooper 		BPF_STMT(BPF_LDX+BPF_W+BPF_MEM, 0), /* X <- M[0]     */
19757718be8SEnji Cooper 		BPF_STMT(BPF_ALU+BPF_ADD+BPF_X, 0), /* A <- A + X    */
19857718be8SEnji Cooper 		BPF_STMT(BPF_ST, 0),                /* M[0] <- A     */
19957718be8SEnji Cooper 
20057718be8SEnji Cooper 		BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 0), /* X <- 0        */
20157718be8SEnji Cooper 		BPF_STMT(BPF_LD+BPF_W+BPF_IND, 1),  /* A <- P[X+1:4] */
20257718be8SEnji Cooper 		BPF_STMT(BPF_LDX+BPF_W+BPF_MEM, 0), /* X <- M[0]     */
20357718be8SEnji Cooper 		BPF_STMT(BPF_ALU+BPF_ADD+BPF_X, 0), /* A <- A + X    */
20457718be8SEnji Cooper 		BPF_STMT(BPF_RET+BPF_A, 0),         /* ret A         */
20557718be8SEnji Cooper 	};
20657718be8SEnji Cooper 
20757718be8SEnji Cooper 	static unsigned char P[] = { 1, 2, 3, 4, 5 };
20857718be8SEnji Cooper 	const unsigned int res = 0x05080b0e;
20957718be8SEnji Cooper 	const size_t insn_count = sizeof(insns) / sizeof(insns[0]);
21057718be8SEnji Cooper 
21157718be8SEnji Cooper 	if (!prog_validate(insns, insn_count))
21257718be8SEnji Cooper 		return false;
21357718be8SEnji Cooper 
21457718be8SEnji Cooper 	return exec_prog_mchain2(insns, insn_count, P, sizeof(P), split) == res;
21557718be8SEnji Cooper }
21657718be8SEnji Cooper 
21757718be8SEnji Cooper static bool
test_ldh_ind(size_t split)21857718be8SEnji Cooper test_ldh_ind(size_t split)
21957718be8SEnji Cooper {
22057718be8SEnji Cooper 	static struct bpf_insn insns[] = {
22157718be8SEnji Cooper 		BPF_STMT(BPF_LD+BPF_H+BPF_IND, 0),  /* A <- P[X+0:2] */
22257718be8SEnji Cooper 		BPF_STMT(BPF_ST, 0),                /* M[0] <- A     */
22357718be8SEnji Cooper 
22457718be8SEnji Cooper 		BPF_STMT(BPF_LD+BPF_H+BPF_IND, 1),  /* A <- P[X+1:2] */
22557718be8SEnji Cooper 		BPF_STMT(BPF_LDX+BPF_W+BPF_MEM, 0), /* X <- M[0]     */
22657718be8SEnji Cooper 		BPF_STMT(BPF_ALU+BPF_ADD+BPF_X, 0), /* A <- A + X    */
22757718be8SEnji Cooper 		BPF_STMT(BPF_ST, 0),                /* M[0] <- A     */
22857718be8SEnji Cooper 
22957718be8SEnji Cooper 		BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 1), /* X <- 1        */
23057718be8SEnji Cooper 		BPF_STMT(BPF_LD+BPF_H+BPF_IND, 1),  /* A <- P[X+1:2] */
23157718be8SEnji Cooper 		BPF_STMT(BPF_LDX+BPF_W+BPF_MEM, 0), /* X <- M[0]     */
23257718be8SEnji Cooper 		BPF_STMT(BPF_ALU+BPF_ADD+BPF_X, 0), /* A <- A + X    */
23357718be8SEnji Cooper 		BPF_STMT(BPF_ST, 0),                /* M[0] <- A     */
23457718be8SEnji Cooper 
23557718be8SEnji Cooper 		BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 1), /* X <- 1        */
23657718be8SEnji Cooper 		BPF_STMT(BPF_LD+BPF_H+BPF_IND, 2),  /* A <- P[X+2:2] */
23757718be8SEnji Cooper 		BPF_STMT(BPF_LDX+BPF_W+BPF_MEM, 0), /* X <- M[0]     */
23857718be8SEnji Cooper 		BPF_STMT(BPF_ALU+BPF_ADD+BPF_X, 0), /* A <- A + X    */
23957718be8SEnji Cooper 		BPF_STMT(BPF_RET+BPF_A, 0),         /* ret A         */
24057718be8SEnji Cooper 	};
24157718be8SEnji Cooper 
24257718be8SEnji Cooper 	static unsigned char P[] = { 1, 2, 3, 4, 5 };
24357718be8SEnji Cooper 	const unsigned int res = 0x0a0e; /* 10 14 */
24457718be8SEnji Cooper 	const size_t insn_count = sizeof(insns) / sizeof(insns[0]);
24557718be8SEnji Cooper 
24657718be8SEnji Cooper 	if (!prog_validate(insns, insn_count))
24757718be8SEnji Cooper 		return false;
24857718be8SEnji Cooper 
24957718be8SEnji Cooper 	return exec_prog_mchain2(insns, insn_count, P, sizeof(P), split) == res;
25057718be8SEnji Cooper }
25157718be8SEnji Cooper 
25257718be8SEnji Cooper static bool
test_msh(size_t split)25357718be8SEnji Cooper test_msh(size_t split)
25457718be8SEnji Cooper {
25557718be8SEnji Cooper 	/* Return a product of all packet bytes. */
25657718be8SEnji Cooper 	static struct bpf_insn insns[] = {
25757718be8SEnji Cooper 		BPF_STMT(BPF_LD+BPF_IMM, 1),        /* A <- 1     */
25857718be8SEnji Cooper 
25957718be8SEnji Cooper 		BPF_STMT(BPF_LDX+BPF_B+BPF_MSH, 0), /* X <- 4*(P[0]&0xf)  */
26057718be8SEnji Cooper 		BPF_STMT(BPF_ALU+BPF_MUL+BPF_X, 0), /* A <- A * X         */
26157718be8SEnji Cooper 		BPF_STMT(BPF_ALU+BPF_DIV+BPF_K, 4), /* A <- A / 4         */
26257718be8SEnji Cooper 
26357718be8SEnji Cooper 		BPF_STMT(BPF_LDX+BPF_B+BPF_MSH, 1), /* X <- 4*(P[1]&0xf)  */
26457718be8SEnji Cooper 		BPF_STMT(BPF_ALU+BPF_MUL+BPF_X, 0), /* A <- A * X         */
26557718be8SEnji Cooper 		BPF_STMT(BPF_ALU+BPF_DIV+BPF_K, 4), /* A <- A / 4         */
26657718be8SEnji Cooper 
26757718be8SEnji Cooper 		BPF_STMT(BPF_LDX+BPF_B+BPF_MSH, 2), /* X <- 4*(P[2]&0xf)  */
26857718be8SEnji Cooper 		BPF_STMT(BPF_ALU+BPF_MUL+BPF_X, 0), /* A <- A * X         */
26957718be8SEnji Cooper 		BPF_STMT(BPF_ALU+BPF_DIV+BPF_K, 4), /* A <- A / 4         */
27057718be8SEnji Cooper 
27157718be8SEnji Cooper 		BPF_STMT(BPF_LDX+BPF_B+BPF_MSH, 3), /* X <- 4*(P[3]&0xf)  */
27257718be8SEnji Cooper 		BPF_STMT(BPF_ALU+BPF_MUL+BPF_X, 0), /* A <- A * X         */
27357718be8SEnji Cooper 		BPF_STMT(BPF_ALU+BPF_DIV+BPF_K, 4), /* A <- A / 4         */
27457718be8SEnji Cooper 
27557718be8SEnji Cooper 		BPF_STMT(BPF_LDX+BPF_B+BPF_MSH, 4), /* X <- 4*(P[4]&0xf)  */
27657718be8SEnji Cooper 		BPF_STMT(BPF_ALU+BPF_MUL+BPF_X, 0), /* A <- A * X         */
27757718be8SEnji Cooper 		BPF_STMT(BPF_ALU+BPF_DIV+BPF_K, 4), /* A <- A / 4         */
27857718be8SEnji Cooper 
27957718be8SEnji Cooper 		BPF_STMT(BPF_RET+BPF_A, 0),         /* ret A      */
28057718be8SEnji Cooper 	};
28157718be8SEnji Cooper 
28257718be8SEnji Cooper 	static unsigned char P[] = { 1, 2, 3, 4, 5 };
28357718be8SEnji Cooper 	const unsigned int res = 120;
28457718be8SEnji Cooper 	const size_t insn_count = sizeof(insns) / sizeof(insns[0]);
28557718be8SEnji Cooper 
28657718be8SEnji Cooper 	if (!prog_validate(insns, insn_count))
28757718be8SEnji Cooper 		return false;
28857718be8SEnji Cooper 
28957718be8SEnji Cooper 	return exec_prog_mchain2(insns, insn_count, P, sizeof(P), split) == res;
29057718be8SEnji Cooper }
29157718be8SEnji Cooper 
29257718be8SEnji Cooper static bool
test_ldb_abs_overflow(size_t split)29357718be8SEnji Cooper test_ldb_abs_overflow(size_t split)
29457718be8SEnji Cooper {
29557718be8SEnji Cooper 	static struct bpf_insn insns[] = {
29657718be8SEnji Cooper 		BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 5),
29757718be8SEnji Cooper 		BPF_STMT(BPF_ALU+BPF_ADD+BPF_K, 1),
29857718be8SEnji Cooper 		BPF_STMT(BPF_RET+BPF_A, 0),
29957718be8SEnji Cooper 	};
30057718be8SEnji Cooper 
30157718be8SEnji Cooper 	static unsigned char P[] = { 1, 2, 3, 4, 5 };
30257718be8SEnji Cooper 	const size_t insn_count = sizeof(insns) / sizeof(insns[0]);
30357718be8SEnji Cooper 
30457718be8SEnji Cooper 	if (!prog_validate(insns, insn_count))
30557718be8SEnji Cooper 		return false;
30657718be8SEnji Cooper 
30757718be8SEnji Cooper 	return exec_prog_mchain2(insns, insn_count, P, sizeof(P), split) == 0;
30857718be8SEnji Cooper }
30957718be8SEnji Cooper 
31057718be8SEnji Cooper static bool
test_ldh_abs_overflow(size_t split)31157718be8SEnji Cooper test_ldh_abs_overflow(size_t split)
31257718be8SEnji Cooper {
31357718be8SEnji Cooper 	static struct bpf_insn insns[] = {
31457718be8SEnji Cooper 		BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 4),
31557718be8SEnji Cooper 		BPF_STMT(BPF_ALU+BPF_ADD+BPF_K, 1),
31657718be8SEnji Cooper 		BPF_STMT(BPF_RET+BPF_A, 0),
31757718be8SEnji Cooper 	};
31857718be8SEnji Cooper 
31957718be8SEnji Cooper 	static unsigned char P[] = { 1, 2, 3, 4, 5 };
32057718be8SEnji Cooper 	const size_t insn_count = sizeof(insns) / sizeof(insns[0]);
32157718be8SEnji Cooper 
32257718be8SEnji Cooper 	if (!prog_validate(insns, insn_count))
32357718be8SEnji Cooper 		return false;
32457718be8SEnji Cooper 
32557718be8SEnji Cooper 	return exec_prog_mchain2(insns, insn_count, P, sizeof(P), split) == 0;
32657718be8SEnji Cooper }
32757718be8SEnji Cooper 
32857718be8SEnji Cooper static bool
test_ldw_abs_overflow(size_t split)32957718be8SEnji Cooper test_ldw_abs_overflow(size_t split)
33057718be8SEnji Cooper {
33157718be8SEnji Cooper 	static struct bpf_insn insns[] = {
33257718be8SEnji Cooper 		BPF_STMT(BPF_LD+BPF_W+BPF_ABS, 2),
33357718be8SEnji Cooper 		BPF_STMT(BPF_ALU+BPF_ADD+BPF_K, 1),
33457718be8SEnji Cooper 		BPF_STMT(BPF_RET+BPF_A, 0),
33557718be8SEnji Cooper 	};
33657718be8SEnji Cooper 
33757718be8SEnji Cooper 	static unsigned char P[] = { 1, 2, 3, 4, 5 };
33857718be8SEnji Cooper 	const size_t insn_count = sizeof(insns) / sizeof(insns[0]);
33957718be8SEnji Cooper 
34057718be8SEnji Cooper 	if (!prog_validate(insns, insn_count))
34157718be8SEnji Cooper 		return false;
34257718be8SEnji Cooper 
34357718be8SEnji Cooper 	return exec_prog_mchain2(insns, insn_count, P, sizeof(P), split) == 0;
34457718be8SEnji Cooper }
34557718be8SEnji Cooper 
34657718be8SEnji Cooper static bool
test_ldb_ind_overflow1(size_t split)34757718be8SEnji Cooper test_ldb_ind_overflow1(size_t split)
34857718be8SEnji Cooper {
34957718be8SEnji Cooper 	static struct bpf_insn insns[] = {
35057718be8SEnji Cooper 		BPF_STMT(BPF_LD+BPF_B+BPF_IND, 5),
35157718be8SEnji Cooper 		BPF_STMT(BPF_ALU+BPF_ADD+BPF_K, 1),
35257718be8SEnji Cooper 		BPF_STMT(BPF_RET+BPF_A, 0),
35357718be8SEnji Cooper 	};
35457718be8SEnji Cooper 
35557718be8SEnji Cooper 	static unsigned char P[] = { 1, 2, 3, 4, 5 };
35657718be8SEnji Cooper 	const size_t insn_count = sizeof(insns) / sizeof(insns[0]);
35757718be8SEnji Cooper 
35857718be8SEnji Cooper 	if (!prog_validate(insns, insn_count))
35957718be8SEnji Cooper 		return false;
36057718be8SEnji Cooper 
36157718be8SEnji Cooper 	return exec_prog_mchain2(insns, insn_count, P, sizeof(P), split) == 0;
36257718be8SEnji Cooper }
36357718be8SEnji Cooper 
36457718be8SEnji Cooper static bool
test_ldb_ind_overflow2(size_t split)36557718be8SEnji Cooper test_ldb_ind_overflow2(size_t split)
36657718be8SEnji Cooper {
36757718be8SEnji Cooper 	static struct bpf_insn insns[] = {
36857718be8SEnji Cooper 		BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 4),
36957718be8SEnji Cooper 		BPF_STMT(BPF_LD+BPF_B+BPF_IND, 1),
37057718be8SEnji Cooper 		BPF_STMT(BPF_ALU+BPF_ADD+BPF_X, 0),
37157718be8SEnji Cooper 		BPF_STMT(BPF_RET+BPF_A, 0),
37257718be8SEnji Cooper 	};
37357718be8SEnji Cooper 
37457718be8SEnji Cooper 	static unsigned char P[] = { 1, 2, 3, 4, 5 };
37557718be8SEnji Cooper 	const size_t insn_count = sizeof(insns) / sizeof(insns[0]);
37657718be8SEnji Cooper 
37757718be8SEnji Cooper 	if (!prog_validate(insns, insn_count))
37857718be8SEnji Cooper 		return false;
37957718be8SEnji Cooper 
38057718be8SEnji Cooper 	return exec_prog_mchain2(insns, insn_count, P, sizeof(P), split) == 0;
38157718be8SEnji Cooper }
38257718be8SEnji Cooper 
38357718be8SEnji Cooper static bool
test_ldb_ind_overflow3(size_t split)38457718be8SEnji Cooper test_ldb_ind_overflow3(size_t split)
38557718be8SEnji Cooper {
38657718be8SEnji Cooper 	static struct bpf_insn insns[] = {
38757718be8SEnji Cooper 		BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, UINT32_MAX),
38857718be8SEnji Cooper 		BPF_STMT(BPF_LD+BPF_B+BPF_IND, 1),
38957718be8SEnji Cooper 		BPF_STMT(BPF_ALU+BPF_ADD+BPF_K, 1),
39057718be8SEnji Cooper 		BPF_STMT(BPF_RET+BPF_A, 0),
39157718be8SEnji Cooper 	};
39257718be8SEnji Cooper 
39357718be8SEnji Cooper 	static unsigned char P[] = { 1, 2, 3, 4, 5 };
39457718be8SEnji Cooper 	const size_t insn_count = sizeof(insns) / sizeof(insns[0]);
39557718be8SEnji Cooper 
39657718be8SEnji Cooper 	if (!prog_validate(insns, insn_count))
39757718be8SEnji Cooper 		return false;
39857718be8SEnji Cooper 
39957718be8SEnji Cooper 	return exec_prog_mchain2(insns, insn_count, P, sizeof(P), split) == 0;
40057718be8SEnji Cooper }
40157718be8SEnji Cooper 
40257718be8SEnji Cooper static bool
test_ldh_ind_overflow1(size_t split)40357718be8SEnji Cooper test_ldh_ind_overflow1(size_t split)
40457718be8SEnji Cooper {
40557718be8SEnji Cooper 	static struct bpf_insn insns[] = {
40657718be8SEnji Cooper 		BPF_STMT(BPF_LD+BPF_H+BPF_IND, 4),
40757718be8SEnji Cooper 		BPF_STMT(BPF_ALU+BPF_ADD+BPF_K, 1),
40857718be8SEnji Cooper 		BPF_STMT(BPF_RET+BPF_A, 0),
40957718be8SEnji Cooper 	};
41057718be8SEnji Cooper 
41157718be8SEnji Cooper 	static unsigned char P[] = { 1, 2, 3, 4, 5 };
41257718be8SEnji Cooper 	const size_t insn_count = sizeof(insns) / sizeof(insns[0]);
41357718be8SEnji Cooper 
41457718be8SEnji Cooper 	if (!prog_validate(insns, insn_count))
41557718be8SEnji Cooper 		return false;
41657718be8SEnji Cooper 
41757718be8SEnji Cooper 	return exec_prog_mchain2(insns, insn_count, P, sizeof(P), split) == 0;
41857718be8SEnji Cooper }
41957718be8SEnji Cooper 
42057718be8SEnji Cooper static bool
test_ldh_ind_overflow2(size_t split)42157718be8SEnji Cooper test_ldh_ind_overflow2(size_t split)
42257718be8SEnji Cooper {
42357718be8SEnji Cooper 	static struct bpf_insn insns[] = {
42457718be8SEnji Cooper 		BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 3),
42557718be8SEnji Cooper 		BPF_STMT(BPF_LD+BPF_H+BPF_IND, 1),
42657718be8SEnji Cooper 		BPF_STMT(BPF_ALU+BPF_ADD+BPF_X, 0),
42757718be8SEnji Cooper 		BPF_STMT(BPF_RET+BPF_A, 0),
42857718be8SEnji Cooper 	};
42957718be8SEnji Cooper 
43057718be8SEnji Cooper 	static unsigned char P[] = { 1, 2, 3, 4, 5 };
43157718be8SEnji Cooper 	const size_t insn_count = sizeof(insns) / sizeof(insns[0]);
43257718be8SEnji Cooper 
43357718be8SEnji Cooper 	if (!prog_validate(insns, insn_count))
43457718be8SEnji Cooper 		return false;
43557718be8SEnji Cooper 
43657718be8SEnji Cooper 	return exec_prog_mchain2(insns, insn_count, P, sizeof(P), split) == 0;
43757718be8SEnji Cooper }
43857718be8SEnji Cooper 
43957718be8SEnji Cooper static bool
test_ldh_ind_overflow3(size_t split)44057718be8SEnji Cooper test_ldh_ind_overflow3(size_t split)
44157718be8SEnji Cooper {
44257718be8SEnji Cooper 	static struct bpf_insn insns[] = {
44357718be8SEnji Cooper 		BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, UINT32_MAX),
44457718be8SEnji Cooper 		BPF_STMT(BPF_LD+BPF_H+BPF_IND, 1),
44557718be8SEnji Cooper 		BPF_STMT(BPF_ALU+BPF_ADD+BPF_K, 1),
44657718be8SEnji Cooper 		BPF_STMT(BPF_RET+BPF_A, 0),
44757718be8SEnji Cooper 	};
44857718be8SEnji Cooper 
44957718be8SEnji Cooper 	static unsigned char P[] = { 1, 2, 3, 4, 5 };
45057718be8SEnji Cooper 	const size_t insn_count = sizeof(insns) / sizeof(insns[0]);
45157718be8SEnji Cooper 
45257718be8SEnji Cooper 	if (!prog_validate(insns, insn_count))
45357718be8SEnji Cooper 		return false;
45457718be8SEnji Cooper 
45557718be8SEnji Cooper 	return exec_prog_mchain2(insns, insn_count, P, sizeof(P), split) == 0;
45657718be8SEnji Cooper }
45757718be8SEnji Cooper 
45857718be8SEnji Cooper static bool
test_ldw_ind_overflow1(size_t split)45957718be8SEnji Cooper test_ldw_ind_overflow1(size_t split)
46057718be8SEnji Cooper {
46157718be8SEnji Cooper 	static struct bpf_insn insns[] = {
46257718be8SEnji Cooper 		BPF_STMT(BPF_LD+BPF_W+BPF_IND, 2),
46357718be8SEnji Cooper 		BPF_STMT(BPF_ALU+BPF_ADD+BPF_K, 1),
46457718be8SEnji Cooper 		BPF_STMT(BPF_RET+BPF_A, 0),
46557718be8SEnji Cooper 	};
46657718be8SEnji Cooper 
46757718be8SEnji Cooper 	static unsigned char P[] = { 1, 2, 3, 4, 5 };
46857718be8SEnji Cooper 	const size_t insn_count = sizeof(insns) / sizeof(insns[0]);
46957718be8SEnji Cooper 
47057718be8SEnji Cooper 	if (!prog_validate(insns, insn_count))
47157718be8SEnji Cooper 		return false;
47257718be8SEnji Cooper 
47357718be8SEnji Cooper 	return exec_prog_mchain2(insns, insn_count, P, sizeof(P), split) == 0;
47457718be8SEnji Cooper }
47557718be8SEnji Cooper 
47657718be8SEnji Cooper static bool
test_ldw_ind_overflow2(size_t split)47757718be8SEnji Cooper test_ldw_ind_overflow2(size_t split)
47857718be8SEnji Cooper {
47957718be8SEnji Cooper 	static struct bpf_insn insns[] = {
48057718be8SEnji Cooper 		BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 1),
48157718be8SEnji Cooper 		BPF_STMT(BPF_LD+BPF_W+BPF_IND, 1),
48257718be8SEnji Cooper 		BPF_STMT(BPF_ALU+BPF_ADD+BPF_X, 0),
48357718be8SEnji Cooper 		BPF_STMT(BPF_RET+BPF_A, 0),
48457718be8SEnji Cooper 	};
48557718be8SEnji Cooper 
48657718be8SEnji Cooper 	static unsigned char P[] = { 1, 2, 3, 4, 5 };
48757718be8SEnji Cooper 	const size_t insn_count = sizeof(insns) / sizeof(insns[0]);
48857718be8SEnji Cooper 
48957718be8SEnji Cooper 	if (!prog_validate(insns, insn_count))
49057718be8SEnji Cooper 		return false;
49157718be8SEnji Cooper 
49257718be8SEnji Cooper 	return exec_prog_mchain2(insns, insn_count, P, sizeof(P), split) == 0;
49357718be8SEnji Cooper }
49457718be8SEnji Cooper 
49557718be8SEnji Cooper static bool
test_ldw_ind_overflow3(size_t split)49657718be8SEnji Cooper test_ldw_ind_overflow3(size_t split)
49757718be8SEnji Cooper {
49857718be8SEnji Cooper 	static struct bpf_insn insns[] = {
49957718be8SEnji Cooper 		BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, UINT32_MAX),
50057718be8SEnji Cooper 		BPF_STMT(BPF_LD+BPF_W+BPF_IND, 1),
50157718be8SEnji Cooper 		BPF_STMT(BPF_ALU+BPF_ADD+BPF_K, 1),
50257718be8SEnji Cooper 		BPF_STMT(BPF_RET+BPF_A, 0),
50357718be8SEnji Cooper 	};
50457718be8SEnji Cooper 
50557718be8SEnji Cooper 	static unsigned char P[] = { 1, 2, 3, 4, 5 };
50657718be8SEnji Cooper 	const size_t insn_count = sizeof(insns) / sizeof(insns[0]);
50757718be8SEnji Cooper 
50857718be8SEnji Cooper 	if (!prog_validate(insns, insn_count))
50957718be8SEnji Cooper 		return false;
51057718be8SEnji Cooper 
51157718be8SEnji Cooper 	return exec_prog_mchain2(insns, insn_count, P, sizeof(P), split) == 0;
51257718be8SEnji Cooper }
51357718be8SEnji Cooper 
51457718be8SEnji Cooper static bool
test_msh_overflow(size_t split)51557718be8SEnji Cooper test_msh_overflow(size_t split)
51657718be8SEnji Cooper {
51757718be8SEnji Cooper 	static struct bpf_insn insns[] = {
51857718be8SEnji Cooper 		BPF_STMT(BPF_LDX+BPF_B+BPF_MSH, 5),
51957718be8SEnji Cooper 		BPF_STMT(BPF_MISC+BPF_TXA, 0),
52057718be8SEnji Cooper 		BPF_STMT(BPF_ALU+BPF_ADD+BPF_K, 1),
52157718be8SEnji Cooper 		BPF_STMT(BPF_RET+BPF_A, 0),
52257718be8SEnji Cooper 	};
52357718be8SEnji Cooper 
52457718be8SEnji Cooper 	static unsigned char P[] = { 1, 2, 3, 4, 5 };
52557718be8SEnji Cooper 	const size_t insn_count = sizeof(insns) / sizeof(insns[0]);
52657718be8SEnji Cooper 
52757718be8SEnji Cooper 	if (!prog_validate(insns, insn_count))
52857718be8SEnji Cooper 		return false;
52957718be8SEnji Cooper 
53057718be8SEnji Cooper 	return exec_prog_mchain2(insns, insn_count, P, sizeof(P), split) == 0;
53157718be8SEnji Cooper }
53257718be8SEnji Cooper 
53357718be8SEnji Cooper ATF_TC(bpfjit_mbuf_ldb_abs);
ATF_TC_HEAD(bpfjit_mbuf_ldb_abs,tc)53457718be8SEnji Cooper ATF_TC_HEAD(bpfjit_mbuf_ldb_abs, tc)
53557718be8SEnji Cooper {
53657718be8SEnji Cooper 
53757718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Check that BPF_LD+BPF_B+BPF_ABS "
53857718be8SEnji Cooper 	    "loads bytes from mbuf correctly");
53957718be8SEnji Cooper }
54057718be8SEnji Cooper 
ATF_TC_BODY(bpfjit_mbuf_ldb_abs,tc)54157718be8SEnji Cooper ATF_TC_BODY(bpfjit_mbuf_ldb_abs, tc)
54257718be8SEnji Cooper {
54357718be8SEnji Cooper 
54457718be8SEnji Cooper 	RZ(rump_init());
54557718be8SEnji Cooper 
54657718be8SEnji Cooper 	ATF_CHECK(test_ldb_abs(0));
54757718be8SEnji Cooper 	ATF_CHECK(test_ldb_abs(1));
54857718be8SEnji Cooper 	ATF_CHECK(test_ldb_abs(2));
54957718be8SEnji Cooper 	ATF_CHECK(test_ldb_abs(3));
55057718be8SEnji Cooper 	ATF_CHECK(test_ldb_abs(4));
55157718be8SEnji Cooper 	ATF_CHECK(test_ldb_abs(5));
55257718be8SEnji Cooper }
55357718be8SEnji Cooper 
55457718be8SEnji Cooper ATF_TC(bpfjit_mbuf_ldh_abs);
ATF_TC_HEAD(bpfjit_mbuf_ldh_abs,tc)55557718be8SEnji Cooper ATF_TC_HEAD(bpfjit_mbuf_ldh_abs, tc)
55657718be8SEnji Cooper {
55757718be8SEnji Cooper 
55857718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Check that BPF_LD+BPF_H+BPF_ABS "
55957718be8SEnji Cooper 	    "loads halfwords from mbuf correctly");
56057718be8SEnji Cooper }
56157718be8SEnji Cooper 
ATF_TC_BODY(bpfjit_mbuf_ldh_abs,tc)56257718be8SEnji Cooper ATF_TC_BODY(bpfjit_mbuf_ldh_abs, tc)
56357718be8SEnji Cooper {
56457718be8SEnji Cooper 
56557718be8SEnji Cooper 	RZ(rump_init());
56657718be8SEnji Cooper 
56757718be8SEnji Cooper 	ATF_CHECK(test_ldh_abs(0));
56857718be8SEnji Cooper 	ATF_CHECK(test_ldh_abs(1));
56957718be8SEnji Cooper 	ATF_CHECK(test_ldh_abs(2));
57057718be8SEnji Cooper 	ATF_CHECK(test_ldh_abs(3));
57157718be8SEnji Cooper 	ATF_CHECK(test_ldh_abs(4));
57257718be8SEnji Cooper 	ATF_CHECK(test_ldh_abs(5));
57357718be8SEnji Cooper }
57457718be8SEnji Cooper 
57557718be8SEnji Cooper ATF_TC(bpfjit_mbuf_ldw_abs);
ATF_TC_HEAD(bpfjit_mbuf_ldw_abs,tc)57657718be8SEnji Cooper ATF_TC_HEAD(bpfjit_mbuf_ldw_abs, tc)
57757718be8SEnji Cooper {
57857718be8SEnji Cooper 
57957718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Check that BPF_LD+BPF_W+BPF_ABS "
58057718be8SEnji Cooper 	    "loads words from mbuf correctly");
58157718be8SEnji Cooper }
58257718be8SEnji Cooper 
ATF_TC_BODY(bpfjit_mbuf_ldw_abs,tc)58357718be8SEnji Cooper ATF_TC_BODY(bpfjit_mbuf_ldw_abs, tc)
58457718be8SEnji Cooper {
58557718be8SEnji Cooper 
58657718be8SEnji Cooper 	RZ(rump_init());
58757718be8SEnji Cooper 
58857718be8SEnji Cooper 	ATF_CHECK(test_ldw_abs(0));
58957718be8SEnji Cooper 	ATF_CHECK(test_ldw_abs(1));
59057718be8SEnji Cooper 	ATF_CHECK(test_ldw_abs(2));
59157718be8SEnji Cooper 	ATF_CHECK(test_ldw_abs(3));
59257718be8SEnji Cooper 	ATF_CHECK(test_ldw_abs(4));
59357718be8SEnji Cooper 	ATF_CHECK(test_ldw_abs(5));
59457718be8SEnji Cooper }
59557718be8SEnji Cooper 
59657718be8SEnji Cooper ATF_TC(bpfjit_mbuf_ldb_ind);
ATF_TC_HEAD(bpfjit_mbuf_ldb_ind,tc)59757718be8SEnji Cooper ATF_TC_HEAD(bpfjit_mbuf_ldb_ind, tc)
59857718be8SEnji Cooper {
59957718be8SEnji Cooper 
60057718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Check that BPF_LD+BPF_B+BPF_IND "
60157718be8SEnji Cooper 	    "loads bytes from mbuf correctly");
60257718be8SEnji Cooper }
60357718be8SEnji Cooper 
ATF_TC_BODY(bpfjit_mbuf_ldb_ind,tc)60457718be8SEnji Cooper ATF_TC_BODY(bpfjit_mbuf_ldb_ind, tc)
60557718be8SEnji Cooper {
60657718be8SEnji Cooper 
60757718be8SEnji Cooper 	RZ(rump_init());
60857718be8SEnji Cooper 
60957718be8SEnji Cooper 	ATF_CHECK(test_ldb_ind(0));
61057718be8SEnji Cooper 	ATF_CHECK(test_ldb_ind(1));
61157718be8SEnji Cooper 	ATF_CHECK(test_ldb_ind(2));
61257718be8SEnji Cooper 	ATF_CHECK(test_ldb_ind(3));
61357718be8SEnji Cooper 	ATF_CHECK(test_ldb_ind(4));
61457718be8SEnji Cooper 	ATF_CHECK(test_ldb_ind(5));
61557718be8SEnji Cooper }
61657718be8SEnji Cooper 
61757718be8SEnji Cooper ATF_TC(bpfjit_mbuf_ldh_ind);
ATF_TC_HEAD(bpfjit_mbuf_ldh_ind,tc)61857718be8SEnji Cooper ATF_TC_HEAD(bpfjit_mbuf_ldh_ind, tc)
61957718be8SEnji Cooper {
62057718be8SEnji Cooper 
62157718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Check that BPF_LD+BPF_H+BPF_IND "
62257718be8SEnji Cooper 	    "loads halfwords from mbuf correctly");
62357718be8SEnji Cooper }
62457718be8SEnji Cooper 
ATF_TC_BODY(bpfjit_mbuf_ldh_ind,tc)62557718be8SEnji Cooper ATF_TC_BODY(bpfjit_mbuf_ldh_ind, tc)
62657718be8SEnji Cooper {
62757718be8SEnji Cooper 
62857718be8SEnji Cooper 	RZ(rump_init());
62957718be8SEnji Cooper 
63057718be8SEnji Cooper 	ATF_CHECK(test_ldh_ind(0));
63157718be8SEnji Cooper 	ATF_CHECK(test_ldh_ind(1));
63257718be8SEnji Cooper 	ATF_CHECK(test_ldh_ind(2));
63357718be8SEnji Cooper 	ATF_CHECK(test_ldh_ind(3));
63457718be8SEnji Cooper 	ATF_CHECK(test_ldh_ind(4));
63557718be8SEnji Cooper 	ATF_CHECK(test_ldh_ind(5));
63657718be8SEnji Cooper }
63757718be8SEnji Cooper 
63857718be8SEnji Cooper ATF_TC(bpfjit_mbuf_ldw_ind);
ATF_TC_HEAD(bpfjit_mbuf_ldw_ind,tc)63957718be8SEnji Cooper ATF_TC_HEAD(bpfjit_mbuf_ldw_ind, tc)
64057718be8SEnji Cooper {
64157718be8SEnji Cooper 
64257718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Check that BPF_LD+BPF_W+BPF_IND "
64357718be8SEnji Cooper 	    "loads words from mbuf correctly");
64457718be8SEnji Cooper }
64557718be8SEnji Cooper 
ATF_TC_BODY(bpfjit_mbuf_ldw_ind,tc)64657718be8SEnji Cooper ATF_TC_BODY(bpfjit_mbuf_ldw_ind, tc)
64757718be8SEnji Cooper {
64857718be8SEnji Cooper 
64957718be8SEnji Cooper 	RZ(rump_init());
65057718be8SEnji Cooper 
65157718be8SEnji Cooper 	ATF_CHECK(test_ldw_ind(0));
65257718be8SEnji Cooper 	ATF_CHECK(test_ldw_ind(1));
65357718be8SEnji Cooper 	ATF_CHECK(test_ldw_ind(2));
65457718be8SEnji Cooper 	ATF_CHECK(test_ldw_ind(3));
65557718be8SEnji Cooper 	ATF_CHECK(test_ldw_ind(4));
65657718be8SEnji Cooper 	ATF_CHECK(test_ldw_ind(5));
65757718be8SEnji Cooper }
65857718be8SEnji Cooper 
65957718be8SEnji Cooper ATF_TC(bpfjit_mbuf_msh);
ATF_TC_HEAD(bpfjit_mbuf_msh,tc)66057718be8SEnji Cooper ATF_TC_HEAD(bpfjit_mbuf_msh, tc)
66157718be8SEnji Cooper {
66257718be8SEnji Cooper 
66357718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Check that BPF_LDX+BPF_B+BPF_MSH "
66457718be8SEnji Cooper 	    "loads bytes from mbuf correctly");
66557718be8SEnji Cooper }
66657718be8SEnji Cooper 
ATF_TC_BODY(bpfjit_mbuf_msh,tc)66757718be8SEnji Cooper ATF_TC_BODY(bpfjit_mbuf_msh, tc)
66857718be8SEnji Cooper {
66957718be8SEnji Cooper 
67057718be8SEnji Cooper 	RZ(rump_init());
67157718be8SEnji Cooper 
67257718be8SEnji Cooper 	ATF_CHECK(test_msh(0));
67357718be8SEnji Cooper 	ATF_CHECK(test_msh(1));
67457718be8SEnji Cooper 	ATF_CHECK(test_msh(2));
67557718be8SEnji Cooper 	ATF_CHECK(test_msh(3));
67657718be8SEnji Cooper 	ATF_CHECK(test_msh(4));
67757718be8SEnji Cooper 	ATF_CHECK(test_msh(5));
67857718be8SEnji Cooper }
67957718be8SEnji Cooper 
68057718be8SEnji Cooper ATF_TC(bpfjit_mbuf_ldb_abs_overflow);
ATF_TC_HEAD(bpfjit_mbuf_ldb_abs_overflow,tc)68157718be8SEnji Cooper ATF_TC_HEAD(bpfjit_mbuf_ldb_abs_overflow, tc)
68257718be8SEnji Cooper {
68357718be8SEnji Cooper 
68457718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Check that BPF_LD+BPF_B+BPF_ABS "
68557718be8SEnji Cooper 	    "with out-of-bounds index aborts a filter program");
68657718be8SEnji Cooper }
68757718be8SEnji Cooper 
ATF_TC_BODY(bpfjit_mbuf_ldb_abs_overflow,tc)68857718be8SEnji Cooper ATF_TC_BODY(bpfjit_mbuf_ldb_abs_overflow, tc)
68957718be8SEnji Cooper {
69057718be8SEnji Cooper 
69157718be8SEnji Cooper 	RZ(rump_init());
69257718be8SEnji Cooper 
69357718be8SEnji Cooper 	ATF_CHECK(test_ldb_abs_overflow(0));
69457718be8SEnji Cooper 	ATF_CHECK(test_ldb_abs_overflow(1));
69557718be8SEnji Cooper 	ATF_CHECK(test_ldb_abs_overflow(2));
69657718be8SEnji Cooper 	ATF_CHECK(test_ldb_abs_overflow(3));
69757718be8SEnji Cooper 	ATF_CHECK(test_ldb_abs_overflow(4));
69857718be8SEnji Cooper 	ATF_CHECK(test_ldb_abs_overflow(5));
69957718be8SEnji Cooper }
70057718be8SEnji Cooper 
70157718be8SEnji Cooper ATF_TC(bpfjit_mbuf_ldh_abs_overflow);
ATF_TC_HEAD(bpfjit_mbuf_ldh_abs_overflow,tc)70257718be8SEnji Cooper ATF_TC_HEAD(bpfjit_mbuf_ldh_abs_overflow, tc)
70357718be8SEnji Cooper {
70457718be8SEnji Cooper 
70557718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Check that BPF_LD+BPF_H+BPF_ABS "
70657718be8SEnji Cooper 	    "with out-of-bounds index aborts a filter program");
70757718be8SEnji Cooper }
70857718be8SEnji Cooper 
ATF_TC_BODY(bpfjit_mbuf_ldh_abs_overflow,tc)70957718be8SEnji Cooper ATF_TC_BODY(bpfjit_mbuf_ldh_abs_overflow, tc)
71057718be8SEnji Cooper {
71157718be8SEnji Cooper 
71257718be8SEnji Cooper 	RZ(rump_init());
71357718be8SEnji Cooper 
71457718be8SEnji Cooper 	ATF_CHECK(test_ldh_abs_overflow(0));
71557718be8SEnji Cooper 	ATF_CHECK(test_ldh_abs_overflow(1));
71657718be8SEnji Cooper 	ATF_CHECK(test_ldh_abs_overflow(2));
71757718be8SEnji Cooper 	ATF_CHECK(test_ldh_abs_overflow(3));
71857718be8SEnji Cooper 	ATF_CHECK(test_ldh_abs_overflow(4));
71957718be8SEnji Cooper 	ATF_CHECK(test_ldh_abs_overflow(5));
72057718be8SEnji Cooper }
72157718be8SEnji Cooper 
72257718be8SEnji Cooper ATF_TC(bpfjit_mbuf_ldw_abs_overflow);
ATF_TC_HEAD(bpfjit_mbuf_ldw_abs_overflow,tc)72357718be8SEnji Cooper ATF_TC_HEAD(bpfjit_mbuf_ldw_abs_overflow, tc)
72457718be8SEnji Cooper {
72557718be8SEnji Cooper 
72657718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Check that BPF_LD+BPF_W+BPF_ABS "
72757718be8SEnji Cooper 	    "with out-of-bounds index aborts a filter program");
72857718be8SEnji Cooper }
72957718be8SEnji Cooper 
ATF_TC_BODY(bpfjit_mbuf_ldw_abs_overflow,tc)73057718be8SEnji Cooper ATF_TC_BODY(bpfjit_mbuf_ldw_abs_overflow, tc)
73157718be8SEnji Cooper {
73257718be8SEnji Cooper 
73357718be8SEnji Cooper 	RZ(rump_init());
73457718be8SEnji Cooper 
73557718be8SEnji Cooper 	ATF_CHECK(test_ldw_abs_overflow(0));
73657718be8SEnji Cooper 	ATF_CHECK(test_ldw_abs_overflow(1));
73757718be8SEnji Cooper 	ATF_CHECK(test_ldw_abs_overflow(2));
73857718be8SEnji Cooper 	ATF_CHECK(test_ldw_abs_overflow(3));
73957718be8SEnji Cooper 	ATF_CHECK(test_ldw_abs_overflow(4));
74057718be8SEnji Cooper 	ATF_CHECK(test_ldw_abs_overflow(5));
74157718be8SEnji Cooper }
74257718be8SEnji Cooper 
74357718be8SEnji Cooper ATF_TC(bpfjit_mbuf_ldb_ind_overflow1);
ATF_TC_HEAD(bpfjit_mbuf_ldb_ind_overflow1,tc)74457718be8SEnji Cooper ATF_TC_HEAD(bpfjit_mbuf_ldb_ind_overflow1, tc)
74557718be8SEnji Cooper {
74657718be8SEnji Cooper 
74757718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Check that BPF_LD+BPF_B+BPF_IND "
74857718be8SEnji Cooper 	    "with out-of-bounds index aborts a filter program");
74957718be8SEnji Cooper }
75057718be8SEnji Cooper 
ATF_TC_BODY(bpfjit_mbuf_ldb_ind_overflow1,tc)75157718be8SEnji Cooper ATF_TC_BODY(bpfjit_mbuf_ldb_ind_overflow1, tc)
75257718be8SEnji Cooper {
75357718be8SEnji Cooper 
75457718be8SEnji Cooper 	RZ(rump_init());
75557718be8SEnji Cooper 
75657718be8SEnji Cooper 	ATF_CHECK(test_ldb_ind_overflow1(0));
75757718be8SEnji Cooper 	ATF_CHECK(test_ldb_ind_overflow1(1));
75857718be8SEnji Cooper 	ATF_CHECK(test_ldb_ind_overflow1(2));
75957718be8SEnji Cooper 	ATF_CHECK(test_ldb_ind_overflow1(3));
76057718be8SEnji Cooper 	ATF_CHECK(test_ldb_ind_overflow1(4));
76157718be8SEnji Cooper 	ATF_CHECK(test_ldb_ind_overflow1(5));
76257718be8SEnji Cooper }
76357718be8SEnji Cooper 
76457718be8SEnji Cooper ATF_TC(bpfjit_mbuf_ldb_ind_overflow2);
ATF_TC_HEAD(bpfjit_mbuf_ldb_ind_overflow2,tc)76557718be8SEnji Cooper ATF_TC_HEAD(bpfjit_mbuf_ldb_ind_overflow2, tc)
76657718be8SEnji Cooper {
76757718be8SEnji Cooper 
76857718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Check that BPF_LD+BPF_B+BPF_IND "
76957718be8SEnji Cooper 	    "with out-of-bounds index aborts a filter program");
77057718be8SEnji Cooper }
77157718be8SEnji Cooper 
ATF_TC_BODY(bpfjit_mbuf_ldb_ind_overflow2,tc)77257718be8SEnji Cooper ATF_TC_BODY(bpfjit_mbuf_ldb_ind_overflow2, tc)
77357718be8SEnji Cooper {
77457718be8SEnji Cooper 
77557718be8SEnji Cooper 	RZ(rump_init());
77657718be8SEnji Cooper 
77757718be8SEnji Cooper 	ATF_CHECK(test_ldb_ind_overflow2(0));
77857718be8SEnji Cooper 	ATF_CHECK(test_ldb_ind_overflow2(1));
77957718be8SEnji Cooper 	ATF_CHECK(test_ldb_ind_overflow2(2));
78057718be8SEnji Cooper 	ATF_CHECK(test_ldb_ind_overflow2(3));
78157718be8SEnji Cooper 	ATF_CHECK(test_ldb_ind_overflow2(4));
78257718be8SEnji Cooper 	ATF_CHECK(test_ldb_ind_overflow2(5));
78357718be8SEnji Cooper }
78457718be8SEnji Cooper 
78557718be8SEnji Cooper ATF_TC(bpfjit_mbuf_ldb_ind_overflow3);
ATF_TC_HEAD(bpfjit_mbuf_ldb_ind_overflow3,tc)78657718be8SEnji Cooper ATF_TC_HEAD(bpfjit_mbuf_ldb_ind_overflow3, tc)
78757718be8SEnji Cooper {
78857718be8SEnji Cooper 
78957718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Check that BPF_LD+BPF_B+BPF_IND "
79057718be8SEnji Cooper 	    "with out-of-bounds index aborts a filter program");
79157718be8SEnji Cooper }
79257718be8SEnji Cooper 
ATF_TC_BODY(bpfjit_mbuf_ldb_ind_overflow3,tc)79357718be8SEnji Cooper ATF_TC_BODY(bpfjit_mbuf_ldb_ind_overflow3, tc)
79457718be8SEnji Cooper {
79557718be8SEnji Cooper 
79657718be8SEnji Cooper 	RZ(rump_init());
79757718be8SEnji Cooper 
79857718be8SEnji Cooper 	ATF_CHECK(test_ldb_ind_overflow3(0));
79957718be8SEnji Cooper 	ATF_CHECK(test_ldb_ind_overflow3(1));
80057718be8SEnji Cooper 	ATF_CHECK(test_ldb_ind_overflow3(2));
80157718be8SEnji Cooper 	ATF_CHECK(test_ldb_ind_overflow3(3));
80257718be8SEnji Cooper 	ATF_CHECK(test_ldb_ind_overflow3(4));
80357718be8SEnji Cooper 	ATF_CHECK(test_ldb_ind_overflow3(5));
80457718be8SEnji Cooper }
80557718be8SEnji Cooper 
80657718be8SEnji Cooper ATF_TC(bpfjit_mbuf_ldh_ind_overflow1);
ATF_TC_HEAD(bpfjit_mbuf_ldh_ind_overflow1,tc)80757718be8SEnji Cooper ATF_TC_HEAD(bpfjit_mbuf_ldh_ind_overflow1, tc)
80857718be8SEnji Cooper {
80957718be8SEnji Cooper 
81057718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Check that BPF_LD+BPF_H+BPF_IND "
81157718be8SEnji Cooper 	    "with out-of-bounds index aborts a filter program");
81257718be8SEnji Cooper }
81357718be8SEnji Cooper 
ATF_TC_BODY(bpfjit_mbuf_ldh_ind_overflow1,tc)81457718be8SEnji Cooper ATF_TC_BODY(bpfjit_mbuf_ldh_ind_overflow1, tc)
81557718be8SEnji Cooper {
81657718be8SEnji Cooper 
81757718be8SEnji Cooper 	RZ(rump_init());
81857718be8SEnji Cooper 
81957718be8SEnji Cooper 	ATF_CHECK(test_ldh_ind_overflow1(0));
82057718be8SEnji Cooper 	ATF_CHECK(test_ldh_ind_overflow1(1));
82157718be8SEnji Cooper 	ATF_CHECK(test_ldh_ind_overflow1(2));
82257718be8SEnji Cooper 	ATF_CHECK(test_ldh_ind_overflow1(3));
82357718be8SEnji Cooper 	ATF_CHECK(test_ldh_ind_overflow1(4));
82457718be8SEnji Cooper 	ATF_CHECK(test_ldh_ind_overflow1(5));
82557718be8SEnji Cooper }
82657718be8SEnji Cooper 
82757718be8SEnji Cooper ATF_TC(bpfjit_mbuf_ldh_ind_overflow2);
ATF_TC_HEAD(bpfjit_mbuf_ldh_ind_overflow2,tc)82857718be8SEnji Cooper ATF_TC_HEAD(bpfjit_mbuf_ldh_ind_overflow2, tc)
82957718be8SEnji Cooper {
83057718be8SEnji Cooper 
83157718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Check that BPF_LD+BPF_H+BPF_IND "
83257718be8SEnji Cooper 	    "with out-of-bounds index aborts a filter program");
83357718be8SEnji Cooper }
83457718be8SEnji Cooper 
ATF_TC_BODY(bpfjit_mbuf_ldh_ind_overflow2,tc)83557718be8SEnji Cooper ATF_TC_BODY(bpfjit_mbuf_ldh_ind_overflow2, tc)
83657718be8SEnji Cooper {
83757718be8SEnji Cooper 
83857718be8SEnji Cooper 	RZ(rump_init());
83957718be8SEnji Cooper 
84057718be8SEnji Cooper 	ATF_CHECK(test_ldh_ind_overflow2(0));
84157718be8SEnji Cooper 	ATF_CHECK(test_ldh_ind_overflow2(1));
84257718be8SEnji Cooper 	ATF_CHECK(test_ldh_ind_overflow2(2));
84357718be8SEnji Cooper 	ATF_CHECK(test_ldh_ind_overflow2(3));
84457718be8SEnji Cooper 	ATF_CHECK(test_ldh_ind_overflow2(4));
84557718be8SEnji Cooper 	ATF_CHECK(test_ldh_ind_overflow2(5));
84657718be8SEnji Cooper }
84757718be8SEnji Cooper 
84857718be8SEnji Cooper ATF_TC(bpfjit_mbuf_ldh_ind_overflow3);
ATF_TC_HEAD(bpfjit_mbuf_ldh_ind_overflow3,tc)84957718be8SEnji Cooper ATF_TC_HEAD(bpfjit_mbuf_ldh_ind_overflow3, tc)
85057718be8SEnji Cooper {
85157718be8SEnji Cooper 
85257718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Check that BPF_LD+BPF_H+BPF_IND "
85357718be8SEnji Cooper 	    "with out-of-bounds index aborts a filter program");
85457718be8SEnji Cooper }
85557718be8SEnji Cooper 
ATF_TC_BODY(bpfjit_mbuf_ldh_ind_overflow3,tc)85657718be8SEnji Cooper ATF_TC_BODY(bpfjit_mbuf_ldh_ind_overflow3, tc)
85757718be8SEnji Cooper {
85857718be8SEnji Cooper 
85957718be8SEnji Cooper 	RZ(rump_init());
86057718be8SEnji Cooper 
86157718be8SEnji Cooper 	ATF_CHECK(test_ldh_ind_overflow3(0));
86257718be8SEnji Cooper 	ATF_CHECK(test_ldh_ind_overflow3(1));
86357718be8SEnji Cooper 	ATF_CHECK(test_ldh_ind_overflow3(2));
86457718be8SEnji Cooper 	ATF_CHECK(test_ldh_ind_overflow3(3));
86557718be8SEnji Cooper 	ATF_CHECK(test_ldh_ind_overflow3(4));
86657718be8SEnji Cooper 	ATF_CHECK(test_ldh_ind_overflow3(5));
86757718be8SEnji Cooper }
86857718be8SEnji Cooper 
86957718be8SEnji Cooper ATF_TC(bpfjit_mbuf_ldw_ind_overflow1);
ATF_TC_HEAD(bpfjit_mbuf_ldw_ind_overflow1,tc)87057718be8SEnji Cooper ATF_TC_HEAD(bpfjit_mbuf_ldw_ind_overflow1, tc)
87157718be8SEnji Cooper {
87257718be8SEnji Cooper 
87357718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Check that BPF_LD+BPF_W+BPF_IND "
87457718be8SEnji Cooper 	    "with out-of-bounds index aborts a filter program");
87557718be8SEnji Cooper }
87657718be8SEnji Cooper 
ATF_TC_BODY(bpfjit_mbuf_ldw_ind_overflow1,tc)87757718be8SEnji Cooper ATF_TC_BODY(bpfjit_mbuf_ldw_ind_overflow1, tc)
87857718be8SEnji Cooper {
87957718be8SEnji Cooper 
88057718be8SEnji Cooper 	RZ(rump_init());
88157718be8SEnji Cooper 
88257718be8SEnji Cooper 	ATF_CHECK(test_ldw_ind_overflow1(0));
88357718be8SEnji Cooper 	ATF_CHECK(test_ldw_ind_overflow1(1));
88457718be8SEnji Cooper 	ATF_CHECK(test_ldw_ind_overflow1(2));
88557718be8SEnji Cooper 	ATF_CHECK(test_ldw_ind_overflow1(3));
88657718be8SEnji Cooper 	ATF_CHECK(test_ldw_ind_overflow1(4));
88757718be8SEnji Cooper 	ATF_CHECK(test_ldw_ind_overflow1(5));
88857718be8SEnji Cooper }
88957718be8SEnji Cooper 
89057718be8SEnji Cooper ATF_TC(bpfjit_mbuf_ldw_ind_overflow2);
ATF_TC_HEAD(bpfjit_mbuf_ldw_ind_overflow2,tc)89157718be8SEnji Cooper ATF_TC_HEAD(bpfjit_mbuf_ldw_ind_overflow2, tc)
89257718be8SEnji Cooper {
89357718be8SEnji Cooper 
89457718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Check that BPF_LD+BPF_W+BPF_IND "
89557718be8SEnji Cooper 	    "with out-of-bounds index aborts a filter program");
89657718be8SEnji Cooper }
89757718be8SEnji Cooper 
ATF_TC_BODY(bpfjit_mbuf_ldw_ind_overflow2,tc)89857718be8SEnji Cooper ATF_TC_BODY(bpfjit_mbuf_ldw_ind_overflow2, tc)
89957718be8SEnji Cooper {
90057718be8SEnji Cooper 
90157718be8SEnji Cooper 	RZ(rump_init());
90257718be8SEnji Cooper 
90357718be8SEnji Cooper 	ATF_CHECK(test_ldw_ind_overflow2(0));
90457718be8SEnji Cooper 	ATF_CHECK(test_ldw_ind_overflow2(1));
90557718be8SEnji Cooper 	ATF_CHECK(test_ldw_ind_overflow2(2));
90657718be8SEnji Cooper 	ATF_CHECK(test_ldw_ind_overflow2(3));
90757718be8SEnji Cooper 	ATF_CHECK(test_ldw_ind_overflow2(4));
90857718be8SEnji Cooper 	ATF_CHECK(test_ldw_ind_overflow2(5));
90957718be8SEnji Cooper }
91057718be8SEnji Cooper 
91157718be8SEnji Cooper ATF_TC(bpfjit_mbuf_ldw_ind_overflow3);
ATF_TC_HEAD(bpfjit_mbuf_ldw_ind_overflow3,tc)91257718be8SEnji Cooper ATF_TC_HEAD(bpfjit_mbuf_ldw_ind_overflow3, tc)
91357718be8SEnji Cooper {
91457718be8SEnji Cooper 
91557718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Check that BPF_LD+BPF_W+BPF_IND "
91657718be8SEnji Cooper 	    "with out-of-bounds index aborts a filter program");
91757718be8SEnji Cooper }
91857718be8SEnji Cooper 
ATF_TC_BODY(bpfjit_mbuf_ldw_ind_overflow3,tc)91957718be8SEnji Cooper ATF_TC_BODY(bpfjit_mbuf_ldw_ind_overflow3, tc)
92057718be8SEnji Cooper {
92157718be8SEnji Cooper 
92257718be8SEnji Cooper 	RZ(rump_init());
92357718be8SEnji Cooper 
92457718be8SEnji Cooper 	ATF_CHECK(test_ldw_ind_overflow3(0));
92557718be8SEnji Cooper 	ATF_CHECK(test_ldw_ind_overflow3(1));
92657718be8SEnji Cooper 	ATF_CHECK(test_ldw_ind_overflow3(2));
92757718be8SEnji Cooper 	ATF_CHECK(test_ldw_ind_overflow3(3));
92857718be8SEnji Cooper 	ATF_CHECK(test_ldw_ind_overflow3(4));
92957718be8SEnji Cooper 	ATF_CHECK(test_ldw_ind_overflow3(5));
93057718be8SEnji Cooper }
93157718be8SEnji Cooper 
93257718be8SEnji Cooper ATF_TC(bpfjit_mbuf_msh_overflow);
ATF_TC_HEAD(bpfjit_mbuf_msh_overflow,tc)93357718be8SEnji Cooper ATF_TC_HEAD(bpfjit_mbuf_msh_overflow, tc)
93457718be8SEnji Cooper {
93557718be8SEnji Cooper 
93657718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Check that BPF_LDX+BPF_B+BPF_MSH "
93757718be8SEnji Cooper 	    "with out-of-bounds index aborts a filter program");
93857718be8SEnji Cooper }
93957718be8SEnji Cooper 
ATF_TC_BODY(bpfjit_mbuf_msh_overflow,tc)94057718be8SEnji Cooper ATF_TC_BODY(bpfjit_mbuf_msh_overflow, tc)
94157718be8SEnji Cooper {
94257718be8SEnji Cooper 
94357718be8SEnji Cooper 	RZ(rump_init());
94457718be8SEnji Cooper 
94557718be8SEnji Cooper 	ATF_CHECK(test_msh_overflow(0));
94657718be8SEnji Cooper 	ATF_CHECK(test_msh_overflow(1));
94757718be8SEnji Cooper 	ATF_CHECK(test_msh_overflow(2));
94857718be8SEnji Cooper 	ATF_CHECK(test_msh_overflow(3));
94957718be8SEnji Cooper 	ATF_CHECK(test_msh_overflow(4));
95057718be8SEnji Cooper 	ATF_CHECK(test_msh_overflow(5));
95157718be8SEnji Cooper }
95257718be8SEnji Cooper 
ATF_TP_ADD_TCS(tp)95357718be8SEnji Cooper ATF_TP_ADD_TCS(tp)
95457718be8SEnji Cooper {
95557718be8SEnji Cooper 
95657718be8SEnji Cooper 	/*
95757718be8SEnji Cooper 	 * For every new test please also add a similar test
95857718be8SEnji Cooper 	 * to ../../net/bpf/t_mbuf.c
95957718be8SEnji Cooper 	 */
96057718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, bpfjit_mbuf_ldb_abs);
96157718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, bpfjit_mbuf_ldh_abs);
96257718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, bpfjit_mbuf_ldw_abs);
96357718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, bpfjit_mbuf_ldb_ind);
96457718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, bpfjit_mbuf_ldh_ind);
96557718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, bpfjit_mbuf_ldw_ind);
96657718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, bpfjit_mbuf_msh);
96757718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, bpfjit_mbuf_ldb_abs_overflow);
96857718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, bpfjit_mbuf_ldh_abs_overflow);
96957718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, bpfjit_mbuf_ldw_abs_overflow);
97057718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, bpfjit_mbuf_ldb_ind_overflow1);
97157718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, bpfjit_mbuf_ldb_ind_overflow2);
97257718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, bpfjit_mbuf_ldb_ind_overflow3);
97357718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, bpfjit_mbuf_ldh_ind_overflow1);
97457718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, bpfjit_mbuf_ldh_ind_overflow2);
97557718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, bpfjit_mbuf_ldh_ind_overflow3);
97657718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, bpfjit_mbuf_ldw_ind_overflow1);
97757718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, bpfjit_mbuf_ldw_ind_overflow2);
97857718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, bpfjit_mbuf_ldw_ind_overflow3);
97957718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, bpfjit_mbuf_msh_overflow);
98057718be8SEnji Cooper 
98157718be8SEnji Cooper 	return atf_no_error();
98257718be8SEnji Cooper }
983