From owner-dev-commits-src-main@freebsd.org Thu Jul 15 16:25:50 2021 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 8CC4B64A318; Thu, 15 Jul 2021 16:25:50 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4GQfqy3Dlvz4fxl; Thu, 15 Jul 2021 16:25:50 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 455FF4D38; Thu, 15 Jul 2021 16:25:50 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 16FGPo6f046286; Thu, 15 Jul 2021 16:25:50 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 16FGPoSk046285; Thu, 15 Jul 2021 16:25:50 GMT (envelope-from git) Date: Thu, 15 Jul 2021 16:25:50 GMT Message-Id: <202107151625.16FGPoSk046285@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 0fcafe8516d1 - main - eli: Zero pad bytes that arise when certain auth algorithms are used MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 0fcafe8516d170852aa73f029a6a28bed1e29292 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Jul 2021 16:25:50 -0000 The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=0fcafe8516d170852aa73f029a6a28bed1e29292 commit 0fcafe8516d170852aa73f029a6a28bed1e29292 Author: Mark Johnston AuthorDate: 2021-07-15 16:23:04 +0000 Commit: Mark Johnston CommitDate: 2021-07-15 16:23:04 +0000 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 MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D31170 --- sys/geom/eli/g_eli_integrity.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sys/geom/eli/g_eli_integrity.c b/sys/geom/eli/g_eli_integrity.c index e79ec136aa2e..e97924b8df08 100644 --- a/sys/geom/eli/g_eli_integrity.c +++ b/sys/geom/eli/g_eli_integrity.c @@ -515,6 +515,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) {