Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/net/bpfilter Add bpfilterbadjmp and bpfilterbadret tests.
details: https://anonhg.NetBSD.org/src/rev/c164dda389db
branches: trunk
changeset: 336086:c164dda389db
user: alnsn <alnsn%NetBSD.org@localhost>
date: Wed Feb 11 19:37:37 2015 +0000
description:
Add bpfilterbadjmp and bpfilterbadret tests.
diffstat:
tests/net/bpfilter/t_bpfilter.c | 61 +++++++++++++++++++++++++++++++++++++++-
1 files changed, 59 insertions(+), 2 deletions(-)
diffs (96 lines):
diff -r ac2fb4dc6515 -r c164dda389db tests/net/bpfilter/t_bpfilter.c
--- a/tests/net/bpfilter/t_bpfilter.c Wed Feb 11 15:19:05 2015 +0000
+++ b/tests/net/bpfilter/t_bpfilter.c Wed Feb 11 19:37:37 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_bpfilter.c,v 1.8 2014/06/24 11:32:36 alnsn Exp $ */
+/* $NetBSD: t_bpfilter.c,v 1.9 2015/02/11 19:37:37 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.8 2014/06/24 11:32:36 alnsn Exp $");
+__RCSID("$NetBSD: t_bpfilter.c,v 1.9 2015/02/11 19:37:37 alnsn Exp $");
#include <sys/param.h>
#include <sys/ioctl.h>
@@ -115,6 +115,15 @@
BPF_STMT(BPF_RET+BPF_A, 0),
};
+static struct bpf_insn badjmp_prog[] = {
+ BPF_STMT(BPF_JMP+BPF_JA, 5),
+ BPF_STMT(BPF_RET+BPF_A, 0),
+};
+
+static struct bpf_insn badret_prog[] = {
+ BPF_STMT(BPF_RET+BPF_A+0x8000, 0),
+};
+
static uint16_t
in_cksum(void *data, size_t len)
{
@@ -387,6 +396,52 @@
RL(send_bpf_prog("bpfilternoinitX", &prog));
}
+ATF_TC(bpfilterbadjmp);
+ATF_TC_HEAD(bpfilterbadjmp, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr", "Checks that bpf program that "
+ "jumps to invalid destination is rejected by the kernel");
+ atf_tc_set_md_var(tc, "timeout", "30");
+}
+
+ATF_TC_BODY(bpfilterbadjmp, tc)
+{
+ struct bpf_program prog;
+
+ prog.bf_len = __arraycount(badjmp_prog);
+ prog.bf_insns = badjmp_prog;
+ ATF_CHECK_ERRNO(EINVAL, send_bpf_prog("bpfilterbadjmp", &prog) == -1);
+}
+
+ATF_TC(bpfilterbadret);
+ATF_TC_HEAD(bpfilterbadret, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr", "Checks that bpf program that "
+ "ends with invalid BPF_RET instruction is rejected by the kernel");
+ atf_tc_set_md_var(tc, "timeout", "30");
+}
+
+ATF_TC_BODY(bpfilterbadret, tc)
+{
+ struct bpf_program prog;
+ struct bpf_insn *last;
+
+ prog.bf_len = __arraycount(badret_prog);
+ prog.bf_insns = badret_prog;
+
+ /*
+ * The point of this test is checking a bad instruction of
+ * a valid class and with a valid BPF_RVAL data.
+ */
+ last = &prog.bf_insns[prog.bf_len - 1];
+ ATF_CHECK(BPF_CLASS(last->code) == BPF_RET &&
+ (BPF_RVAL(last->code) == BPF_K || BPF_RVAL(last->code) == BPF_A));
+
+ ATF_CHECK_ERRNO(EINVAL, send_bpf_prog("bpfilterbadret", &prog) == -1);
+}
+
ATF_TP_ADD_TCS(tp)
{
@@ -395,6 +450,8 @@
ATF_TP_ADD_TC(tp, bpfilterbadmem);
ATF_TP_ADD_TC(tp, bpfilternoinitA);
ATF_TP_ADD_TC(tp, bpfilternoinitX);
+ ATF_TP_ADD_TC(tp, bpfilterbadjmp);
+ ATF_TP_ADD_TC(tp, bpfilterbadret);
return atf_no_error();
}
Home |
Main Index |
Thread Index |
Old Index