Octeontx2-af: Fix negative array index read warning
PATCH 1/1 Octeontx2-af: Fix negative array index read warning
The cgx_get_cgxid function may return a negative value. Using this value directly as an array index triggers Coverity warnings.
Validate the returned value and handle the case gracefully.
--- drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c +2 -0
@@ -3005,6 +3005,8 @@ static int cgx_print_fwdata(struct seq_file *s, int lmac_id)return -EAGAIN ; cgx_id =cgx_get_cgxid (cgxd); +if (cgx_id <0 ) +return -EINVAL ;if (rvu->hw->lmac_per_cgx ==CGX_LMACS_USX ) fwdata = &rvu->fwdata->cgx_fw_data_usx[cgx_id][lmac_id];
Signature · 1 line
2.43.0
Quoted 15 lines · Chandra Mohan Sundar
The
cgx_get_cgxidfunction may return a negative value. Using this value directly as an array index triggers Coverity warnings.Validate the returned value and handle the case gracefully.
Signed-off-by Chandra Mohan Sundar <[email protected]>--- drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c | 2 ++ 1 file changed, 2 insertions(+)drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c +0
-0
drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c static int cgx_print_fwdata(struct seq_file *s, int lmac_id) · line 3012
Quoted 8 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c +2
-0@@ -3005,6 +3005,8 @@ static int cgx_print_fwdata(struct seq_file *s, int lmac_id)return -EAGAIN ; cgx_id =cgx_get_cgxid (cgxd); +if (cgx_id <0 ) +return -EINVAL ;if (rvu->hw->lmac_per_cgx ==CGX_LMACS_USX ) fwdata = &rvu->fwdata->cgx_fw_data_usx[cgx_id][lmac_id];
A couple pieces of feedback for you:
1. Since this is a fixes it needs a Fixes tag and a commit SHA that it is fixing.
2. cgx_get_cgxid is called in 3 places, so your patch would probably need to be expanded to fix all uses?
Overall though, did you somehow trigger this issue?
It seems like all cases where cgx_get_cgxid is used it would be extremely difficult (maybe impossible?) for cgxd to be NULL and for it to return a negative value.
Quoted 3 lines · Joe Damato
A couple pieces of feedback for you:
1. Since this is a fixes it needs a Fixes tag and a commit SHA that it is fixing.
Thank you very much for your feedback.I will add the Fixes tag as suggested.
Quoted 2 lines
2.
cgx_get_cgxidis called in 3 places, so your patch would probably need to be expanded to fix all uses?
Thanks for the suggestion.
I can add a similar check in cgxlmac_to_pf() to check if cgx_id is negative and return an error.
Quoted 5 lines
Overall though, did you somehow trigger this issue?
It seems like all cases where
cgx_get_cgxidis used it would be extremely difficult (maybe impossible?) for cgxd to be NULL and for it to return a negative value.
I could not reproduce a scenario where cgx_get_cgxid returns a negative value. However, this issue was reported by the Black Duck Coverity scan.
The fix was made to cover all possible return paths.
Please advise if you think there’s a better way to address it.
Thanks,
Chandra Mohan Sundar
Quoted 37 lines · Joe Damato
Quoted 15 lines · Chandra Mohan Sundar
The
cgx_get_cgxidfunction may return a negative value. Using this value directly as an array index triggers Coverity warnings.Validate the returned value and handle the case gracefully.
Signed-off-by Chandra Mohan Sundar <[email protected]>--- drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c | 2 ++ 1 file changed, 2 insertions(+)drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c +0
-0drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c static int cgx_print_fwdata(struct seq_file *s, int lmac_id) · line 3012
Quoted 8 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c +2
-0@@ -3005,6 +3005,8 @@ static int cgx_print_fwdata(struct seq_file *s, int lmac_id)return -EAGAIN ; cgx_id =cgx_get_cgxid (cgxd); +if (cgx_id <0 ) +return -EINVAL ;if (rvu->hw->lmac_per_cgx ==CGX_LMACS_USX ) fwdata = &rvu->fwdata->cgx_fw_data_usx[cgx_id][lmac_id];A couple pieces of feedback for you:
1. Since this is a fixes it needs a Fixes tag and a commit SHA that it is fixing.
2.cgx_get_cgxidis called in 3 places, so your patch would probably need to be expanded to fix all uses?Overall though, did you somehow trigger this issue?
It seems like all cases where
cgx_get_cgxidis used it would be extremely difficult (maybe impossible?) for cgxd to be NULL and for it to return a negative value.