1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-29 12:03:03 +00:00

geom: don't write stack garbage in disk labels

Most consumers of g_metadata_store were passing in partially unallocated
memory, resulting in stack garbage being written to disk labels. Fix them by
zeroing the memory first.

gvirstor repeated the same mistake, but in the kernel.

Also, glabel's label contained a fixed-size string that wasn't
initialized to zero.

PR:		222077
Reported by:	Maxim Khitrov <max@mxcrypt.com>
Reviewed by:	cem
MFC after:	3 weeks
X-MFC-With:	323314
X-MFC-With:	323338
Differential Revision:	https://reviews.freebsd.org/D14164
This commit is contained in:
Alan Somers 2018-02-04 14:49:55 +00:00
parent aa3c83c3c6
commit f5b4099e6b
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=328849
10 changed files with 17 additions and 0 deletions

View File

@ -137,6 +137,7 @@ cache_label(struct gctl_req *req)
int error, nargs;
intmax_t val;
bzero(sector, sizeof(sector));
nargs = gctl_get_int(req, "nargs");
if (nargs != 2) {
gctl_error(req, "Invalid number of arguments.");

View File

@ -119,6 +119,7 @@ concat_label(struct gctl_req *req)
const char *name;
int error, i, hardcode, nargs;
bzero(sector, sizeof(sector));
nargs = gctl_get_int(req, "nargs");
if (nargs < 2) {
gctl_error(req, "Too few arguments.");

View File

@ -144,6 +144,7 @@ journal_label(struct gctl_req *req)
intmax_t jsize, msize, ssize;
int error, force, i, nargs, checksum, hardcode;
bzero(sector, sizeof(sector));
nargs = gctl_get_int(req, "nargs");
str = NULL; /* gcc */

View File

@ -125,6 +125,7 @@ label_label(struct gctl_req *req)
u_char sector[512];
int error, nargs;
bzero(sector, sizeof(sector));
nargs = gctl_get_int(req, "nargs");
if (nargs != 2) {
gctl_error(req, "Invalid number of arguments.");
@ -145,6 +146,7 @@ label_label(struct gctl_req *req)
strlcpy(md.md_magic, G_LABEL_MAGIC, sizeof(md.md_magic));
md.md_version = G_LABEL_VERSION;
label = gctl_get_ascii(req, "arg0");
bzero(md.md_label, sizeof(md.md_label));
strlcpy(md.md_label, label, sizeof(md.md_label));
md.md_provsize = g_get_mediasize(name);
if (md.md_provsize == 0) {

View File

@ -188,6 +188,7 @@ mirror_label(struct gctl_req *req)
intmax_t val;
int error, i, nargs, bal, hardcode;
bzero(sector, sizeof(sector));
nargs = gctl_get_int(req, "nargs");
if (nargs < 2) {
gctl_error(req, "Too few arguments.");

View File

@ -151,6 +151,7 @@ raid3_label(struct gctl_req *req)
int hardcode, round_robin, verify;
int error, i, nargs;
bzero(sector, sizeof(sector));
nargs = gctl_get_int(req, "nargs");
if (nargs < 4) {
gctl_error(req, "Too few arguments.");

View File

@ -112,6 +112,7 @@ shsec_label(struct gctl_req *req)
const char *name;
int error, i, nargs, hardcode;
bzero(sector, sizeof(sector));
nargs = gctl_get_int(req, "nargs");
if (nargs <= 2) {
gctl_error(req, "Too few arguments.");

View File

@ -130,6 +130,7 @@ stripe_label(struct gctl_req *req)
const char *name;
int error, i, nargs, hardcode;
bzero(sector, sizeof(sector));
nargs = gctl_get_int(req, "nargs");
if (nargs < 3) {
gctl_error(req, "Too few arguments.");

View File

@ -273,6 +273,13 @@ g_metadata_read(const char *name, unsigned char *md, size_t size,
return (error);
}
/*
* Actually write the GEOM label to the provider
*
* @param name GEOM provider's name (ie "ada0")
* @param md Pointer to the label data to write
* @param size Size of the data pointed to by md
*/
int
g_metadata_store(const char *name, const unsigned char *md, size_t size)
{

View File

@ -1042,6 +1042,7 @@ write_metadata(struct g_consumer *cp, struct g_virstor_metadata *md)
pp = cp->provider;
buf = malloc(pp->sectorsize, M_GVIRSTOR, M_WAITOK);
bzero(buf, pp->sectorsize);
virstor_metadata_encode(md, buf);
g_topology_unlock();
error = g_write_data(cp, pp->mediasize - pp->sectorsize, buf,