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 bpfilternegjmp test.
details: https://anonhg.NetBSD.org/src/rev/43811470d7b0
branches: trunk
changeset: 336094:43811470d7b0
user: alnsn <alnsn%NetBSD.org@localhost>
date: Wed Feb 11 23:39:07 2015 +0000
description:
Add bpfilternegjmp test.
diffstat:
tests/net/bpfilter/t_bpfilter.c | 29 +++++++++++++++++++++++++++--
1 files changed, 27 insertions(+), 2 deletions(-)
diffs (64 lines):
diff -r 80827642d1c2 -r 43811470d7b0 tests/net/bpfilter/t_bpfilter.c
--- a/tests/net/bpfilter/t_bpfilter.c Wed Feb 11 23:33:16 2015 +0000
+++ b/tests/net/bpfilter/t_bpfilter.c Wed Feb 11 23:39:07 2015 +0000
@@ -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 @@
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_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_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();
Home |
Main Index |
Thread Index |
Old Index