* [PATCH net v2] net/sched: cls_flower: exact-match ERSPAN key when no mask supplied
@ 2026-09-24 12:18 Jamal Hadi Salim
2026-09-25 14:25 ` Simon Horman
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Jamal Hadi Salim @ 2026-09-24 12:18 UTC (permalink / raw)
To: netdev
Cc: Jamal Hadi Salim, Jiri Pirko, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, Xin Long,
Victor Nogueira, stable, sashiko-bot, hybris
Commit 292207809486 ("net: sched: fix erspan_opt settings in cls_flower")
removed the unconditional memset of the erspan_metadata mask in
fl_set_erspan_opt(). On the mask-parse pass, when userspace supplies the
encap option key but no mask (TCA_FLOWER_KEY_ENC_OPTS without
TCA_FLOWER_KEY_ENC_OPTS_MASK), the !depth early return leaves the mask
zeroed -- a wildcard. A filter keyed on an ERSPAN index (v1), or dir/hwid
(v2), then matches every ERSPAN packet's values instead of exact-matching.
Default the match fields on the no-mask path the same way the with-mask
branches default them: v1 index to 0xff, v2 dir and hwid to their
exact-match masks. The union cannot just be memset to 0xff -- that would
re-mask the overlapping timestamp/sgt bytes of the v2 header that the
commit deliberately left to 0.
A mask and a key that declare different ERSPAN versions describe different
union layouts, so the mask would silently wildcard the key's matched
fields. Reject that combination. Have fl_set_erspan_opt() report the
parsed key's version back through a u8 pointer so the mask pass uses it
without re-reading the union.
This is a follow-up to commit fee10655709c ("net/sched: cls_flower:
validate mask pointer after nla_next()").
Conditions to recreate the bug: add an ERSPAN encap-opts flower filter
with a key but no mask (raw netlink, TCA_FLOWER_KEY_ENC_OPTS present,
TCA_FLOWER_KEY_ENC_OPTS_MASK absent); dump the filter and observe the
match mask is zero (wildcard) instead of exact for the supplied fields.
For the mismatch case, pair a v1 key with a v2 mask (or vice versa) and
observe the request is accepted with a mask of the other version.
Fixes: 292207809486 ("net: sched: fix erspan_opt settings in cls_flower")
Reported-by: Sashiko (gemini) <sashiko-bot@kernel.org>
Closes: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260826025123.62758-1-ljp1205831794@gmail.com
Link: https://lore.kernel.org/netdev/20260826025123.62758-1-ljp1205831794@gmail.com/
Reported-by: Sashiko (nipa) <sashiko-bot@kernel.org>
Link: https://lore.kernel.org/netdev/179003833955.2160803.1077681716391858800@kernel.org/
Suggested-by: Xin Long <lucien.xin@gmail.com>
Tested-by: hybris <hybris@mojatatu.ai>
Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
---
v1 -> v2:
- Scope the key's version default to the no-mask path only. v1 assigned
the key's version to the mask unconditionally, which changed the
with-mask parse path for a mask nest that declared no version (nipa M1).
- Reject a mask whose declared version differs from the key's; the two
versions index different union layouts, so the mismatch silently
wildcarded the key's matched fields (nipa M2).
- Set the key's parsed version through a u8 pointer argument rather than
re-reading it from the union at the call site (Xin Long).
net/sched/cls_flower.c | 39 ++++++++++++++++++++++++++++++++++-----
1 file changed, 34 insertions(+), 5 deletions(-)
diff --git a/net/sched/cls_flower.c b/net/sched/cls_flower.c
index 1cefea571efd..0c4beff18d68 100644
--- a/net/sched/cls_flower.c
+++ b/net/sched/cls_flower.c
@@ -1358,17 +1358,29 @@ static int fl_set_vxlan_opt(const struct nlattr *nla, struct fl_flow_key *key,
static int fl_set_erspan_opt(const struct nlattr *nla, struct fl_flow_key *key,
int depth, int option_len,
- struct netlink_ext_ack *extack)
+ struct netlink_ext_ack *extack, u8 *key_ver)
{
struct nlattr *tb[TCA_FLOWER_KEY_ENC_OPT_ERSPAN_MAX + 1];
struct erspan_metadata *md;
int err;
md = (struct erspan_metadata *)&key->enc_opts.data[key->enc_opts.len];
- md->version = 1;
- if (!depth)
+ if (!depth) {
+ /* No mask attribute supplied: exact-match every field the
+ * key set, keyed off the key's own version so the v2 dir/hwid
+ * bytes are masked without touching the overlapping
+ * timestamp/sgt bytes of the union (see 292207809486).
+ */
+ md->version = *key_ver;
+ if (md->version == 1) {
+ memset(&md->u.index, 0xff, sizeof(md->u.index));
+ } else if (md->version == 2) {
+ md->u.md2.dir = 1;
+ set_hwid(&md->u.md2, 0xff);
+ }
return sizeof(*md);
+ }
if (nla_type(nla) != TCA_FLOWER_KEY_ENC_OPTS_ERSPAN) {
NL_SET_ERR_MSG(extack, "Non-erspan option type for mask");
@@ -1387,6 +1399,22 @@ static int fl_set_erspan_opt(const struct nlattr *nla, struct fl_flow_key *key,
if (tb[TCA_FLOWER_KEY_ENC_OPT_ERSPAN_VER])
md->version = nla_get_u8(tb[TCA_FLOWER_KEY_ENC_OPT_ERSPAN_VER]);
+ else
+ md->version = 1;
+
+ /* The key and mask must describe the same union layout: the
+ * per-version default below only exact-matches the fields of its own
+ * version, so a mask version that differs from the key's would
+ * silently wildcard the key's matched fields. A mask without a
+ * version keeps the historical v1 default.
+ */
+ if (option_len && md->version != *key_ver) {
+ NL_SET_ERR_MSG(extack, "Tunnel key erspan option ver mismatch");
+ return -EINVAL;
+ }
+
+ if (!option_len)
+ *key_ver = md->version;
if (md->version == 1) {
if (!option_len && !tb[TCA_FLOWER_KEY_ENC_OPT_ERSPAN_INDEX]) {
@@ -1509,6 +1537,7 @@ static int fl_set_enc_opt(struct nlattr **tb, struct fl_flow_key *key,
{
const struct nlattr *nla_enc_key, *nla_opt_key, *nla_opt_msk = NULL;
int err, option_len, key_depth, msk_depth = 0;
+ u8 key_ver = 1;
err = nla_validate_nested_deprecated(tb[TCA_FLOWER_KEY_ENC_OPTS],
TCA_FLOWER_KEY_ENC_OPTS_MAX,
@@ -1607,7 +1636,7 @@ static int fl_set_enc_opt(struct nlattr **tb, struct fl_flow_key *key,
key->enc_opts.dst_opt_type = IP_TUNNEL_ERSPAN_OPT_BIT;
option_len = fl_set_erspan_opt(nla_opt_key, key,
key_depth, option_len,
- extack);
+ extack, &key_ver);
if (option_len < 0)
return option_len;
@@ -1618,7 +1647,7 @@ static int fl_set_enc_opt(struct nlattr **tb, struct fl_flow_key *key,
mask->enc_opts.dst_opt_type = IP_TUNNEL_ERSPAN_OPT_BIT;
option_len = fl_set_erspan_opt(nla_opt_msk, mask,
msk_depth, option_len,
- extack);
+ extack, &key_ver);
if (option_len < 0)
return option_len;
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH net v2] net/sched: cls_flower: exact-match ERSPAN key when no mask supplied
2026-09-24 12:18 [PATCH net v2] net/sched: cls_flower: exact-match ERSPAN key when no mask supplied Jamal Hadi Salim
@ 2026-09-25 14:25 ` Simon Horman
2026-09-25 14:39 ` Xin Long
2026-09-26 0:30 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Simon Horman @ 2026-09-25 14:25 UTC (permalink / raw)
To: Jamal Hadi Salim
Cc: netdev, Jiri Pirko, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Xin Long, Victor Nogueira, stable, sashiko-bot,
hybris
On Thu, Sep 24, 2026 at 08:18:41AM -0400, Jamal Hadi Salim wrote:
> Commit 292207809486 ("net: sched: fix erspan_opt settings in cls_flower")
> removed the unconditional memset of the erspan_metadata mask in
> fl_set_erspan_opt(). On the mask-parse pass, when userspace supplies the
> encap option key but no mask (TCA_FLOWER_KEY_ENC_OPTS without
> TCA_FLOWER_KEY_ENC_OPTS_MASK), the !depth early return leaves the mask
> zeroed -- a wildcard. A filter keyed on an ERSPAN index (v1), or dir/hwid
> (v2), then matches every ERSPAN packet's values instead of exact-matching.
>
> Default the match fields on the no-mask path the same way the with-mask
> branches default them: v1 index to 0xff, v2 dir and hwid to their
> exact-match masks. The union cannot just be memset to 0xff -- that would
> re-mask the overlapping timestamp/sgt bytes of the v2 header that the
> commit deliberately left to 0.
>
> A mask and a key that declare different ERSPAN versions describe different
> union layouts, so the mask would silently wildcard the key's matched
> fields. Reject that combination. Have fl_set_erspan_opt() report the
> parsed key's version back through a u8 pointer so the mask pass uses it
> without re-reading the union.
>
> This is a follow-up to commit fee10655709c ("net/sched: cls_flower:
> validate mask pointer after nla_next()").
>
> Conditions to recreate the bug: add an ERSPAN encap-opts flower filter
> with a key but no mask (raw netlink, TCA_FLOWER_KEY_ENC_OPTS present,
> TCA_FLOWER_KEY_ENC_OPTS_MASK absent); dump the filter and observe the
> match mask is zero (wildcard) instead of exact for the supplied fields.
> For the mismatch case, pair a v1 key with a v2 mask (or vice versa) and
> observe the request is accepted with a mask of the other version.
>
> Fixes: 292207809486 ("net: sched: fix erspan_opt settings in cls_flower")
> Reported-by: Sashiko (gemini) <sashiko-bot@kernel.org>
> Closes: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260826025123.62758-1-ljp1205831794@gmail.com
> Link: https://lore.kernel.org/netdev/20260826025123.62758-1-ljp1205831794@gmail.com/
> Reported-by: Sashiko (nipa) <sashiko-bot@kernel.org>
> Link: https://lore.kernel.org/netdev/179003833955.2160803.1077681716391858800@kernel.org/
> Suggested-by: Xin Long <lucien.xin@gmail.com>
> Tested-by: hybris <hybris@mojatatu.ai>
> Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
> ---
> v1 -> v2:
> - Scope the key's version default to the no-mask path only. v1 assigned
> the key's version to the mask unconditionally, which changed the
> with-mask parse path for a mask nest that declared no version (nipa M1).
> - Reject a mask whose declared version differs from the key's; the two
> versions index different union layouts, so the mismatch silently
> wildcarded the key's matched fields (nipa M2).
> - Set the key's parsed version through a u8 pointer argument rather than
> re-reading it from the union at the call site (Xin Long).
Reviewed-by: Simon Horman <horms@kernel.org>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH net v2] net/sched: cls_flower: exact-match ERSPAN key when no mask supplied
2026-09-24 12:18 [PATCH net v2] net/sched: cls_flower: exact-match ERSPAN key when no mask supplied Jamal Hadi Salim
2026-09-25 14:25 ` Simon Horman
@ 2026-09-25 14:39 ` Xin Long
2026-09-26 0:30 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Xin Long @ 2026-09-25 14:39 UTC (permalink / raw)
To: Jamal Hadi Salim
Cc: netdev, Jiri Pirko, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman, Victor Nogueira, stable, sashiko-bot,
hybris
On Thu, Sep 24, 2026 at 8:18 AM Jamal Hadi Salim <jhs@mojatatu.com> wrote:
>
> Commit 292207809486 ("net: sched: fix erspan_opt settings in cls_flower")
> removed the unconditional memset of the erspan_metadata mask in
> fl_set_erspan_opt(). On the mask-parse pass, when userspace supplies the
> encap option key but no mask (TCA_FLOWER_KEY_ENC_OPTS without
> TCA_FLOWER_KEY_ENC_OPTS_MASK), the !depth early return leaves the mask
> zeroed -- a wildcard. A filter keyed on an ERSPAN index (v1), or dir/hwid
> (v2), then matches every ERSPAN packet's values instead of exact-matching.
>
> Default the match fields on the no-mask path the same way the with-mask
> branches default them: v1 index to 0xff, v2 dir and hwid to their
> exact-match masks. The union cannot just be memset to 0xff -- that would
> re-mask the overlapping timestamp/sgt bytes of the v2 header that the
> commit deliberately left to 0.
>
> A mask and a key that declare different ERSPAN versions describe different
> union layouts, so the mask would silently wildcard the key's matched
> fields. Reject that combination. Have fl_set_erspan_opt() report the
> parsed key's version back through a u8 pointer so the mask pass uses it
> without re-reading the union.
>
> This is a follow-up to commit fee10655709c ("net/sched: cls_flower:
> validate mask pointer after nla_next()").
>
> Conditions to recreate the bug: add an ERSPAN encap-opts flower filter
> with a key but no mask (raw netlink, TCA_FLOWER_KEY_ENC_OPTS present,
> TCA_FLOWER_KEY_ENC_OPTS_MASK absent); dump the filter and observe the
> match mask is zero (wildcard) instead of exact for the supplied fields.
> For the mismatch case, pair a v1 key with a v2 mask (or vice versa) and
> observe the request is accepted with a mask of the other version.
>
> Fixes: 292207809486 ("net: sched: fix erspan_opt settings in cls_flower")
> Reported-by: Sashiko (gemini) <sashiko-bot@kernel.org>
> Closes: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260826025123.62758-1-ljp1205831794@gmail.com
> Link: https://lore.kernel.org/netdev/20260826025123.62758-1-ljp1205831794@gmail.com/
> Reported-by: Sashiko (nipa) <sashiko-bot@kernel.org>
> Link: https://lore.kernel.org/netdev/179003833955.2160803.1077681716391858800@kernel.org/
> Suggested-by: Xin Long <lucien.xin@gmail.com>
> Tested-by: hybris <hybris@mojatatu.ai>
> Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
Reviewed-by: Xin Long <lucien.xin@gmail.com>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH net v2] net/sched: cls_flower: exact-match ERSPAN key when no mask supplied
2026-09-24 12:18 [PATCH net v2] net/sched: cls_flower: exact-match ERSPAN key when no mask supplied Jamal Hadi Salim
2026-09-25 14:25 ` Simon Horman
2026-09-25 14:39 ` Xin Long
@ 2026-09-26 0:30 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-09-26 0:30 UTC (permalink / raw)
To: Jamal Hadi Salim
Cc: netdev, jiri, davem, edumazet, kuba, pabeni, horms, lucien.xin,
victor, stable, sashiko-bot, hybris
Hello:
This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Thu, 24 Sep 2026 08:18:41 -0400 you wrote:
> Commit 292207809486 ("net: sched: fix erspan_opt settings in cls_flower")
> removed the unconditional memset of the erspan_metadata mask in
> fl_set_erspan_opt(). On the mask-parse pass, when userspace supplies the
> encap option key but no mask (TCA_FLOWER_KEY_ENC_OPTS without
> TCA_FLOWER_KEY_ENC_OPTS_MASK), the !depth early return leaves the mask
> zeroed -- a wildcard. A filter keyed on an ERSPAN index (v1), or dir/hwid
> (v2), then matches every ERSPAN packet's values instead of exact-matching.
>
> [...]
Here is the summary with links:
- [net,v2] net/sched: cls_flower: exact-match ERSPAN key when no mask supplied
https://git.kernel.org/netdev/net-next/c/e0edf25f141a
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-09-26 0:31 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-24 12:18 [PATCH net v2] net/sched: cls_flower: exact-match ERSPAN key when no mask supplied Jamal Hadi Salim
2026-09-25 14:25 ` Simon Horman
2026-09-25 14:39 ` Xin Long
2026-09-26 0:30 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox