From owner-dev-commits-src-main@freebsd.org Tue Jul 13 22:17:23 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 8E7BB6663B4; Tue, 13 Jul 2021 22:17:23 +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 4GPZkW2x0tz3sD0; Tue, 13 Jul 2021 22:17:23 +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 44B7E24B8; Tue, 13 Jul 2021 22:17:23 +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 16DMHNrZ060779; Tue, 13 Jul 2021 22:17:23 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 16DMHNAH060778; Tue, 13 Jul 2021 22:17:23 GMT (envelope-from git) Date: Tue, 13 Jul 2021 22:17:23 GMT Message-Id: <202107132217.16DMHNAH060778@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: 0f09ab89cc44 - main - gconcat: Zero the metadata block before writing 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: 0f09ab89cc444e468837c23cd9855689114769d4 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: Tue, 13 Jul 2021 22:17:23 -0000 The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=0f09ab89cc444e468837c23cd9855689114769d4 commit 0f09ab89cc444e468837c23cd9855689114769d4 Author: Mark Johnston AuthorDate: 2021-07-13 21:45:59 +0000 Commit: Mark Johnston CommitDate: 2021-07-13 21:45:59 +0000 gconcat: Zero the metadata block before writing Ensure that string buffers and pad bytes are zero-filled before writing gconcat metadata. Also make sure to zero the full block buffer before encoding the metadata and writing. Fix some style bugs in g_concat_write_metadata() while here. Reported by: KMSAN MFC after: 2 weeks Sponsored by: The FreeBSD Foundation --- sys/geom/concat/g_concat.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/sys/geom/concat/g_concat.c b/sys/geom/concat/g_concat.c index 1bfca1585423..c4a5e0476edf 100644 --- a/sys/geom/concat/g_concat.c +++ b/sys/geom/concat/g_concat.c @@ -865,6 +865,7 @@ g_concat_ctl_create(struct gctl_req *req, struct g_class *mp) return; } + bzero(&md, sizeof(md)); strlcpy(md.md_magic, G_CONCAT_MAGIC, sizeof(md.md_magic)); md.md_version = G_CONCAT_VERSION; name = gctl_get_asciiparam(req, "arg0"); @@ -876,7 +877,6 @@ g_concat_ctl_create(struct gctl_req *req, struct g_class *mp) md.md_id = arc4random(); md.md_no = 0; md.md_all = *nargs - 1; - bzero(md.md_provider, sizeof(md.md_provider)); /* This field is not important here. */ md.md_provsize = 0; @@ -1017,6 +1017,7 @@ g_concat_write_metadata(struct gctl_req *req, struct g_concat_softc *sc) u_char *sector; int error; + bzero(&md, sizeof(md)); strlcpy(md.md_magic, G_CONCAT_MAGIC, sizeof(md.md_magic)); md.md_version = G_CONCAT_VERSION; strlcpy(md.md_name, sc->sc_name, sizeof(md.md_name)); @@ -1026,25 +1027,24 @@ g_concat_write_metadata(struct gctl_req *req, struct g_concat_softc *sc) pp = disk->d_consumer->provider; md.md_no = no; - bzero(md.md_provider, sizeof(md.md_provider)); - if (disk->d_hardcoded) { - strlcpy(md.md_provider, pp->name, sizeof(md.md_provider)); - } + if (disk->d_hardcoded) + strlcpy(md.md_provider, pp->name, + sizeof(md.md_provider)); md.md_provsize = disk->d_consumer->provider->mediasize; - sector = g_malloc(pp->sectorsize, M_WAITOK); - + sector = g_malloc(pp->sectorsize, M_WAITOK | M_ZERO); concat_metadata_encode(&md, sector); error = g_access(disk->d_consumer, 0, 1, 0); if (error == 0) { - error = g_write_data(disk->d_consumer, pp->mediasize - pp->sectorsize, - sector, pp->sectorsize); + error = g_write_data(disk->d_consumer, + pp->mediasize - pp->sectorsize, sector, + pp->sectorsize); (void)g_access(disk->d_consumer, 0, -1, 0); } g_free(sector); - if (error != 0) { - gctl_error(req, "Cannot store metadata on %s: %d", pp->name, error); - } + if (error != 0) + gctl_error(req, "Cannot store metadata on %s: %d", + pp->name, error); no++; }