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.
This commit is contained in:
parent
c18a0f90f4
commit
c2cf8ad6d4
|
@ -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 @@ configure(int argc, char **argv, struct params *inparams, int flags)
|
|||
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 @@ verify_mbr(int fd)
|
|||
|
||||
memcpy(&mbr, buf, sizeof(mbr));
|
||||
if (le16toh(mbr.mbr_magic) != MBR_MAGIC)
|
||||
return -1;
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -916,7 +918,7 @@ verify_gpt(int fd)
|
|||
return -1;
|
||||
}
|
||||
|
||||
ret = -1;
|
||||
ret = 1;
|
||||
for (blksize=DEV_BSIZE;
|
||||
(off = blksize * GPT_HDR_BLKNO) <= SCANSIZE - sizeof(hdr);
|
||||
blksize <<= 1) {
|
||||
|
|
|
@ -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 @@ unaligned_write_cleanup()
|
|||
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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue