CVS commit: src/tests/lib/libi386
Module Name:src Committed By: christos Date: Fri Apr 30 13:53:30 UTC 2021 Modified Files: src/tests/lib/libi386: t_user_ldt.c Log Message: remove hacks. To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/tests/lib/libi386/t_user_ldt.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/lib/libi386/t_user_ldt.c diff -u src/tests/lib/libi386/t_user_ldt.c:1.5 src/tests/lib/libi386/t_user_ldt.c:1.6 --- src/tests/lib/libi386/t_user_ldt.c:1.5 Sun Jul 19 10:31:31 2020 +++ src/tests/lib/libi386/t_user_ldt.c Fri Apr 30 09:53:30 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: t_user_ldt.c,v 1.5 2020/07/19 14:31:31 maxv Exp $ */ +/* $NetBSD: t_user_ldt.c,v 1.6 2021/04/30 13:53:30 christos Exp $ */ /* * Copyright (c) 2020 The NetBSD Foundation, Inc. @@ -41,10 +41,7 @@ #include #include #include - -#define _LOCORE /* XXX a bit of a hack, but whatever */ #include -#undef _LOCORE #include
CVS commit: src/tests/lib/libi386
Module Name:src Committed By: maxv Date: Fri Jul 3 16:07:52 UTC 2020 Modified Files: src/tests/lib/libi386: t_user_ldt.c Log Message: more To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libi386/t_user_ldt.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/lib/libi386/t_user_ldt.c diff -u src/tests/lib/libi386/t_user_ldt.c:1.3 src/tests/lib/libi386/t_user_ldt.c:1.4 --- src/tests/lib/libi386/t_user_ldt.c:1.3 Sat May 9 09:08:41 2020 +++ src/tests/lib/libi386/t_user_ldt.c Fri Jul 3 16:07:52 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_user_ldt.c,v 1.3 2020/05/09 09:08:41 maxv Exp $ */ +/* $NetBSD: t_user_ldt.c,v 1.4 2020/07/03 16:07:52 maxv Exp $ */ /* * Copyright (c) 2020 The NetBSD Foundation, Inc. @@ -92,6 +92,12 @@ build_desc(union descriptor *desc, void } static void +set_ds(unsigned int val) +{ + __asm volatile("mov %0,%%ds"::"r" ((unsigned short)val)); +} + +static void set_fs(unsigned int val) { __asm volatile("mov %0,%%fs"::"r" ((unsigned short)val)); @@ -181,10 +187,98 @@ ATF_TC_BODY(filter_ops, tc) /* -- */ +static void +iretq_gp__gp_handler(int signo, siginfo_t *sig, void *ctx) +{ + ATF_REQUIRE(sig->si_signo == SIGSEGV); + ATF_REQUIRE(sig->si_code == SEGV_ACCERR); + atf_tc_pass(); + /* NOTREACHED */ +} + +ATF_TC(iretq_gp); +ATF_TC_HEAD(iretq_gp, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Ensure that the kernel correctly handles iretq #GP faults"); +} +ATF_TC_BODY(iretq_gp, tc) +{ + union descriptor desc; + struct sigaction act; + + if (!user_ldt_supported) { + atf_tc_skip("USER_LDT disabled"); + } + + /* Build a desc, set %ds to it. */ + build_desc(, 0, 0xFUL, SDT_MEMRWA, SEL_UPL, 1, 1); + ATF_REQUIRE_EQ(i386_set_ldt(256, , 1), 256); + set_ds(LSEL(256, SEL_UPL)); + + /* Register the fault handler. */ + memset(, 0, sizeof(act)); + act.sa_sigaction = iretq_gp__gp_handler; + act.sa_flags = SA_SIGINFO; + ATF_REQUIRE_EQ(sigaction(SIGSEGV, , NULL), 0); + + /* Set NULL on %ds, iretq should fault. */ + memset(, 0, sizeof(desc)); + ATF_REQUIRE_EQ(i386_set_ldt(256, , 1), 256); + + atf_tc_fail("test did not fault as expected"); +} + +/* -- */ + +static void +iretq_np__np_handler(int signo, siginfo_t *sig, void *ctx) +{ + ATF_REQUIRE(sig->si_signo == SIGBUS); + ATF_REQUIRE(sig->si_code == BUS_ADRERR); + atf_tc_pass(); + /* NOTREACHED */ +} + +ATF_TC(iretq_np); +ATF_TC_HEAD(iretq_np, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Ensure that the kernel correctly handles iretq #NP faults"); +} +ATF_TC_BODY(iretq_np, tc) +{ + union descriptor desc; + struct sigaction act; + + if (!user_ldt_supported) { + atf_tc_skip("USER_LDT disabled"); + } + + /* Build a desc, set %ds to it. */ + build_desc(, 0, 0xUL, SDT_MEMRWA, SEL_UPL, 1, 1); + ATF_REQUIRE_EQ(i386_set_ldt(256, , 1), 256); + set_ds(LSEL(256, SEL_UPL)); + + /* Register the fault handler. */ + memset(, 0, sizeof(act)); + act.sa_sigaction = iretq_np__np_handler; + act.sa_flags = SA_SIGINFO; + ATF_REQUIRE_EQ(sigaction(SIGBUS, , NULL), 0); + + /* Set non-present on %ds, iretq should fault. */ + desc.sd.sd_p = 0; + ATF_REQUIRE_EQ(i386_set_ldt(256, , 1), 256); + + atf_tc_fail("test did not fault as expected"); +} + +/* -- */ + static volatile bool expect_crash; static void -gp_handler(int signo, siginfo_t *sig, void *ctx) +user_ldt__gp_handler(int signo, siginfo_t *sig, void *ctx) { ucontext_t *uctx = ctx; extern uint8_t fs_read_begin; @@ -222,7 +316,7 @@ ATF_TC_BODY(user_ldt, tc) } memset(, 0, sizeof(act)); - act.sa_sigaction = gp_handler; + act.sa_sigaction = user_ldt__gp_handler; act.sa_flags = SA_SIGINFO; ATF_REQUIRE_EQ(sigaction(SIGSEGV, , NULL), 0); @@ -252,6 +346,8 @@ ATF_TP_ADD_TCS(tp) init_ldt_base(); ATF_TP_ADD_TC(tp, filter_ops); + ATF_TP_ADD_TC(tp, iretq_gp); + ATF_TP_ADD_TC(tp, iretq_np); ATF_TP_ADD_TC(tp, user_ldt); return atf_no_error();
CVS commit: src/tests/lib/libi386
Module Name:src Committed By: maxv Date: Sat May 9 09:08:41 UTC 2020 Modified Files: src/tests/lib/libi386: t_user_ldt.c Log Message: A kernel without USER_LDT returns ENOSYS, not ENOTSUP. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libi386/t_user_ldt.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/lib/libi386/t_user_ldt.c diff -u src/tests/lib/libi386/t_user_ldt.c:1.2 src/tests/lib/libi386/t_user_ldt.c:1.3 --- src/tests/lib/libi386/t_user_ldt.c:1.2 Sun Apr 26 12:13:10 2020 +++ src/tests/lib/libi386/t_user_ldt.c Sat May 9 09:08:41 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_user_ldt.c,v 1.2 2020/04/26 12:13:10 maxv Exp $ */ +/* $NetBSD: t_user_ldt.c,v 1.3 2020/05/09 09:08:41 maxv Exp $ */ /* * Copyright (c) 2020 The NetBSD Foundation, Inc. @@ -58,7 +58,7 @@ user_ldt_detect(void) int ret; ret = i386_get_ldt(0, , 1); - user_ldt_supported = (ret != -1) || (errno != ENOTSUP); + user_ldt_supported = (ret != -1) || (errno != ENOSYS); } static void
CVS commit: src/tests/lib/libi386
Module Name:src Committed By: maxv Date: Sun Apr 26 12:13:10 UTC 2020 Modified Files: src/tests/lib/libi386: t_user_ldt.c Log Message: Add a test on the maximum number of slots. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libi386/t_user_ldt.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/lib/libi386/t_user_ldt.c diff -u src/tests/lib/libi386/t_user_ldt.c:1.1 src/tests/lib/libi386/t_user_ldt.c:1.2 --- src/tests/lib/libi386/t_user_ldt.c:1.1 Sun Apr 19 13:22:58 2020 +++ src/tests/lib/libi386/t_user_ldt.c Sun Apr 26 12:13:10 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_user_ldt.c,v 1.1 2020/04/19 13:22:58 maxv Exp $ */ +/* $NetBSD: t_user_ldt.c,v 1.2 2020/04/26 12:13:10 maxv Exp $ */ /* * Copyright (c) 2020 The NetBSD Foundation, Inc. @@ -42,6 +42,10 @@ #include #include +#define _LOCORE /* XXX a bit of a hack, but whatever */ +#include +#undef _LOCORE + #include static uint8_t *ldt_base; @@ -166,6 +170,13 @@ ATF_TC_BODY(filter_ops, tc) ATF_REQUIRE_EQ(i386_set_ldt(256, , 1), -1); ATF_REQUIRE_EQ(errno, EACCES); } + + /* Check the slot limit. */ + build_desc(, ldt_base, PAGE_SIZE, SDT_MEMRW, SEL_UPL, 1, 0); + ATF_REQUIRE_EQ(i386_set_ldt(MAX_USERLDT_SLOTS-1, , 1), + MAX_USERLDT_SLOTS-1); + ATF_REQUIRE_EQ(i386_set_ldt(MAX_USERLDT_SLOTS, , 1), -1); + ATF_REQUIRE_EQ(errno, EINVAL); } /* -- */
CVS commit: src/tests/lib/libi386
Module Name:src Committed By: joerg Date: Mon Apr 20 12:08:08 UTC 2020 Modified Files: src/tests/lib/libi386: Makefile Log Message: Provide SHLIBINSTALLDIR explicitly as it defauls to /lib otherwise and makes ld complain about the 64bit libc. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libi386/Makefile Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/lib/libi386/Makefile diff -u src/tests/lib/libi386/Makefile:1.2 src/tests/lib/libi386/Makefile:1.3 --- src/tests/lib/libi386/Makefile:1.2 Sun Apr 19 18:07:00 2020 +++ src/tests/lib/libi386/Makefile Mon Apr 20 12:08:08 2020 @@ -1,10 +1,11 @@ -# $NetBSD: Makefile,v 1.2 2020/04/19 18:07:00 kre Exp $ +# $NetBSD: Makefile,v 1.3 2020/04/20 12:08:08 joerg Exp $ .include TESTSDIR= ${TESTSBASE}/lib/libi386 .if ${MACHINE} == "amd64" +SHLIBINSTALLDIR= /usr/lib/i386 COPTS+= -m32 LDFLAGS+= -m32 LDADD+= -li386
CVS commit: src/tests/lib/libi386
Module Name:src Committed By: kre Date: Sun Apr 19 18:07:00 UTC 2020 Modified Files: src/tests/lib/libi386: Makefile Log Message: Define TESTSDIR even when not amd64 so the Atffile will be installed in the correct location. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libi386/Makefile Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/lib/libi386/Makefile diff -u src/tests/lib/libi386/Makefile:1.1 src/tests/lib/libi386/Makefile:1.2 --- src/tests/lib/libi386/Makefile:1.1 Sun Apr 19 13:22:58 2020 +++ src/tests/lib/libi386/Makefile Sun Apr 19 18:07:00 2020 @@ -1,9 +1,10 @@ -# $NetBSD: Makefile,v 1.1 2020/04/19 13:22:58 maxv Exp $ +# $NetBSD: Makefile,v 1.2 2020/04/19 18:07:00 kre Exp $ .include -.if ${MACHINE} == "amd64" TESTSDIR= ${TESTSBASE}/lib/libi386 + +.if ${MACHINE} == "amd64" COPTS+= -m32 LDFLAGS+= -m32 LDADD+= -li386