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 bpfilterbadmem, bpfilternoinitA and b...
details: https://anonhg.NetBSD.org/src/rev/2021361aaddc
branches: trunk
changeset: 325333:2021361aaddc
user: alnsn <alnsn%NetBSD.org@localhost>
date: Wed Dec 18 22:39:16 2013 +0000
description:
Add bpfilterbadmem, bpfilternoinitA and bpfilternoinitX tests.
diffstat:
tests/net/bpfilter/t_bpfilter.c | 96 ++++++++++++++++++++++++++++++++++++++++-
1 files changed, 94 insertions(+), 2 deletions(-)
diffs (136 lines):
diff -r 3c2f03eb77ec -r 2021361aaddc tests/net/bpfilter/t_bpfilter.c
--- a/tests/net/bpfilter/t_bpfilter.c Wed Dec 18 20:56:32 2013 +0000
+++ b/tests/net/bpfilter/t_bpfilter.c Wed Dec 18 22:39:16 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_bpfilter.c,v 1.6 2012/09/03 21:27:14 alnsn Exp $ */
+/* $NetBSD: t_bpfilter.c,v 1.7 2013/12/18 22:39:16 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.6 2012/09/03 21:27:14 alnsn Exp $");
+__RCSID("$NetBSD: t_bpfilter.c,v 1.7 2013/12/18 22:39:16 alnsn Exp $");
#include <sys/param.h>
#include <sys/ioctl.h>
@@ -101,6 +101,20 @@
BPF_STMT(BPF_RET+BPF_K, SNAPLEN)
};
+static struct bpf_insn badmem_prog[] = {
+ BPF_STMT(BPF_LD+BPF_MEM, 5),
+ BPF_STMT(BPF_RET+BPF_A, 0),
+};
+
+static struct bpf_insn noinitA_prog[] = {
+ BPF_STMT(BPF_RET+BPF_A, 0),
+};
+
+static struct bpf_insn noinitX_prog[] = {
+ BPF_STMT(BPF_MISC+BPF_TXA, 0),
+ BPF_STMT(BPF_RET+BPF_A, 0),
+};
+
static uint16_t
in_cksum(void *data, size_t len)
{
@@ -266,6 +280,27 @@
kill(child, SIGKILL);
}
+static int
+send_bpf_prog(const char *ifname, struct bpf_program *prog)
+{
+ struct ifreq ifr;
+ int bpfd, e, rv;
+
+ RZ(rump_init());
+ netcfg_rump_makeshmif(ifname, ifr.ifr_name);
+ netcfg_rump_if(ifr.ifr_name, "10.1.1.20", "255.0.0.0");
+
+ RL(bpfd = rump_sys_open("/dev/bpf", O_RDONLY));
+
+ rv = rump_sys_ioctl(bpfd, BIOCSETF, prog);
+ e = errno;
+
+ rump_sys_close(bpfd);
+ errno = e;
+
+ return rv;
+}
+
ATF_TC(bpfiltercontig);
ATF_TC_HEAD(bpfiltercontig, tc)
{
@@ -298,11 +333,68 @@
}
+ATF_TC(bpfilterbadmem);
+ATF_TC_HEAD(bpfilterbadmem, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr", "Checks that bpf program that "
+ "doesn't initialize memomy store is rejected by the kernel");
+ atf_tc_set_md_var(tc, "timeout", "30");
+}
+
+ATF_TC_BODY(bpfilterbadmem, tc)
+{
+ struct bpf_program prog;
+
+ prog.bf_len = __arraycount(badmem_prog);
+ prog.bf_insns = badmem_prog;
+ ATF_CHECK_ERRNO(EINVAL, send_bpf_prog("bpfilterbadmem", &prog) == -1);
+}
+
+ATF_TC(bpfilternoinitA);
+ATF_TC_HEAD(bpfilternoinitA, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr", "Checks that bpf program that "
+ "doesn't initialize the A register is accepted by the kernel");
+ atf_tc_set_md_var(tc, "timeout", "30");
+}
+
+ATF_TC_BODY(bpfilternoinitA, tc)
+{
+ struct bpf_program prog;
+
+ prog.bf_len = __arraycount(noinitA_prog);
+ prog.bf_insns = noinitA_prog;
+ RL(send_bpf_prog("bpfilternoinitA", &prog));
+}
+
+ATF_TC(bpfilternoinitX);
+ATF_TC_HEAD(bpfilternoinitX, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr", "Checks that bpf program that "
+ "doesn't initialize the X register is accepted by the kernel");
+ atf_tc_set_md_var(tc, "timeout", "30");
+}
+
+ATF_TC_BODY(bpfilternoinitX, tc)
+{
+ struct bpf_program prog;
+
+ prog.bf_len = __arraycount(noinitX_prog);
+ prog.bf_insns = noinitX_prog;
+ RL(send_bpf_prog("bpfilternoinitX", &prog));
+}
+
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, bpfiltercontig);
ATF_TP_ADD_TC(tp, bpfiltermchain);
+ ATF_TP_ADD_TC(tp, bpfilterbadmem);
+ ATF_TP_ADD_TC(tp, bpfilternoinitA);
+ ATF_TP_ADD_TC(tp, bpfilternoinitX);
return atf_no_error();
}
Home |
Main Index |
Thread Index |
Old Index