Skip to content

Commit fb02180

Browse files
mnazimamirulgregkh
authored andcommitted
net: stmmac: fix l3l4 filter rejecting unsupported offload requests
[ Upstream commit 5536d7c ] The basic flow parser in tc_add_basic_flow() does not validate match keys before proceeding. Unsupported offload configurations such as partial protocol masks, non-IPv4 network proto, or non-TCP/UDP transport proto are silently accepted instead of returning -EOPNOTSUPP. Add validation to return -EOPNOTSUPP early for: - No network or transport proto present in the key - Partial protocol mask (only full mask supported) - Network proto is not IPv4 - Transport proto is not TCP or UDP Each rejection includes an extack message so the user knows which part of the match is unsupported. Also propagate -EOPNOTSUPP from tc_add_basic_flow() in tc_add_flow() by returning it directly rather than using break. The break was silently discarding the error for FLOW_CLS_REPLACE operations where entry->in_use is already true, causing tc_add_flow() to return 0 (success) for unsupported replace requests. Fixes: 425eabd ("net: stmmac: Implement L3/L4 Filters using TC Flower") Signed-off-by: Rohan G Thomas <rohan.g.thomas@altera.com> Signed-off-by: Nazim Amirul <muhammad.nazim.amirul.nazle.asmade@altera.com> Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com> Link: https://patch.msgid.link/20260714023716.29865-4-muhammad.nazim.amirul.nazle.asmade@altera.com Reviewed-by: Jakub Raczynski <j.raczynski@samsung.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 71b096d commit fb02180

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ static int tc_parse_flow_actions(struct stmmac_priv *priv,
446446
}
447447

448448
#define ETHER_TYPE_FULL_MASK cpu_to_be16(~0)
449+
#define IP_PROTO_FULL_MASK 0xFF
449450

450451
static int tc_add_basic_flow(struct stmmac_priv *priv,
451452
struct flow_cls_offload *cls,
@@ -461,6 +462,37 @@ static int tc_add_basic_flow(struct stmmac_priv *priv,
461462

462463
flow_rule_match_basic(rule, &match);
463464

465+
/* Both network proto and transport proto not present in the key */
466+
if (!match.mask || !(match.mask->n_proto || match.mask->ip_proto)) {
467+
NL_SET_ERR_MSG_MOD(cls->common.extack,
468+
"filter must specify network or transport protocol");
469+
return -EOPNOTSUPP;
470+
}
471+
472+
/* If the proto is present in the key and is not full mask */
473+
if ((match.mask->n_proto && match.mask->n_proto != ETHER_TYPE_FULL_MASK) ||
474+
(match.mask->ip_proto && match.mask->ip_proto != IP_PROTO_FULL_MASK)) {
475+
NL_SET_ERR_MSG_MOD(cls->common.extack,
476+
"only full protocol mask is supported");
477+
return -EOPNOTSUPP;
478+
}
479+
480+
/* Network proto is present in the key and is not IPv4 */
481+
if (match.mask->n_proto && match.key->n_proto != cpu_to_be16(ETH_P_IP)) {
482+
NL_SET_ERR_MSG_MOD(cls->common.extack,
483+
"only IPv4 network protocol is supported");
484+
return -EOPNOTSUPP;
485+
}
486+
487+
/* Transport proto is present in the key and is not TCP or UDP */
488+
if (match.mask->ip_proto &&
489+
match.key->ip_proto != IPPROTO_TCP &&
490+
match.key->ip_proto != IPPROTO_UDP) {
491+
NL_SET_ERR_MSG_MOD(cls->common.extack,
492+
"only TCP and UDP transport protocols are supported");
493+
return -EOPNOTSUPP;
494+
}
495+
464496
entry->ip_proto = match.key->ip_proto;
465497
return 0;
466498
}
@@ -598,6 +630,8 @@ static int tc_add_flow(struct stmmac_priv *priv,
598630
ret = tc_flow_parsers[i].fn(priv, cls, entry);
599631
if (!ret)
600632
entry->in_use = true;
633+
else if (ret == -EOPNOTSUPP)
634+
return ret;
601635
}
602636

603637
if (!entry->in_use)

0 commit comments

Comments
 (0)