Skip to content

Commit 63c8299

Browse files
Jakub Kicinskidavem330
authored andcommitted
net: sched: cls_flower: validate nested enc_opts_policy to avoid warning
TCA_FLOWER_KEY_ENC_OPTS and TCA_FLOWER_KEY_ENC_OPTS_MASK can only currently contain further nested attributes, which are parsed by hand, so the policy is never actually used resulting in a W=1 build warning: net/sched/cls_flower.c:492:1: warning: ‘enc_opts_policy’ defined but not used [-Wunused-const-variable=] enc_opts_policy[TCA_FLOWER_KEY_ENC_OPTS_MAX + 1] = { Add the validation anyway to avoid potential bugs when other attributes are added and to make the attribute structure slightly more clear. Validation will also set extact to point to bad attribute on error. Fixes: 0a6e777 ("net/sched: allow flower to match tunnel options") Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com> Acked-by: Simon Horman <simon.horman@netronome.com> Acked-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent fbd1d52 commit 63c8299

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

net/sched/cls_flower.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,11 +709,23 @@ static int fl_set_enc_opt(struct nlattr **tb, struct fl_flow_key *key,
709709
struct netlink_ext_ack *extack)
710710
{
711711
const struct nlattr *nla_enc_key, *nla_opt_key, *nla_opt_msk = NULL;
712-
int option_len, key_depth, msk_depth = 0;
712+
int err, option_len, key_depth, msk_depth = 0;
713+
714+
err = nla_validate_nested(tb[TCA_FLOWER_KEY_ENC_OPTS],
715+
TCA_FLOWER_KEY_ENC_OPTS_MAX,
716+
enc_opts_policy, extack);
717+
if (err)
718+
return err;
713719

714720
nla_enc_key = nla_data(tb[TCA_FLOWER_KEY_ENC_OPTS]);
715721

716722
if (tb[TCA_FLOWER_KEY_ENC_OPTS_MASK]) {
723+
err = nla_validate_nested(tb[TCA_FLOWER_KEY_ENC_OPTS_MASK],
724+
TCA_FLOWER_KEY_ENC_OPTS_MAX,
725+
enc_opts_policy, extack);
726+
if (err)
727+
return err;
728+
717729
nla_opt_msk = nla_data(tb[TCA_FLOWER_KEY_ENC_OPTS_MASK]);
718730
msk_depth = nla_len(tb[TCA_FLOWER_KEY_ENC_OPTS_MASK]);
719731
}

0 commit comments

Comments
 (0)