[v2,080/148] net/ice/base: check array bounds

Message ID 46403e6aaa6a5a231ba72db977d301cac18fc493.1718204529.git.anatoly.burakov@intel.com (mailing list archive)
State Superseded
Delegated to: Bruce Richardson
Headers
Series Update net/ice base driver to latest upstream snapshot |

Checks

Context Check Description
ci/checkpatch warning coding style issues

Commit Message

Anatoly Burakov June 12, 2024, 3:01 p.m. UTC
  From: Ian Stokes <ian.stokes@intel.com>

Some compilation targets were generating errors due to unchecked array bounds
when accessing recipe groups. Add a check to avoid that.

Signed-off-by: Waldemar Dworakowski <waldemar.dworakowski@intel.com>
Signed-off-by: Ian Stokes <ian.stokes@intel.com>
---
 drivers/net/ice/base/ice_switch.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
  

Patch

diff --git a/drivers/net/ice/base/ice_switch.c b/drivers/net/ice/base/ice_switch.c
index 9ea302585c..051cf087f5 100644
--- a/drivers/net/ice/base/ice_switch.c
+++ b/drivers/net/ice/base/ice_switch.c
@@ -7533,12 +7533,14 @@  ice_create_first_fit_recp_def(struct ice_hw *hw,
 				(*recp_cnt)++;
 			}
 
-			grp->pairs[grp->n_val_pairs].prot_id =
-				lkup_exts->fv_words[j].prot_id;
-			grp->pairs[grp->n_val_pairs].off =
-				lkup_exts->fv_words[j].off;
-			grp->mask[grp->n_val_pairs] = lkup_exts->field_mask[j];
-			grp->n_val_pairs++;
+			if (grp->n_val_pairs < ICE_NUM_WORDS_RECIPE) {
+				grp->pairs[grp->n_val_pairs].prot_id =
+					lkup_exts->fv_words[j].prot_id;
+				grp->pairs[grp->n_val_pairs].off =
+					lkup_exts->fv_words[j].off;
+				grp->mask[grp->n_val_pairs] = lkup_exts->field_mask[j];
+				grp->n_val_pairs++;
+			}
 		}
 
 	return 0;