vfio/pci: Fix integer overflows, bitmask check
authorVlad Tsyrklevich <vlad@tsyrklevich.net>
Wed, 12 Oct 2016 16:51:24 +0000 (18:51 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 20 Jun 2017 12:04:13 +0000 (14:04 +0200)
commit37ccd2be0e783b1fb8860ccd8b168109c22655c6
tree0b71d6c5834896459f3784eaeebe1e3450db2aa1
parentf466ca6552401524c229af56d1d120a96fa9184a
vfio/pci: Fix integer overflows, bitmask check

commit 05692d7005a364add85c6e25a6c4447ce08f913a upstream.

The VFIO_DEVICE_SET_IRQS ioctl did not sufficiently sanitize
user-supplied integers, potentially allowing memory corruption. This
patch adds appropriate integer overflow checks, checks the range bounds
for VFIO_IRQ_SET_DATA_NONE, and also verifies that only single element
in the VFIO_IRQ_SET_DATA_TYPE_MASK bitmask is set.
VFIO_IRQ_SET_ACTION_TYPE_MASK is already correctly checked later in
vfio_pci_set_irqs_ioctl().

Furthermore, a kzalloc is changed to a kcalloc because the use of a
kzalloc with an integer multiplication allowed an integer overflow
condition to be reached without this patch. kcalloc checks for overflow
and should prevent a similar occurrence.

Signed-off-by: Vlad Tsyrklevich <vlad@tsyrklevich.net>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Willy Tarreau <w@1wt.eu>
drivers/vfio/pci/vfio_pci.c
drivers/vfio/pci/vfio_pci_intrs.c