x86/msi: fix loop termination condition in pci_msi_conf_write_intercept()
authorPaul Durrant <paul.durrant@citrix.com>
Fri, 5 Jul 2019 08:34:32 +0000 (10:34 +0200)
committerJan Beulich <jbeulich@suse.com>
Fri, 5 Jul 2019 08:34:32 +0000 (10:34 +0200)
commit8efcc0d2d3bc3fdc325c0e7c9ec625575e66b805
tree87557b67c08119c3017398de3882502d59d7bb46
parent1cf304fc55d9afa86b700d78423379ae8a39d8b3
x86/msi: fix loop termination condition in pci_msi_conf_write_intercept()

The for loop that deals with MSI masking is coded as follows:

for ( pos = 0; pos < entry->msi.nvec; ++pos, ++entry )

Thus the loop termination condition is dereferencing a struct pointer that
is being incremented by the loop.

A block of MSI entries stores the number of vectors in entry[0].msi.nvec,
with all subsequent entries using a value of 0.  Therefore, for a block of
two or more MSIs will terminate the loop early, as entry[1].msi.nvec is 0.

However, for a single MSI, ++entry moves the pointer out of bounds, and a
bogus read is used for the termination condition.  In the case that the
loop body gets entered, there are subsequent OoB writes which clobber
adjacent memory in the heap.

This patch simply initializes a stack variable to the value of
entry->msi.nvec before starting the loop and then uses that in the
termination condition instead.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
master commit: 56ad626532eb7addeef2bb2f5f67a15756b5cee2
master date: 2019-07-02 12:00:42 +0100
xen/arch/x86/msi.c