From 5140c627386e49111aee94762e74525c9ae2d7db Mon Sep 17 00:00:00 2001 From: Hans-Joerg Hoexer Date: Fri, 13 Jun 2008 18:27:00 +0000 Subject: When assembling an already initialized crytpo softraid, correctly copy in mask key from userland. Thus, modify sr_crypto_get_kdf() do correclty handle copying kdf hint and/or mask key. While there, remove superflous sr_read_meta(). ok marco djm --- sys/dev/softraid.c | 10 ++++++---- sys/dev/softraid_crypto.c | 27 ++++++++++++++++----------- 2 files changed, 22 insertions(+), 15 deletions(-) (limited to 'sys/dev') diff --git a/sys/dev/softraid.c b/sys/dev/softraid.c index 7f035669c1b..4e7117b4b29 100644 --- a/sys/dev/softraid.c +++ b/sys/dev/softraid.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softraid.c,v 1.112 2008/06/12 23:29:27 hshoexer Exp $ */ +/* $OpenBSD: softraid.c,v 1.113 2008/06/13 18:26:59 hshoexer Exp $ */ /* * Copyright (c) 2007 Marco Peereboom * Copyright (c) 2008 Chris Kuethe @@ -884,9 +884,6 @@ sr_ioctl_createraid(struct sr_softc *sc, struct bioc_createraid *bc, int user) if (bc->bc_opaque == NULL) goto unwind; - if (sr_read_meta(sd) == 0) - goto unwind; - if (sizeof(sd->mds.mdd_crypto.scr_meta.scm_kdfhint) < bc->bc_opaque_size) goto unwind; @@ -899,6 +896,11 @@ sr_ioctl_createraid(struct sr_softc *sc, struct bioc_createraid *bc, int user) rv = 0; goto unwind; } + /* get kdf with maskkey from userland */ + if (bc->bc_opaque_flags & BIOC_SOIN) { + if (sr_crypto_get_kdf(bc, sd)) + goto unwind; + } #endif /* CRYPTO */ DNPRINTF(SR_D_META, "%s: disk assembled from metadata\n", DEVNAME(sc)); diff --git a/sys/dev/softraid_crypto.c b/sys/dev/softraid_crypto.c index 70170622f0f..239cdeb9f38 100644 --- a/sys/dev/softraid_crypto.c +++ b/sys/dev/softraid_crypto.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softraid_crypto.c,v 1.21 2008/06/12 18:23:29 hshoexer Exp $ */ +/* $OpenBSD: softraid_crypto.c,v 1.22 2008/06/13 18:26:59 hshoexer Exp $ */ /* * Copyright (c) 2007 Marco Peereboom * Copyright (c) 2008 Hans-Joerg Hoexer @@ -181,20 +181,25 @@ sr_crypto_get_kdf(struct bioc_createraid *bc, struct sr_discipline *sd) if (kdfinfo->len != bc->bc_opaque_size) goto out; - if (!(kdfinfo->flags & SR_CRYPTOKDF_KEY) || - !(kdfinfo->flags & SR_CRYPTOKDF_HINT)) - goto out; /* copy KDF hint to disk meta data */ - if (sizeof(sd->mds.mdd_crypto.scr_meta.scm_kdfhint) < - kdfinfo->kdfhint.len) - goto out; - bcopy(&kdfinfo->kdfhint, sd->mds.mdd_crypto.scr_meta.scm_kdfhint, - kdfinfo->kdfhint.len); + if (kdfinfo->flags & SR_CRYPTOKDF_HINT) { + if (sizeof(sd->mds.mdd_crypto.scr_meta.scm_kdfhint) < + kdfinfo->kdfhint.len) + goto out; + bcopy(&kdfinfo->kdfhint, + sd->mds.mdd_crypto.scr_meta.scm_kdfhint, + kdfinfo->kdfhint.len); + } /* copy mask key to run-time meta data */ - bcopy(&kdfinfo->maskkey, sd->mds.mdd_crypto.scr_maskkey, - sizeof(kdfinfo->maskkey)); + if ((kdfinfo->flags & SR_CRYPTOKDF_KEY)) { + if (sizeof(sd->mds.mdd_crypto.scr_maskkey) < + sizeof(kdfinfo->maskkey)) + goto out; + bcopy(&kdfinfo->maskkey, sd->mds.mdd_crypto.scr_maskkey, + sizeof(kdfinfo->maskkey)); + } rv = 0; out: -- cgit v1.2.3