From be1d11762b39e70c5ea18282f8d1cb2dff9f71fa Mon Sep 17 00:00:00 2001 From: John Snow Date: Tue, 5 Aug 2014 00:23:21 -0500 Subject: [CHANGE 30/31] virtio-rng: Add human-readable error message for negative max-bytes parameter To: rhvirt-patches@redhat.com, jen@redhat.com RH-Author: John Snow Message-id: <1407198202-3989-2-git-send-email-jsnow@redhat.com> Patchwork-id: 60433 O-Subject: [RHEL6.6 qemu-kvm PATCH v2 1/2] virtio-rng: Add human-readable error message for negative max-bytes parameter Bugzilla: 1119207 RH-Acked-by: Markus Armbruster RH-Acked-by: Amit Shah RH-Acked-by: Amos Kong If a negative integer is used for the max_bytes parameter, QEMU currently calls abort() and leaves behind a core dump. This patch replaces the abort with a simple error message to make the reason for the termination clearer. This also ensures device-hotplug with invalid input doesn't cause qemu to quit. There is an underlying insufficiency in the parameter parsing code of QEMU that renders it unable to reject negative values for unsigned properties, thus the error message "a non-negative integer below 2^63" is the most user-friendly and correct message we can give until the underlying insufficiency is corrected. Signed-off-by: John Snow Reviewed-by: Markus Armbruster Signed-off-by: Amit Shah (cherry picked from commit 713e8a102222b6b8ca65050d13b287f5705831b0) Signed-off-by: John Snow Signed-off-by: jen Conflicts: hw/virtio/virtio-rng.c Signed-off-by: John Snow --- hw/virtio-rng.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) Signed-off-by: jen --- hw/virtio-rng.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/hw/virtio-rng.c b/hw/virtio-rng.c index afa8430..356e3d4 100644 --- a/hw/virtio-rng.c +++ b/hw/virtio-rng.c @@ -192,7 +192,13 @@ VirtIODevice *virtio_rng_init(DeviceState *dev, VirtIORNGConf *conf) vrng->quota_remaining = vrng->conf->max_bytes; - g_assert_cmpint(vrng->conf->max_bytes, <=, INT64_MAX); + /* Workaround: Property parsing does not enforce unsigned integers, + * So this is a hack to reject such numbers. */ + if (vrng->conf->max_bytes > INT64_MAX) { + qerror_report(QERR_INVALID_PARAMETER_VALUE, "max-bytes", + "a non-negative integer below 2^63"); + return NULL; + } vrng->rate_limit_timer = qemu_new_timer(vm_clock, check_rate_limit, vrng); -- 1.9.3