dumpon: fix encrypted dumps after commit 372557d8c3

That commit moved key generation into a child process, including
a memory allocation referenced by a structure.  The child wrote
the structure to the parent over a pipe, but did not write the
referenced allocation.  The parent read the structure from the
child and used its pointer, which was bogus in the parent.

In the child, send both chunks of data to the parent.  In the
parent, make a corresponding allocation and read both chunks.

Fixes:		372557d8c3
Reviewed by:	bdrewery, markj
MFC after:	1 week
Sponsored by:	Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D31452
This commit is contained in:
Eric van Gyzen 2021-08-07 03:59:02 -05:00
parent 710c055673
commit 96f9bd4654

View file

@ -332,6 +332,10 @@ genkey(const char *pubkeyfile, struct diocskerneldump_arg *kdap)
bytes = write(filedes[1], kdap, sizeof(*kdap));
if (bytes != sizeof(*kdap))
err(1, "genkey pipe write");
bytes = write(filedes[1], kdap->kda_encryptedkey,
kdap->kda_encryptedkeysize);
if (bytes != kdap->kda_encryptedkeysize)
err(1, "genkey pipe write kda_encryptedkey");
_exit(0);
}
close(filedes[1]);
@ -339,6 +343,16 @@ genkey(const char *pubkeyfile, struct diocskerneldump_arg *kdap)
bytes = read(filedes[0], kdap, sizeof(*kdap));
if (bytes != sizeof(*kdap))
errx(1, "genkey pipe read");
if (kdap->kda_encryptedkeysize > KERNELDUMP_ENCKEY_MAX_SIZE)
errx(1, "Public key has to be at most %db long.",
8 * KERNELDUMP_ENCKEY_MAX_SIZE);
kdap->kda_encryptedkey = calloc(1, kdap->kda_encryptedkeysize);
if (kdap->kda_encryptedkey == NULL)
err(1, "Unable to allocate encrypted key");
bytes = read(filedes[0], kdap->kda_encryptedkey,
kdap->kda_encryptedkeysize);
if (bytes != kdap->kda_encryptedkeysize)
errx(1, "genkey pipe read kda_encryptedkey");
error = waitpid(pid, &status, WEXITED);
if (error == -1)
err(1, "waitpid");