Skip to content

Commit 6ebbe97

Browse files
azaki1anguy11
authored andcommitted
ice: Add a per-VF limit on number of FDIR filters
While the iavf driver adds a s/w limit (128) on the number of FDIR filters that the VF can request, a malicious VF driver can request more than that and exhaust the resources for other VFs. Add a similar limit in ice. CC: [email protected] Fixes: 1f7ea1c ("ice: Enable FDIR Configure for AVF") Reviewed-by: Przemek Kitszel <[email protected]> Suggested-by: Sridhar Samudrala <[email protected]> Signed-off-by: Ahmed Zaki <[email protected]> Reviewed-by: Wojciech Drewek <[email protected]> Tested-by: Rafal Romanowski <[email protected]> Signed-off-by: Tony Nguyen <[email protected]>
1 parent 3ba359c commit 6ebbe97

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

drivers/net/ethernet/intel/ice/ice_ethtool_fdir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ ice_parse_rx_flow_user_data(struct ethtool_rx_flow_spec *fsp,
534534
*
535535
* Returns the number of available flow director filters to this VSI
536536
*/
537-
static int ice_fdir_num_avail_fltr(struct ice_hw *hw, struct ice_vsi *vsi)
537+
int ice_fdir_num_avail_fltr(struct ice_hw *hw, struct ice_vsi *vsi)
538538
{
539539
u16 vsi_num = ice_get_hw_vsi_num(hw, vsi->idx);
540540
u16 num_guar;

drivers/net/ethernet/intel/ice/ice_fdir.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ struct ice_fdir_base_pkt {
207207
const u8 *tun_pkt;
208208
};
209209

210+
struct ice_vsi;
211+
210212
int ice_alloc_fd_res_cntr(struct ice_hw *hw, u16 *cntr_id);
211213
int ice_free_fd_res_cntr(struct ice_hw *hw, u16 cntr_id);
212214
int ice_alloc_fd_guar_item(struct ice_hw *hw, u16 *cntr_id, u16 num_fltr);
@@ -218,6 +220,7 @@ int
218220
ice_fdir_get_gen_prgm_pkt(struct ice_hw *hw, struct ice_fdir_fltr *input,
219221
u8 *pkt, bool frag, bool tun);
220222
int ice_get_fdir_cnt_all(struct ice_hw *hw);
223+
int ice_fdir_num_avail_fltr(struct ice_hw *hw, struct ice_vsi *vsi);
221224
bool ice_fdir_is_dup_fltr(struct ice_hw *hw, struct ice_fdir_fltr *input);
222225
bool ice_fdir_has_frag(enum ice_fltr_ptype flow);
223226
struct ice_fdir_fltr *

drivers/net/ethernet/intel/ice/ice_virtchnl_fdir.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,8 @@ static void ice_vc_fdir_reset_cnt_all(struct ice_vf_fdir *fdir)
536536
fdir->fdir_fltr_cnt[flow][0] = 0;
537537
fdir->fdir_fltr_cnt[flow][1] = 0;
538538
}
539+
540+
fdir->fdir_fltr_cnt_total = 0;
539541
}
540542

541543
/**
@@ -1560,6 +1562,7 @@ ice_vc_add_fdir_fltr_post(struct ice_vf *vf, struct ice_vf_fdir_ctx *ctx,
15601562
resp->status = status;
15611563
resp->flow_id = conf->flow_id;
15621564
vf->fdir.fdir_fltr_cnt[conf->input.flow_type][is_tun]++;
1565+
vf->fdir.fdir_fltr_cnt_total++;
15631566

15641567
ret = ice_vc_send_msg_to_vf(vf, ctx->v_opcode, v_ret,
15651568
(u8 *)resp, len);
@@ -1624,6 +1627,7 @@ ice_vc_del_fdir_fltr_post(struct ice_vf *vf, struct ice_vf_fdir_ctx *ctx,
16241627
resp->status = status;
16251628
ice_vc_fdir_remove_entry(vf, conf, conf->flow_id);
16261629
vf->fdir.fdir_fltr_cnt[conf->input.flow_type][is_tun]--;
1630+
vf->fdir.fdir_fltr_cnt_total--;
16271631

16281632
ret = ice_vc_send_msg_to_vf(vf, ctx->v_opcode, v_ret,
16291633
(u8 *)resp, len);
@@ -1790,6 +1794,7 @@ int ice_vc_add_fdir_fltr(struct ice_vf *vf, u8 *msg)
17901794
struct virtchnl_fdir_add *stat = NULL;
17911795
struct virtchnl_fdir_fltr_conf *conf;
17921796
enum virtchnl_status_code v_ret;
1797+
struct ice_vsi *vf_vsi;
17931798
struct device *dev;
17941799
struct ice_pf *pf;
17951800
int is_tun = 0;
@@ -1798,6 +1803,17 @@ int ice_vc_add_fdir_fltr(struct ice_vf *vf, u8 *msg)
17981803

17991804
pf = vf->pf;
18001805
dev = ice_pf_to_dev(pf);
1806+
vf_vsi = ice_get_vf_vsi(vf);
1807+
1808+
#define ICE_VF_MAX_FDIR_FILTERS 128
1809+
if (!ice_fdir_num_avail_fltr(&pf->hw, vf_vsi) ||
1810+
vf->fdir.fdir_fltr_cnt_total >= ICE_VF_MAX_FDIR_FILTERS) {
1811+
v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1812+
dev_err(dev, "Max number of FDIR filters for VF %d is reached\n",
1813+
vf->vf_id);
1814+
goto err_exit;
1815+
}
1816+
18011817
ret = ice_vc_fdir_param_check(vf, fltr->vsi_id);
18021818
if (ret) {
18031819
v_ret = VIRTCHNL_STATUS_ERR_PARAM;

drivers/net/ethernet/intel/ice/ice_virtchnl_fdir.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ struct ice_vf_fdir_ctx {
2929
struct ice_vf_fdir {
3030
u16 fdir_fltr_cnt[ICE_FLTR_PTYPE_MAX][ICE_FD_HW_SEG_MAX];
3131
int prof_entry_cnt[ICE_FLTR_PTYPE_MAX][ICE_FD_HW_SEG_MAX];
32+
u16 fdir_fltr_cnt_total;
3233
struct ice_fd_hw_prof **fdir_prof;
3334

3435
struct idr fdir_rule_idr;

0 commit comments

Comments
 (0)