aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Johnston <markj@FreeBSD.org>2021-07-15 16:23:04 +0000
committerMark Johnston <markj@FreeBSD.org>2021-07-29 12:12:22 +0000
commit90ffac35b778564d1b4cb8ec7d2ff92ccc8e56dd (patch)
tree63fd69eadfb3103788bebf2a13c174f957c5531c
parent822c62b7db64bd2a2326e460faf68b5442e4c52c (diff)
downloadsrc-90ffac35b778564d1b4cb8ec7d2ff92ccc8e56dd.tar.gz
src-90ffac35b778564d1b4cb8ec7d2ff92ccc8e56dd.zip
eli: Zero pad bytes that arise when certain auth algorithms are used
When authentication is configured, GELI ensures that the amount of data per sector is a multiple of 16 bytes. This is done in eli_metadata_softc(). When the digest size is not a multiple of 16 bytes, this leaves some extra pad bytes at the end of every sector, and they were not being zeroed before being written to disk. In particular, this happens with the HMAC/SHA1, HMAC/RIPEMD160 and HMAC/SHA384 data authentication algorithms. This change ensures that they are zeroed before being written to disk. Reported by: KMSAN Reviewed by: delphij, asomers Sponsored by: The FreeBSD Foundation (cherry picked from commit 0fcafe8516d170852aa73f029a6a28bed1e29292)
-rw-r--r--sys/geom/eli/g_eli_integrity.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/sys/geom/eli/g_eli_integrity.c b/sys/geom/eli/g_eli_integrity.c
index 4cf982e3ddfa..d9ac0a2a3d72 100644
--- a/sys/geom/eli/g_eli_integrity.c
+++ b/sys/geom/eli/g_eli_integrity.c
@@ -510,6 +510,17 @@ g_eli_auth_run(struct g_eli_worker *wr, struct bio *bp)
if (bp->bio_cmd == BIO_WRITE)
memset(data + sc->sc_alen + data_secsize, 0,
encr_secsize - sc->sc_alen - data_secsize);
+ } else if (data_secsize + sc->sc_alen != encr_secsize) {
+ /*
+ * If the HMAC size is not a multiple of 128 bits, the
+ * per-sector data size is rounded down to ensure that
+ * encryption can be performed without requiring any
+ * padding. In this case, each sector contains unused
+ * bytes.
+ */
+ if (bp->bio_cmd == BIO_WRITE)
+ memset(data + sc->sc_alen + data_secsize, 0,
+ encr_secsize - sc->sc_alen - data_secsize);
}
if (bp->bio_cmd == BIO_WRITE) {