git: 0f09ab89cc44 - main - gconcat: Zero the metadata block before writing
Mark Johnston
markj at FreeBSD.org
Tue Jul 13 22:17:23 UTC 2021
The branch main has been updated by markj:
URL: https://cgit.FreeBSD.org/src/commit/?id=0f09ab89cc444e468837c23cd9855689114769d4
commit 0f09ab89cc444e468837c23cd9855689114769d4
Author: Mark Johnston <markj at FreeBSD.org>
AuthorDate: 2021-07-13 21:45:59 +0000
Commit: Mark Johnston <markj at FreeBSD.org>
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++;
}
More information about the dev-commits-src-all
mailing list