cxgb4 holds a 24 bit VNI and truncates the key and the mask of enc_key_id. An exact key above bit 23 already selects the wrong VNI. Flower is about to accept partial masks. A mask that only covers bits above 23 would then clear the VNI mask and encap_vld. The rule would match any traffic its other keys allow. Refuse a key that no VNI can match and a mask that leaves no VNI bit. Found by an AI code review agent while auditing the users of enc_key_id. Confirmed by code inspection. The wrong match was not triggered. Build tested only. Fixes: 98f3697f8d41 ("cxgb4: add tc flower match support for tunnel VNI") Signed-off-by: Alexandre Cassen --- .../net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c index 3307e5042681..467f055e318c 100644 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c @@ -316,6 +316,21 @@ static int cxgb4_validate_flow_match(struct netlink_ext_ack *extack, return -EOPNOTSUPP; } + if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ENC_KEYID)) { + struct flow_match_enc_keyid match; + u32 key, mask; + + flow_rule_match_enc_keyid(rule, &match); + key = be32_to_cpu(match.key->keyid); + mask = be32_to_cpu(match.mask->keyid); + if (key >> ENCAP_VNI_BITWIDTH || + !(mask & GENMASK(ENCAP_VNI_BITWIDTH - 1, 0))) { + NL_SET_ERR_MSG_MOD(extack, + "Tunnel key does not fit the 24 bit VNI"); + return -EOPNOTSUPP; + } + } + if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_BASIC)) { struct flow_match_basic match; -- 2.43.0