Skip to content

Commit 1329651

Browse files
philmdmdroth
authored andcommitted
qga: Restrict guest-file-read count to 48 MB to avoid crashes
On [*] Daniel Berrangé commented: The QEMU guest agent protocol is not sensible way to access huge files inside the guest. It requires the inefficient process of reading the entire data into memory than duplicating it again in base64 format, and then copying it again in the JSON serializer / monitor code. For arbitrary general purpose file access, especially for large files, use a real file transfer program or use a network block device, not the QEMU guest agent. To avoid bug reports as BZ#1594054 (CVE-2018-12617), follow his suggestion to put a low, hard limit on "count" in the guest agent QAPI schema, and don't allow count to be larger than 48 MB. [*] https://www.mail-archive.com/[email protected]/msg693176.html Fixes: CVE-2018-12617 Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=1594054 Reported-by: Fakhri Zulkifli <[email protected]> Suggested-by: Daniel P. Berrangé <[email protected]> Signed-off-by: Philippe Mathieu-Daudé <[email protected]> Reviewed-by: Daniel P. Berrangé <[email protected]> *update schema documentation to indicate 48MB limit instead of 10MB Signed-off-by: Michael Roth <[email protected]>
1 parent ead83a1 commit 1329651

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

qga/commands.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212

1313
#include "qemu/osdep.h"
14+
#include "qemu/units.h"
1415
#include "guest-agent-core.h"
1516
#include "qga-qapi-commands.h"
1617
#include "qapi/error.h"
@@ -24,6 +25,12 @@
2425
#define GUEST_EXEC_MAX_OUTPUT (16*1024*1024)
2526
/* Allocation and I/O buffer for reading guest-exec out_data/err_data - 4KB */
2627
#define GUEST_EXEC_IO_SIZE (4*1024)
28+
/*
29+
* Maximum file size to read - 48MB
30+
*
31+
* (48MB + Base64 3:4 overhead = JSON parser 64 MB limit)
32+
*/
33+
#define GUEST_FILE_READ_COUNT_MAX (48 * MiB)
2734

2835
/* Note: in some situations, like with the fsfreeze, logging may be
2936
* temporarilly disabled. if it is necessary that a command be able
@@ -560,7 +567,7 @@ GuestFileRead *qmp_guest_file_read(int64_t handle, bool has_count,
560567
}
561568
if (!has_count) {
562569
count = QGA_READ_COUNT_DEFAULT;
563-
} else if (count < 0 || count >= UINT32_MAX) {
570+
} else if (count < 0 || count > GUEST_FILE_READ_COUNT_MAX) {
564571
error_setg(errp, "value '%" PRId64 "' is invalid for argument count",
565572
count);
566573
return NULL;

qga/qapi-schema.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,13 @@
266266
##
267267
# @guest-file-read:
268268
#
269-
# Read from an open file in the guest. Data will be base64-encoded
269+
# Read from an open file in the guest. Data will be base64-encoded.
270+
# As this command is just for limited, ad-hoc debugging, such as log
271+
# file access, the number of bytes to read is limited to 48 MB.
270272
#
271273
# @handle: filehandle returned by guest-file-open
272274
#
273-
# @count: maximum number of bytes to read (default is 4KB)
275+
# @count: maximum number of bytes to read (default is 4KB, maximum is 48MB)
274276
#
275277
# Returns: @GuestFileRead on success.
276278
#

0 commit comments

Comments
 (0)