client: don't send uninitialized data in fio_send_file error replies
PATCH v2 1/1 client: don't send uninitialized data in fio_send_file error replies
Various error cases in fio_send_file() might send an uninitialized buffer over the wire. The server should ignore this when errno is set, but it's best practice to not ship heap data over the wire, so fix that by:
- using calloc vs malloc in the initial allocation so that early error paths send initialized data.
- grow the buffer via realloc only after open() succeeds, so that an open() failure doesn't send a grown/uninit buffer back with the error.
--- client.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
client.c +5 -5
@@ -1807,7 +1807,7 @@ static int fio_send_file(struct fio_client *client, struct cmd_sendfile *pdu,int fd; size =sizeof (*rep); - rep =malloc (size); + rep =calloc (1 , size);if (stat ((char *)pdu->path, &sb) <0 ) { fail:
@@ -1817,14 +1817,14 @@ fail:return 1 ; } - size += sb.st_size; - rep =realloc (rep, size); - rep->size =cpu_to_le32 ((uint32_t ) sb.st_size); - fd =open ((char *)pdu->path,O_RDONLY );if (fd ==-1 ) goto fail; + size += sb.st_size; + rep =realloc (rep, size); + rep->size =cpu_to_le32 ((uint32_t ) sb.st_size); + rep->error =read_data (fd, &rep->data, sb.st_size);sendfile_reply (client->fd, rep, size, tag);free (rep);
Signature · 1 line
2.55.0
Jens Axboe
AppliedQuoted 9 lines · Eric Sandeen
Various error cases in
fio_send_file()might send an uninitialized buffer over the wire. The server should ignore this when errno is set, but it's best practice to not ship heap data over the wire, so fix that by:- using calloc vs malloc in the initial allocation so that early error paths send initialized data.
[...]
Applied, thanks!
[1/1] client: don't send uninitialized data in fio_send_file error replies
commit: 162e8fb3d059c090caa56255e4a6a92bfa6e47b3
Best regards,
Signature · 1 line
Jens Axboe