* [PATCH net] net: flower: fix stack-out-of-bounds in fl_set_key_cfm()
@ 2023-07-24 16:32 Eric Dumazet
2023-07-24 16:38 ` Eric Dumazet
2023-07-25 6:44 ` Zahari Doychev
0 siblings, 2 replies; 4+ messages in thread
From: Eric Dumazet @ 2023-07-24 16:32 UTC (permalink / raw)
To: David S . Miller, Jakub Kicinski, Paolo Abeni
Cc: Jamal Hadi Salim, Cong Wang, Jiri Pirko, netdev, eric.dumazet,
Eric Dumazet, syzbot, Simon Horman, Ido Schimmel
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 <syzkaller@googlegroups.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Simon Horman <simon.horman@corigine.com>
Cc: Ido Schimmel <idosch@nvidia.com>
---
net/sched/cls_flower.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/sched/cls_flower.c b/net/sched/cls_flower.c
index 8da9d039d964ea417700a2f59ad95a9ce52f5eab..3c7a272bf7c7cf7d4ae21b5370cbc428086d6979 100644
--- a/net/sched/cls_flower.c
+++ b/net/sched/cls_flower.c
@@ -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])
--
2.41.0.487.g6d72f3e995-goog
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net] net: flower: fix stack-out-of-bounds in fl_set_key_cfm()
2023-07-24 16:32 [PATCH net] net: flower: fix stack-out-of-bounds in fl_set_key_cfm() Eric Dumazet
@ 2023-07-24 16:38 ` Eric Dumazet
2023-07-25 6:44 ` Zahari Doychev
1 sibling, 0 replies; 4+ messages in thread
From: Eric Dumazet @ 2023-07-24 16:38 UTC (permalink / raw)
To: David S . Miller, Jakub Kicinski, Paolo Abeni, Zahari Doychev
Cc: Jamal Hadi Salim, Cong Wang, Jiri Pirko, netdev, eric.dumazet,
syzbot, Simon Horman, Ido Schimmel
On Mon, Jul 24, 2023 at 6:32 PM Eric Dumazet <edumazet@google.com> wrote:
>
> 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 <syzkaller@googlegroups.com>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: Simon Horman <simon.horman@corigine.com>
> Cc: Ido Schimmel <idosch@nvidia.com>
> ---
> net/sched/cls_flower.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/sched/cls_flower.c b/net/sched/cls_flower.c
> index 8da9d039d964ea417700a2f59ad95a9ce52f5eab..3c7a272bf7c7cf7d4ae21b5370cbc428086d6979 100644
> --- a/net/sched/cls_flower.c
> +++ b/net/sched/cls_flower.c
> @@ -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])
> --
> 2.41.0.487.g6d72f3e995-goog
>
Cc Zahari Doychev <zdoychev@maxlinear.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net] net: flower: fix stack-out-of-bounds in fl_set_key_cfm()
2023-07-24 16:32 [PATCH net] net: flower: fix stack-out-of-bounds in fl_set_key_cfm() Eric Dumazet
2023-07-24 16:38 ` Eric Dumazet
@ 2023-07-25 6:44 ` Zahari Doychev
2023-07-25 12:04 ` Ido Schimmel
1 sibling, 1 reply; 4+ messages in thread
From: Zahari Doychev @ 2023-07-25 6:44 UTC (permalink / raw)
To: Eric Dumazet
Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, Jamal Hadi Salim,
Cong Wang, Jiri Pirko, netdev, eric.dumazet, syzbot, Simon Horman,
Ido Schimmel
On Mon, Jul 24, 2023 at 04:32:54PM +0000, Eric Dumazet wrote:
> 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 <syzkaller@googlegroups.com>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: Simon Horman <simon.horman@corigine.com>
> Cc: Ido Schimmel <idosch@nvidia.com>
> ---
> net/sched/cls_flower.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/sched/cls_flower.c b/net/sched/cls_flower.c
> index 8da9d039d964ea417700a2f59ad95a9ce52f5eab..3c7a272bf7c7cf7d4ae21b5370cbc428086d6979 100644
> --- a/net/sched/cls_flower.c
> +++ b/net/sched/cls_flower.c
> @@ -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:
diff --git a/include/uapi/linux/pkt_cls.h b/include/uapi/linux/pkt_cls.h
index 7865f5a9885b..4f3932bb712d 100644
--- a/include/uapi/linux/pkt_cls.h
+++ b/include/uapi/linux/pkt_cls.h
@@ -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
> int err;
>
> if (!tb[TCA_FLOWER_KEY_CFM])
> --
> 2.41.0.487.g6d72f3e995-goog
>
>
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net] net: flower: fix stack-out-of-bounds in fl_set_key_cfm()
2023-07-25 6:44 ` Zahari Doychev
@ 2023-07-25 12:04 ` Ido Schimmel
0 siblings, 0 replies; 4+ messages in thread
From: Ido Schimmel @ 2023-07-25 12:04 UTC (permalink / raw)
To: Zahari Doychev
Cc: Eric Dumazet, David S . Miller, Jakub Kicinski, Paolo Abeni,
Jamal Hadi Salim, Cong Wang, Jiri Pirko, netdev, eric.dumazet,
syzbot, Simon Horman, Ido Schimmel
On Tue, Jul 25, 2023 at 08:44:42AM +0200, Zahari Doychev wrote:
> On Mon, Jul 24, 2023 at 04:32:54PM +0000, Eric Dumazet wrote:
> > 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 <syzkaller@googlegroups.com>
> > Signed-off-by: Eric Dumazet <edumazet@google.com>
> > Cc: Simon Horman <simon.horman@corigine.com>
> > Cc: Ido Schimmel <idosch@nvidia.com>
> > ---
> > net/sched/cls_flower.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/net/sched/cls_flower.c b/net/sched/cls_flower.c
> > index 8da9d039d964ea417700a2f59ad95a9ce52f5eab..3c7a272bf7c7cf7d4ae21b5370cbc428086d6979 100644
> > --- a/net/sched/cls_flower.c
> > +++ b/net/sched/cls_flower.c
> > @@ -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:
>
> diff --git a/include/uapi/linux/pkt_cls.h b/include/uapi/linux/pkt_cls.h
> index 7865f5a9885b..4f3932bb712d 100644
> --- a/include/uapi/linux/pkt_cls.h
> +++ b/include/uapi/linux/pkt_cls.h
> @@ -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]
diff --git a/include/uapi/linux/pkt_cls.h b/include/uapi/linux/pkt_cls.h
index 7865f5a9885b..4f3932bb712d 100644
--- a/include/uapi/linux/pkt_cls.h
+++ b/include/uapi/linux/pkt_cls.h
@@ -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 */
diff --git a/net/sched/cls_flower.c b/net/sched/cls_flower.c
index 8da9d039d964..9f0711da9c95 100644
--- a/net/sched/cls_flower.c
+++ b/net/sched/cls_flower.c
@@ -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])
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-07-25 12:05 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-24 16:32 [PATCH net] net: flower: fix stack-out-of-bounds in fl_set_key_cfm() Eric Dumazet
2023-07-24 16:38 ` Eric Dumazet
2023-07-25 6:44 ` Zahari Doychev
2023-07-25 12:04 ` Ido Schimmel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).