Skip to content

Commit 990a9d4

Browse files
Dan Carpenterdavem330
authored andcommitted
net/ncsi: prevent a couple array underflows
We recently refactored this code and introduced a static checker warning. Smatch complains that if cmd->index is zero then we would underflow the arrays. That's obviously true. The question is whether we prevent cmd->index from being zero at a different level. I've looked at the code and I don't immediately see a check for that. Fixes: 062b3e1 ("net/ncsi: Refactor MAC, VLAN filters") Signed-off-by: Dan Carpenter <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent be7f3e5 commit 990a9d4

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

net/ncsi/ncsi-rsp.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ static int ncsi_rsp_handler_svf(struct ncsi_request *nr)
347347

348348
cmd = (struct ncsi_cmd_svf_pkt *)skb_network_header(nr->cmd);
349349
ncf = &nc->vlan_filter;
350-
if (cmd->index > ncf->n_vids)
350+
if (cmd->index == 0 || cmd->index > ncf->n_vids)
351351
return -ERANGE;
352352

353353
/* Add or remove the VLAN filter. Remember HW indexes from 1 */
@@ -445,7 +445,8 @@ static int ncsi_rsp_handler_sma(struct ncsi_request *nr)
445445
ncf = &nc->mac_filter;
446446
bitmap = &ncf->bitmap;
447447

448-
if (cmd->index > ncf->n_uc + ncf->n_mc + ncf->n_mixed)
448+
if (cmd->index == 0 ||
449+
cmd->index > ncf->n_uc + ncf->n_mc + ncf->n_mixed)
449450
return -ERANGE;
450451

451452
index = (cmd->index - 1) * ETH_ALEN;

0 commit comments

Comments
 (0)