OSDN Git Service

virtio_console: validate max_nr_ports before trying to use it
authorJason Wang <jasowang@redhat.com>
Tue, 19 Oct 2021 07:01:44 +0000 (15:01 +0800)
committerMichael S. Tsirkin <mst@redhat.com>
Mon, 1 Nov 2021 09:26:48 +0000 (05:26 -0400)
commit28962ec595d701ec9d39369f9774895dfa408273
treef3f44b8e7d47cf40053f364f417859c5eb8c1213
parent63b4ffa4fad0b14e9ebfedd7f7bb709b1c92472f
virtio_console: validate max_nr_ports before trying to use it

We calculate nr_ports based on the max_nr_ports:

nr_queues = use_multiport(portdev) ? (nr_ports + 1) * 2 : 2;

If the device advertises a large max_nr_ports, we will end up with a
integer overflow. Fixing this by validating the max_nr_ports and fail
the probe for invalid max_nr_ports in this case.

Cc: Amit Shah <amit@kernel.org>
Signed-off-by: Jason Wang <jasowang@redhat.com>
Link: https://lore.kernel.org/r/20211019070152.8236-3-jasowang@redhat.com
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
drivers/char/virtio_console.c