Skip to content

Commit 1388dd5

Browse files
halfboy93anguy11
authored andcommitted
ice: fix using untrusted value of pkt_len in ice_vc_fdir_parse_raw()
Fix using the untrusted value of proto->raw.pkt_len in function ice_vc_fdir_parse_raw() by verifying if it does not exceed the VIRTCHNL_MAX_SIZE_RAW_PACKET value. Fixes: 99f419d ("ice: enable FDIR filters from raw binary patterns for VFs") Reviewed-by: Przemek Kitszel <[email protected]> Signed-off-by: Mateusz Polchlopek <[email protected]> Signed-off-by: Martyna Szapar-Mudlaw <[email protected]> Tested-by: Rafal Romanowski <[email protected]> Signed-off-by: Tony Nguyen <[email protected]>
1 parent c5be656 commit 1388dd5

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -832,21 +832,27 @@ ice_vc_fdir_parse_raw(struct ice_vf *vf,
832832
struct virtchnl_proto_hdrs *proto,
833833
struct virtchnl_fdir_fltr_conf *conf)
834834
{
835-
u8 *pkt_buf, *msk_buf __free(kfree);
835+
u8 *pkt_buf, *msk_buf __free(kfree) = NULL;
836836
struct ice_parser_result rslt;
837837
struct ice_pf *pf = vf->pf;
838+
u16 pkt_len, udp_port = 0;
838839
struct ice_parser *psr;
839840
int status = -ENOMEM;
840841
struct ice_hw *hw;
841-
u16 udp_port = 0;
842842

843-
pkt_buf = kzalloc(proto->raw.pkt_len, GFP_KERNEL);
844-
msk_buf = kzalloc(proto->raw.pkt_len, GFP_KERNEL);
843+
pkt_len = proto->raw.pkt_len;
844+
845+
if (!pkt_len || pkt_len > VIRTCHNL_MAX_SIZE_RAW_PACKET)
846+
return -EINVAL;
847+
848+
pkt_buf = kzalloc(pkt_len, GFP_KERNEL);
849+
msk_buf = kzalloc(pkt_len, GFP_KERNEL);
850+
845851
if (!pkt_buf || !msk_buf)
846852
goto err_mem_alloc;
847853

848-
memcpy(pkt_buf, proto->raw.spec, proto->raw.pkt_len);
849-
memcpy(msk_buf, proto->raw.mask, proto->raw.pkt_len);
854+
memcpy(pkt_buf, proto->raw.spec, pkt_len);
855+
memcpy(msk_buf, proto->raw.mask, pkt_len);
850856

851857
hw = &pf->hw;
852858

@@ -862,7 +868,7 @@ ice_vc_fdir_parse_raw(struct ice_vf *vf,
862868
if (ice_get_open_tunnel_port(hw, &udp_port, TNL_VXLAN))
863869
ice_parser_vxlan_tunnel_set(psr, udp_port, true);
864870

865-
status = ice_parser_run(psr, pkt_buf, proto->raw.pkt_len, &rslt);
871+
status = ice_parser_run(psr, pkt_buf, pkt_len, &rslt);
866872
if (status)
867873
goto err_parser_destroy;
868874

@@ -876,7 +882,7 @@ ice_vc_fdir_parse_raw(struct ice_vf *vf,
876882
}
877883

878884
status = ice_parser_profile_init(&rslt, pkt_buf, msk_buf,
879-
proto->raw.pkt_len, ICE_BLK_FD,
885+
pkt_len, ICE_BLK_FD,
880886
conf->prof);
881887
if (status)
882888
goto err_parser_profile_init;
@@ -885,7 +891,7 @@ ice_vc_fdir_parse_raw(struct ice_vf *vf,
885891
ice_parser_profile_dump(hw, conf->prof);
886892

887893
/* Store raw flow info into @conf */
888-
conf->pkt_len = proto->raw.pkt_len;
894+
conf->pkt_len = pkt_len;
889895
conf->pkt_buf = pkt_buf;
890896
conf->parser_ena = true;
891897

0 commit comments

Comments
 (0)