From 9d18043979d7efe9e3e32df9961e8fab12d7253e Mon Sep 17 00:00:00 2001 From: Pawel Jakub Dawidek Date: Fri, 10 Aug 2012 18:43:29 +0000 Subject: [PATCH] Always initialize sc_ekey, because as of r238116 it is always used. If GELI provider was created on FreeBSD HEAD r238116 or later (but before this change), it is using very weak keys and the data is not protected. The bug was introduced on 4th July 2012. One can verify if its provider was created with weak keys by running: # geli dump | grep version If the version is 7 and the system didn't include this fix when provider was initialized, then the data has to be backed up, underlying provider overwritten with random data, system upgraded and provider recreated. Reported by: Fabian Keil Tested by: Fabian Keil Discussed with: so MFC after: 3 days --- sys/geom/eli/g_eli_key_cache.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/sys/geom/eli/g_eli_key_cache.c b/sys/geom/eli/g_eli_key_cache.c index d7158e4ac84..9530495050e 100644 --- a/sys/geom/eli/g_eli_key_cache.c +++ b/sys/geom/eli/g_eli_key_cache.c @@ -193,24 +193,24 @@ g_eli_key_remove(struct g_eli_softc *sc, struct g_eli_key *key) void g_eli_key_init(struct g_eli_softc *sc) { + uint8_t *mkey; mtx_lock(&sc->sc_ekeys_lock); + + mkey = sc->sc_mkey + sizeof(sc->sc_ivkey); + if ((sc->sc_flags & G_ELI_FLAG_AUTH) == 0) + bcopy(mkey, sc->sc_ekey, G_ELI_DATAKEYLEN); + else { + /* + * The encryption key is: ekey = HMAC_SHA512(Data-Key, 0x10) + */ + g_eli_crypto_hmac(mkey, G_ELI_MAXKEYLEN, "\x10", 1, + sc->sc_ekey, 0); + } + if ((sc->sc_flags & G_ELI_FLAG_SINGLE_KEY) != 0) { - uint8_t *mkey; - - mkey = sc->sc_mkey + sizeof(sc->sc_ivkey); - sc->sc_ekeys_total = 1; sc->sc_ekeys_allocated = 0; - if ((sc->sc_flags & G_ELI_FLAG_AUTH) == 0) - bcopy(mkey, sc->sc_ekey, G_ELI_DATAKEYLEN); - else { - /* - * The encryption key is: ekey = HMAC_SHA512(Data-Key, 0x10) - */ - g_eli_crypto_hmac(mkey, G_ELI_MAXKEYLEN, "\x10", 1, - sc->sc_ekey, 0); - } } else { off_t mediasize; size_t blocksize; @@ -241,6 +241,7 @@ g_eli_key_init(struct g_eli_softc *sc) (uintmax_t)sc->sc_ekeys_allocated)); } } + mtx_unlock(&sc->sc_ekeys_lock); }