net: flower: fix stack-out-of-bounds in fl_set_key_cfm()
Subsystems (3)
PATCH 1/1 net: flower: fix stack-out-of-bounds in fl_set_key_cfm()
Typical misuse of
nla_parse_nested(array, XXX_MAX, ...);
array must be declared as
struct nlattr *array[XXX_MAX + 1];
--- net/sched/cls_flower.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/sched/cls_flower.c +1 -1
@@ -1709,7 +1709,7 @@ static int fl_set_key_cfm(struct nlattr **tb,struct fl_flow_key *mask, struct netlink_ext_ack *extack) { - struct nlattr *nla_cfm_opt[TCA_FLOWER_KEY_CFM_OPT_MAX]; + struct nlattr *nla_cfm_opt[TCA_FLOWER_KEY_CFM_OPT_MAX + 1];int err;if (!tb[TCA_FLOWER_KEY_CFM ])
Signature · 1 line
2.41.0.487.g6d72f3e995-goog
Quoted 32 lines · Eric Dumazet
Typical misuse of
nla_parse_nested(array, XXX_MAX, ...);array must be declared as
struct nlattr *array[XXX_MAX + 1];Fixes 7cfffd5fed3e ("net: flower: add support for matching cfm fields")Reported-by syzbot <[email protected]>Signed-off-by Eric Dumazet <[email protected]>Cc Simon Horman <[email protected]>Cc Ido Schimmel <[email protected]>--- net/sched/cls_flower.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/sched/cls_flower.c +1
-2@@ -1709,7 +1709,7 @@ static int fl_set_key_cfm(struct nlattr **tb,struct fl_flow_key *mask, struct netlink_ext_ack *extack) { - struct nlattr *nla_cfm_opt[TCA_FLOWER_KEY_CFM_OPT_MAX]; + struct nlattr *nla_cfm_opt[TCA_FLOWER_KEY_CFM_OPT_MAX + 1];int err;if (!tb[TCA_FLOWER_KEY_CFM ]) --
Quoted 2 lines
2.41.0.487.g6d72f3e995-goog
Cc Zahari Doychev <[email protected]>
Quoted 22 lines · Eric Dumazet
Typical misuse of
nla_parse_nested(array, XXX_MAX, ...);array must be declared as
struct nlattr *array[XXX_MAX + 1];Fixes 7cfffd5fed3e ("net: flower: add support for matching cfm fields")Reported-by syzbot <[email protected]>Signed-off-by Eric Dumazet <[email protected]>Cc Simon Horman <[email protected]>Cc Ido Schimmel <[email protected]>--- net/sched/cls_flower.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/sched/cls_flower.c +0
-0
net/sched/cls_flower.c static int fl_set_key_cfm(struct nlattr **tb, · line 1712
Quoted 5 lines
net/sched/cls_flower.c +1
-1@@ -1709,7 +1709,7 @@ static int fl_set_key_cfm(struct nlattr **tb,struct fl_flow_key *mask, struct netlink_ext_ack *extack) { - struct nlattr *nla_cfm_opt[TCA_FLOWER_KEY_CFM_OPT_MAX]; + struct nlattr *nla_cfm_opt[TCA_FLOWER_KEY_CFM_OPT_MAX + 1];
I think we need to redefine TCA_FLOWER_KEY_CFM_OPT_MAX like this as well:
include/uapi/linux/pkt_cls.h +2 -1
@@ -710,9 +710,11 @@ enum {TCA_FLOWER_KEY_CFM_OPT_UNSPEC ,TCA_FLOWER_KEY_CFM_MD_LEVEL ,TCA_FLOWER_KEY_CFM_OPCODE , - TCA_FLOWER_KEY_CFM_OPT_MAX, + __TCA_FLOWER_KEY_CFM_OPT_MAX, }; +#define TCA_FLOWER_KEY_CFM_OPT_MAX (__TCA_FLOWER_KEY_CFM_OPT_MAX - 1)
Thanks,
Zahari
Quoted 7 lines
net/sched/cls_flower.c +0
-0int err;if (!tb[TCA_FLOWER_KEY_CFM ])Signature · 1 line
2.41.0.487.g6d72f3e995-goog
Quoted 36 lines · Zahari Doychev
Quoted 22 lines · Eric Dumazet
Typical misuse of
nla_parse_nested(array, XXX_MAX, ...);array must be declared as
struct nlattr *array[XXX_MAX + 1];Fixes 7cfffd5fed3e ("net: flower: add support for matching cfm fields")Reported-by syzbot <[email protected]>Signed-off-by Eric Dumazet <[email protected]>Cc Simon Horman <[email protected]>Cc Ido Schimmel <[email protected]>--- net/sched/cls_flower.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/sched/cls_flower.c +0
-0net/sched/cls_flower.c static int fl_set_key_cfm(struct nlattr **tb, · line 1712
Quoted 5 lines
net/sched/cls_flower.c +1
-1@@ -1709,7 +1709,7 @@ static int fl_set_key_cfm(struct nlattr **tb,struct fl_flow_key *mask, struct netlink_ext_ack *extack) { - struct nlattr *nla_cfm_opt[TCA_FLOWER_KEY_CFM_OPT_MAX]; + struct nlattr *nla_cfm_opt[TCA_FLOWER_KEY_CFM_OPT_MAX + 1];I think we need to redefine
TCA_FLOWER_KEY_CFM_OPT_MAXlike this as well:include/uapi/linux/pkt_cls.h +0
-0
include/uapi/linux/pkt_cls.h enum { · line 716
Quoted 8 lines
include/uapi/linux/pkt_cls.h +2
-1@@ -710,9 +710,11 @@ enum {TCA_FLOWER_KEY_CFM_OPT_UNSPEC ,TCA_FLOWER_KEY_CFM_MD_LEVEL ,TCA_FLOWER_KEY_CFM_OPCODE , - TCA_FLOWER_KEY_CFM_OPT_MAX, + __TCA_FLOWER_KEY_CFM_OPT_MAX, }; +#define TCA_FLOWER_KEY_CFM_OPT_MAX (__TCA_FLOWER_KEY_CFM_OPT_MAX - 1)
Yes, I believe you are right. "MAX" should be the value of the highest valid attribute. That's not the case with "TCA_FLOWER_KEY_CFM_OPT_MAX". Need to adjust "cfm_opt_policy" as well.
Tested [1] and it works fine:
# cd tools/testing/selftests/net/forwarding/ # ./tc_flower_cfm.sh TEST: CFM opcode match test [ OK ] TEST: CFM level match test [ OK ] TEST: CFM opcode and level match test [ OK ]
[1]
include/uapi/linux/pkt_cls.h +3 -1
@@ -710,9 +710,11 @@ enum {TCA_FLOWER_KEY_CFM_OPT_UNSPEC ,TCA_FLOWER_KEY_CFM_MD_LEVEL ,TCA_FLOWER_KEY_CFM_OPCODE , - TCA_FLOWER_KEY_CFM_OPT_MAX, + __TCA_FLOWER_KEY_CFM_OPT_MAX, }; +#define TCA_FLOWER_KEY_CFM_OPT_MAX (__TCA_FLOWER_KEY_CFM_OPT_MAX - 1) +#define TCA_FLOWER_MASK_FLAGS_RANGE (1 << 0)/* Range-based match */ /* Match-all classifier */
net/sched/cls_flower.c +3 -2
@@ -776,7 +776,8 @@ mpls_stack_entry_policy[TCA_FLOWER_KEY_MPLS_OPT_LSE_MAX + 1] = { [TCA_FLOWER_KEY_MPLS_OPT_LSE_LABEL] = { .type = NLA_U32 }, }; -static const struct nla_policy cfm_opt_policy[TCA_FLOWER_KEY_CFM_OPT_MAX ] = { +static const struct nla_policy +cfm_opt_policy[TCA_FLOWER_KEY_CFM_OPT_MAX +1 ] = { [TCA_FLOWER_KEY_CFM_MD_LEVEL ] =NLA_POLICY_MAX (NLA_U8 ,FLOW_DIS_CFM_MDL_MAX ), [TCA_FLOWER_KEY_CFM_OPCODE ] = { .type =NLA_U8 },
@@ -1709,7 +1710,7 @@ static int fl_set_key_cfm(struct nlattr **tb,struct fl_flow_key *mask, struct netlink_ext_ack *extack) { - struct nlattr *nla_cfm_opt[TCA_FLOWER_KEY_CFM_OPT_MAX]; + struct nlattr *nla_cfm_opt[TCA_FLOWER_KEY_CFM_OPT_MAX + 1];int err;if (!tb[TCA_FLOWER_KEY_CFM ])