]> www.infradead.org Git - users/dwmw2/qemu.git/commitdiff
vhost-backend: avoid overflow on memslots_limit
authorRoman Kagan <rvkagan@yandex-team.ru>
Thu, 11 Nov 2021 15:33:49 +0000 (18:33 +0300)
committerMichael S. Tsirkin <mst@redhat.com>
Fri, 7 Jan 2022 10:19:55 +0000 (05:19 -0500)
Fix the (hypothetical) potential problem when the value parsed out of
the vhost module parameter in sysfs overflows the return value from
vhost_kernel_memslots_limit.

Signed-off-by: Roman Kagan <rvkagan@yandex-team.ru>
Message-Id: <20211111153354.18807-6-rvkagan@yandex-team.ru>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
hw/virtio/vhost-backend.c

index b65f8f7e97bfc3e78128115b01836a1620342fa3..44f7dbb2436d266b9a8df6d6fb16cf286be93b1c 100644 (file)
@@ -58,7 +58,7 @@ static int vhost_kernel_memslots_limit(struct vhost_dev *dev)
     if (g_file_get_contents("/sys/module/vhost/parameters/max_mem_regions",
                             &s, NULL, NULL)) {
         uint64_t val = g_ascii_strtoull(s, NULL, 10);
-        if (!((val == G_MAXUINT64 || !val) && errno)) {
+        if (val < INT_MAX && val > 0) {
             g_free(s);
             return val;
         }