I found this bug while reviewing a proposed ALL_MCAST fallback patch
for bnxt_multi_set(), which we ended up not using. bnxt_copy_maddr()
is the if_foreach_llmaddr() callback that copies a port's multicast
MAC addresses into the list that the driver hands to the firmware. It
currently only skips the copy when cnt == BNXT_MAX_MC_ADDRS, but it
returns 1 for each address, so cnt keeps counting and from the 18th
address on it writes past the end of the list buffer. Those extra
entries are never used: the firmware only reads as many entries as the
driver says are valid, at most 16, and with more than 16 addresses the
driver switches to all-multicast anyway.
As far as I can tell the list buffer is 96 bytes but, on amd64 at
least, it sits alone in a 4 KB allocation because of the page
alignment, so the stray writes land in unused space until the 683rd
address. After that they would overwrite whatever comes next.
This patch changes the check to >=.
Proposed commit message:
bnxt: fix an out-of-bounds write in bnxt_copy_maddr()
bnxt_copy_maddr() copies link-layer multicast addresses into the
BNXT_MAX_MC_ADDRS-entry list given to the firmware, but only skips the
copy when cnt == BNXT_MAX_MC_ADDRS. The callback returns 1 for every
address, so with 18 or more addresses it writes past the end of the
list. bnxt_multi_set() switches to ALL_MCAST when there are more than
BNXT_MAX_MC_ADDRS addresses, so the extra entries are never used, but
on amd64 the list sits at the start of a 4 KB allocation, and with 683
or more addresses the writes go past it.
Skip the copy for every cnt >= BNXT_MAX_MC_ADDRS.
Fixes: dbf9bf044c6e ("Convert to if_foreach_llmaddr() KPI.")
MFC after: 2 weeks
Sponsored by: E-CARD LTD.
Sponsored by: Klara, Inc.