Checks
Context | Check | Description |
---|---|---|
ci/checkpatch | success | coding style OK |
Commit Message
Qi Zhang
Aug. 15, 2022, 7:12 a.m. UTC
The add rule functionality works fine with a NULL lookups parameter. However when running the undefined behavior sanitizer it noticed that the function could trigger a memcpy from a NULL target. Fix the code to handle NULL lkups and a zero lkups_cnt variable more explicitly, and clean up the test to just directly pass a NULL value instead of allocating a stack variable assigned to NULL and passing that as a pointer. Signed-off-by: Jesse Brandeburg <jesse.brandeburg@intel.com> Signed-off-by: Qi Zhang <qi.z.zhang@intel.com> --- drivers/net/ice/base/ice_switch.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/drivers/net/ice/base/ice_switch.c b/drivers/net/ice/base/ice_switch.c index 91a959e10f..01441211ff 100644 --- a/drivers/net/ice/base/ice_switch.c +++ b/drivers/net/ice/base/ice_switch.c @@ -9002,9 +9002,13 @@ ice_add_adv_rule(struct ice_hw *hw, struct ice_adv_lkup_elem *lkups, goto err_ice_add_adv_rule; } - adv_fltr->lkups = (struct ice_adv_lkup_elem *) - ice_memdup(hw, lkups, lkups_cnt * sizeof(*lkups), - ICE_NONDMA_TO_NONDMA); + if (lkups_cnt) { + adv_fltr->lkups = (struct ice_adv_lkup_elem *) + ice_memdup(hw, lkups, lkups_cnt * sizeof(*lkups), + ICE_NONDMA_TO_NONDMA); + } else { + adv_fltr->lkups = NULL; + } if (!adv_fltr->lkups && !prof_rule) { status = ICE_ERR_NO_MEMORY; goto err_ice_add_adv_rule;