Skip to content

Commit

Permalink
hw/xen: fix off-by-one in xen_evtchn_set_gsi()
Browse files Browse the repository at this point in the history
Coverity points out (CID 1508128) a bounds checking error. We need to check
for gsi >= IOAPIC_NUM_PINS, not just greater-than.

Also fix up an assert() that has the same problem, that Coverity didn't see.

Fixes: 4f81baa ("hw/xen: Support GSI mapping to PIRQ")
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-Id: <20230801175747.145906-2-dwmw2@infradead.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
(cherry picked from commit cf885b1)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
  • Loading branch information
dwmw2 authored and Michael Tokarev committed Aug 3, 2023
1 parent 6efd355 commit 49476e7
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions hw/i386/kvm/xen_evtchn.c
Original file line number Diff line number Diff line change
Expand Up @@ -1587,7 +1587,7 @@ static int allocate_pirq(XenEvtchnState *s, int type, int gsi)
found:
pirq_inuse_word(s, pirq) |= pirq_inuse_bit(pirq);
if (gsi >= 0) {
assert(gsi <= IOAPIC_NUM_PINS);
assert(gsi < IOAPIC_NUM_PINS);
s->gsi_pirq[gsi] = pirq;
}
s->pirq[pirq].gsi = gsi;
Expand All @@ -1601,7 +1601,7 @@ bool xen_evtchn_set_gsi(int gsi, int level)

assert(qemu_mutex_iothread_locked());

if (!s || gsi < 0 || gsi > IOAPIC_NUM_PINS) {
if (!s || gsi < 0 || gsi >= IOAPIC_NUM_PINS) {
return false;
}

Expand Down

0 comments on commit 49476e7

Please sign in to comment.