Module Name: src Committed By: alnsn Date: Wed Feb 11 23:39:07 UTC 2015
Modified Files: src/tests/net/bpfilter: t_bpfilter.c Log Message: Add bpfilternegjmp test. To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/tests/net/bpfilter/t_bpfilter.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/net/bpfilter/t_bpfilter.c diff -u src/tests/net/bpfilter/t_bpfilter.c:1.9 src/tests/net/bpfilter/t_bpfilter.c:1.10 --- src/tests/net/bpfilter/t_bpfilter.c:1.9 Wed Feb 11 19:37:37 2015 +++ src/tests/net/bpfilter/t_bpfilter.c Wed Feb 11 23:39:07 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: t_bpfilter.c,v 1.9 2015/02/11 19:37:37 alnsn Exp $ */ +/* $NetBSD: t_bpfilter.c,v 1.10 2015/02/11 23:39:07 alnsn Exp $ */ /*- * Copyright (c) 2012 The NetBSD Foundation, Inc. @@ -25,7 +25,7 @@ * SUCH DAMAGE. */ #include <sys/cdefs.h> -__RCSID("$NetBSD: t_bpfilter.c,v 1.9 2015/02/11 19:37:37 alnsn Exp $"); +__RCSID("$NetBSD: t_bpfilter.c,v 1.10 2015/02/11 23:39:07 alnsn Exp $"); #include <sys/param.h> #include <sys/ioctl.h> @@ -120,6 +120,12 @@ static struct bpf_insn badjmp_prog[] = { BPF_STMT(BPF_RET+BPF_A, 0), }; +static struct bpf_insn negjmp_prog[] = { + BPF_STMT(BPF_JMP+BPF_JA, 0), + BPF_STMT(BPF_JMP+BPF_JA, UINT32_MAX - 1), // -2 + BPF_STMT(BPF_RET+BPF_A, 0), +}; + static struct bpf_insn badret_prog[] = { BPF_STMT(BPF_RET+BPF_A+0x8000, 0), }; @@ -414,6 +420,24 @@ ATF_TC_BODY(bpfilterbadjmp, tc) ATF_CHECK_ERRNO(EINVAL, send_bpf_prog("bpfilterbadjmp", &prog) == -1); } +ATF_TC(bpfilternegjmp); +ATF_TC_HEAD(bpfilternegjmp, tc) +{ + + atf_tc_set_md_var(tc, "descr", "Checks that bpf program that " + "jumps backwards is rejected by the kernel"); + atf_tc_set_md_var(tc, "timeout", "30"); +} + +ATF_TC_BODY(bpfilternegjmp, tc) +{ + struct bpf_program prog; + + prog.bf_len = __arraycount(negjmp_prog); + prog.bf_insns = negjmp_prog; + ATF_CHECK_ERRNO(EINVAL, send_bpf_prog("bpfilternegjmp", &prog) == -1); +} + ATF_TC(bpfilterbadret); ATF_TC_HEAD(bpfilterbadret, tc) { @@ -451,6 +475,7 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, bpfilternoinitA); ATF_TP_ADD_TC(tp, bpfilternoinitX); ATF_TP_ADD_TC(tp, bpfilterbadjmp); + ATF_TP_ADD_TC(tp, bpfilternegjmp); ATF_TP_ADD_TC(tp, bpfilterbadret); return atf_no_error();