Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: sched: fix erspan_opt settings in cls_flower

When matching erspan_opt in cls_flower, only the (version, dir, hwid)
fields are relevant. However, in fl_set_erspan_opt() it initializes
all bits of erspan_opt and its mask to 1. This inadvertently requires
packets to match not only the (version, dir, hwid) fields but also the
other fields that are unexpectedly set to 1.

This patch resolves the issue by ensuring that only the (version, dir,
hwid) fields are configured in fl_set_erspan_opt(), leaving the other
fields to 0 in erspan_opt.

Fixes: 79b1011cb33d ("net: sched: allow flower to match erspan options")
Reported-by: Shuang Li <shuali@redhat.com>
Signed-off-by: Xin Long <lucien.xin@gmail.com>
Reviewed-by: Cong Wang <cong.wang@bytedance.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Xin Long and committed by
David S. Miller
29220780 94071909

+3 -2
+3 -2
net/sched/cls_flower.c
··· 1369 1369 int err; 1370 1370 1371 1371 md = (struct erspan_metadata *)&key->enc_opts.data[key->enc_opts.len]; 1372 - memset(md, 0xff, sizeof(*md)); 1373 1372 md->version = 1; 1374 1373 1375 1374 if (!depth) ··· 1397 1398 NL_SET_ERR_MSG(extack, "Missing tunnel key erspan option index"); 1398 1399 return -EINVAL; 1399 1400 } 1401 + memset(&md->u.index, 0xff, sizeof(md->u.index)); 1400 1402 if (tb[TCA_FLOWER_KEY_ENC_OPT_ERSPAN_INDEX]) { 1401 1403 nla = tb[TCA_FLOWER_KEY_ENC_OPT_ERSPAN_INDEX]; 1402 - memset(&md->u, 0x00, sizeof(md->u)); 1403 1404 md->u.index = nla_get_be32(nla); 1404 1405 } 1405 1406 } else if (md->version == 2) { ··· 1408 1409 NL_SET_ERR_MSG(extack, "Missing tunnel key erspan option dir or hwid"); 1409 1410 return -EINVAL; 1410 1411 } 1412 + md->u.md2.dir = 1; 1411 1413 if (tb[TCA_FLOWER_KEY_ENC_OPT_ERSPAN_DIR]) { 1412 1414 nla = tb[TCA_FLOWER_KEY_ENC_OPT_ERSPAN_DIR]; 1413 1415 md->u.md2.dir = nla_get_u8(nla); 1414 1416 } 1417 + set_hwid(&md->u.md2, 0xff); 1415 1418 if (tb[TCA_FLOWER_KEY_ENC_OPT_ERSPAN_HWID]) { 1416 1419 nla = tb[TCA_FLOWER_KEY_ENC_OPT_ERSPAN_HWID]; 1417 1420 set_hwid(&md->u.md2, nla_get_u8(nla));