Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src PR bin/53999 from rudolf (eq.cz)



details:   https://anonhg.NetBSD.org/src/rev/bc309f1d1b79
branches:  trunk
changeset: 840559:bc309f1d1b79
user:      kre <kre%NetBSD.org@localhost>
date:      Wed Apr 10 06:09:39 2019 +0000

description:
PR bin/53999 from rudolf (eq.cz)

Fix cgdconfig to report verification failures with gpt and mbr
verification methods (and not treat them as silent hard errors).
This also causes the cgd to be unconfigured when one of those
verification methods fails.

Add ATF tests to check that bad verification is reported, and
does not leave the cgd configured.

Patches from the PR applied.

diffstat:

 sbin/cgdconfig/cgdconfig.c |  12 +++++++-----
 tests/dev/cgd/t_cgd.sh     |  45 ++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 51 insertions(+), 6 deletions(-)

diffs (111 lines):

diff -r 5847779ff313 -r bc309f1d1b79 sbin/cgdconfig/cgdconfig.c
--- a/sbin/cgdconfig/cgdconfig.c        Wed Apr 10 04:37:00 2019 +0000
+++ b/sbin/cgdconfig/cgdconfig.c        Wed Apr 10 06:09:39 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cgdconfig.c,v 1.48 2018/05/09 19:38:46 alnsn Exp $ */
+/* $NetBSD: cgdconfig.c,v 1.49 2019/04/10 06:09:39 kre Exp $ */
 
 /*-
  * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
 #ifndef lint
 __COPYRIGHT("@(#) Copyright (c) 2002, 2003\
  The NetBSD Foundation, Inc.  All rights reserved.");
-__RCSID("$NetBSD: cgdconfig.c,v 1.48 2018/05/09 19:38:46 alnsn Exp $");
+__RCSID("$NetBSD: cgdconfig.c,v 1.49 2019/04/10 06:09:39 kre Exp $");
 #endif
 
 #include <err.h>
@@ -625,8 +625,10 @@
                        goto bail_err;
 
                ret = verify(p, fd);
-               if (ret == -1)
+               if (ret == -1) {
+                       (void)unconfigure_fd(fd);
                        goto bail_err;
+               }
                if (!ret)
                        break;
 
@@ -830,7 +832,7 @@
 
        memcpy(&mbr, buf, sizeof(mbr));
        if (le16toh(mbr.mbr_magic) != MBR_MAGIC)
-               return -1;
+               return 1;
 
        return 0;
 }
@@ -916,7 +918,7 @@
                return -1;
        }
 
-       ret = -1;
+       ret = 1;
        for (blksize=DEV_BSIZE;
              (off = blksize * GPT_HDR_BLKNO) <= SCANSIZE - sizeof(hdr);
              blksize <<= 1) {
diff -r 5847779ff313 -r bc309f1d1b79 tests/dev/cgd/t_cgd.sh
--- a/tests/dev/cgd/t_cgd.sh    Wed Apr 10 04:37:00 2019 +0000
+++ b/tests/dev/cgd/t_cgd.sh    Wed Apr 10 06:09:39 2019 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: t_cgd.sh,v 1.11 2013/02/19 21:08:24 joerg Exp $
+#      $NetBSD: t_cgd.sh,v 1.12 2019/04/10 06:09:39 kre Exp $
 #
 # Copyright (c) 2010 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -150,10 +150,53 @@
        env RUMP_SERVER=unix://csock rump.halt || true
 }
 
+vmeth_failure_body()
+{
+
+       local vmeth="$1"
+       local d=$(atf_get_srcdir)
+
+       atf_check -s exit:0 \
+           ${cgdserver} -d key=/dev/dk,hostpath=dk.img,size=1m unix://csock
+       export RUMP_SERVER=unix://csock
+       atf_check -s not-exit:0 -e ignore -x "echo 12345 | \
+           rump.cgdconfig -V "${vmeth}" -p cgd0 /dev/dk ${d}/paramsfile"
+       atf_check -s exit:0 -o not-match:"(^| )cgd0( |$)" rump.sysctl -n hw.disknames
+}
+
+test_case_vmeth_failure()
+{
+
+       local vmeth="${1}"
+       local name="vmeth_failure_${vmeth}"
+
+       atf_test_case "${name}" cleanup
+       eval "${name}_head() { \
+               atf_set "descr" "Tests verification method \"${vmeth}\" failure" ; \
+               atf_set "require.progs" "rump_server" ; \
+       }"
+       eval "${name}_body() { \
+               vmeth_failure_body "${vmeth}" ; \
+       }"
+       eval "${name}_cleanup() { \
+               rump.cgdconfig -u cgd0 2>/dev/null ; \
+               env RUMP_SERVER=unix://csock rump.halt || true ; \
+       }"
+}
+
+test_case_vmeth_failure disklabel
+test_case_vmeth_failure ffs
+test_case_vmeth_failure gpt
+test_case_vmeth_failure mbr
+
 atf_init_test_cases()
 {
 
        atf_add_test_case basic
        atf_add_test_case wrongpass
        atf_add_test_case unaligned_write
+       atf_add_test_case vmeth_failure_disklabel
+       atf_add_test_case vmeth_failure_ffs
+       atf_add_test_case vmeth_failure_gpt
+       atf_add_test_case vmeth_failure_mbr
 }



Home | Main Index | Thread Index | Old Index