[BUG] RDMA/hw/qib/qib_iba6120: possible buffer underflow in rcvctrl_6120_mod()

From: Tuo Li
Date: Thu Aug 12 2021 - 03:36:02 EST


Hello,

Our static analysis tool reports a possible buffer underflow in qib_iba6120.c in Linux 5.14.0-rc3:

The variable ctxt is checked in:
2110:    if (ctxt < 0)

This indicates that ctxt can be negative.
If so, possible buffer underflows will occur:
2120:    qib_write_kreg_ctxt(dd, kr_rcvhdrtailaddr, ctxt, dd->rcd[ctxt]->rcvhdrqtailaddr_phys);
2122:    qib_write_kreg_ctxt(dd, kr_rcvhdraddr, ctxt, dd->rcd[ctxt]->rcvhdrq_phys);

However, I am not sure whether ctxt < 0 and op & QIB_RCVCTRL_CTXT_ENB can be true at the same time.

Any feedback would be appreciated, thanks!

Reported-by: TOTE Robot <oslab@xxxxxxxxxxxxxxx>

Best wishes,
Tuo Li