* [PATCH net v5] net/sched: cls_flower: Reject invalid ct_state flags rules
@ 2021-02-09 6:37 wenxu
2021-02-10 0:12 ` Marcelo Ricardo Leitner
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: wenxu @ 2021-02-09 6:37 UTC (permalink / raw)
To: jhs, mleitner, kuba; +Cc: netdev
From: wenxu <wenxu@ucloud.cn>
Reject the unsupported and invalid ct_state flags of cls flower rules.
Fixes: e0ace68af2ac ("net/sched: cls_flower: Add matching on conntrack info")
Signed-off-by: wenxu <wenxu@ucloud.cn>
---
include/uapi/linux/pkt_cls.h | 2 ++
net/sched/cls_flower.c | 39 +++++++++++++++++++++++++++++++++++++--
2 files changed, 39 insertions(+), 2 deletions(-)
diff --git a/include/uapi/linux/pkt_cls.h b/include/uapi/linux/pkt_cls.h
index ee95f42..88f4bf0 100644
--- a/include/uapi/linux/pkt_cls.h
+++ b/include/uapi/linux/pkt_cls.h
@@ -591,6 +591,8 @@ enum {
TCA_FLOWER_KEY_CT_FLAGS_ESTABLISHED = 1 << 1, /* Part of an existing connection. */
TCA_FLOWER_KEY_CT_FLAGS_RELATED = 1 << 2, /* Related to an established connection. */
TCA_FLOWER_KEY_CT_FLAGS_TRACKED = 1 << 3, /* Conntrack has occurred. */
+
+ __TCA_FLOWER_KEY_CT_FLAGS_MAX,
};
enum {
diff --git a/net/sched/cls_flower.c b/net/sched/cls_flower.c
index 84f9325..46c1b3e 100644
--- a/net/sched/cls_flower.c
+++ b/net/sched/cls_flower.c
@@ -30,6 +30,11 @@
#include <uapi/linux/netfilter/nf_conntrack_common.h>
+#define TCA_FLOWER_KEY_CT_FLAGS_MAX \
+ ((__TCA_FLOWER_KEY_CT_FLAGS_MAX - 1) << 1)
+#define TCA_FLOWER_KEY_CT_FLAGS_MASK \
+ (TCA_FLOWER_KEY_CT_FLAGS_MAX - 1)
+
struct fl_flow_key {
struct flow_dissector_key_meta meta;
struct flow_dissector_key_control control;
@@ -686,8 +691,10 @@ static void *fl_get(struct tcf_proto *tp, u32 handle)
[TCA_FLOWER_KEY_ENC_IP_TTL_MASK] = { .type = NLA_U8 },
[TCA_FLOWER_KEY_ENC_OPTS] = { .type = NLA_NESTED },
[TCA_FLOWER_KEY_ENC_OPTS_MASK] = { .type = NLA_NESTED },
- [TCA_FLOWER_KEY_CT_STATE] = { .type = NLA_U16 },
- [TCA_FLOWER_KEY_CT_STATE_MASK] = { .type = NLA_U16 },
+ [TCA_FLOWER_KEY_CT_STATE] =
+ NLA_POLICY_MASK(NLA_U16, TCA_FLOWER_KEY_CT_FLAGS_MASK),
+ [TCA_FLOWER_KEY_CT_STATE_MASK] =
+ NLA_POLICY_MASK(NLA_U16, TCA_FLOWER_KEY_CT_FLAGS_MASK),
[TCA_FLOWER_KEY_CT_ZONE] = { .type = NLA_U16 },
[TCA_FLOWER_KEY_CT_ZONE_MASK] = { .type = NLA_U16 },
[TCA_FLOWER_KEY_CT_MARK] = { .type = NLA_U32 },
@@ -1390,12 +1397,33 @@ static int fl_set_enc_opt(struct nlattr **tb, struct fl_flow_key *key,
return 0;
}
+static int fl_validate_ct_state(u16 state, struct nlattr *tb,
+ struct netlink_ext_ack *extack)
+{
+ if (state && !(state & TCA_FLOWER_KEY_CT_FLAGS_TRACKED)) {
+ NL_SET_ERR_MSG_ATTR(extack, tb,
+ "no trk, so no other flag can be set");
+ return -EINVAL;
+ }
+
+ if (state & TCA_FLOWER_KEY_CT_FLAGS_NEW &&
+ state & TCA_FLOWER_KEY_CT_FLAGS_ESTABLISHED) {
+ NL_SET_ERR_MSG_ATTR(extack, tb,
+ "new and est are mutually exclusive");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
static int fl_set_key_ct(struct nlattr **tb,
struct flow_dissector_key_ct *key,
struct flow_dissector_key_ct *mask,
struct netlink_ext_ack *extack)
{
if (tb[TCA_FLOWER_KEY_CT_STATE]) {
+ int err;
+
if (!IS_ENABLED(CONFIG_NF_CONNTRACK)) {
NL_SET_ERR_MSG(extack, "Conntrack isn't enabled");
return -EOPNOTSUPP;
@@ -1403,6 +1431,13 @@ static int fl_set_key_ct(struct nlattr **tb,
fl_set_key_val(tb, &key->ct_state, TCA_FLOWER_KEY_CT_STATE,
&mask->ct_state, TCA_FLOWER_KEY_CT_STATE_MASK,
sizeof(key->ct_state));
+
+ err = fl_validate_ct_state(mask->ct_state,
+ tb[TCA_FLOWER_KEY_CT_STATE_MASK],
+ extack);
+ if (err)
+ return err;
+
}
if (tb[TCA_FLOWER_KEY_CT_ZONE]) {
if (!IS_ENABLED(CONFIG_NF_CONNTRACK_ZONES)) {
--
1.8.3.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net v5] net/sched: cls_flower: Reject invalid ct_state flags rules
2021-02-09 6:37 [PATCH net v5] net/sched: cls_flower: Reject invalid ct_state flags rules wenxu
@ 2021-02-10 0:12 ` Marcelo Ricardo Leitner
2021-02-10 18:56 ` Jakub Kicinski
2021-02-10 23:40 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Marcelo Ricardo Leitner @ 2021-02-10 0:12 UTC (permalink / raw)
To: wenxu; +Cc: jhs, kuba, netdev, Marcelo Ricardo Leitner
On Tue, Feb 09, 2021 at 02:37:49PM +0800, wenxu@ucloud.cn wrote:
> --- a/net/sched/cls_flower.c
> +++ b/net/sched/cls_flower.c
> @@ -30,6 +30,11 @@
>
> #include <uapi/linux/netfilter/nf_conntrack_common.h>
>
> +#define TCA_FLOWER_KEY_CT_FLAGS_MAX \
> + ((__TCA_FLOWER_KEY_CT_FLAGS_MAX - 1) << 1)
> +#define TCA_FLOWER_KEY_CT_FLAGS_MASK \
> + (TCA_FLOWER_KEY_CT_FLAGS_MAX - 1)
> +
> struct fl_flow_key {
> struct flow_dissector_key_meta meta;
> struct flow_dissector_key_control control;
> @@ -686,8 +691,10 @@ static void *fl_get(struct tcf_proto *tp, u32 handle)
> [TCA_FLOWER_KEY_ENC_IP_TTL_MASK] = { .type = NLA_U8 },
> [TCA_FLOWER_KEY_ENC_OPTS] = { .type = NLA_NESTED },
> [TCA_FLOWER_KEY_ENC_OPTS_MASK] = { .type = NLA_NESTED },
> - [TCA_FLOWER_KEY_CT_STATE] = { .type = NLA_U16 },
> - [TCA_FLOWER_KEY_CT_STATE_MASK] = { .type = NLA_U16 },
> + [TCA_FLOWER_KEY_CT_STATE] =
> + NLA_POLICY_MASK(NLA_U16, TCA_FLOWER_KEY_CT_FLAGS_MASK),
> + [TCA_FLOWER_KEY_CT_STATE_MASK] =
> + NLA_POLICY_MASK(NLA_U16, TCA_FLOWER_KEY_CT_FLAGS_MASK),
> [TCA_FLOWER_KEY_CT_ZONE] = { .type = NLA_U16 },
> [TCA_FLOWER_KEY_CT_ZONE_MASK] = { .type = NLA_U16 },
> [TCA_FLOWER_KEY_CT_MARK] = { .type = NLA_U32 },
> @@ -1390,12 +1397,33 @@ static int fl_set_enc_opt(struct nlattr **tb, struct fl_flow_key *key,
> return 0;
> }
>
> +static int fl_validate_ct_state(u16 state, struct nlattr *tb,
> + struct netlink_ext_ack *extack)
> +{
> + if (state && !(state & TCA_FLOWER_KEY_CT_FLAGS_TRACKED)) {
> + NL_SET_ERR_MSG_ATTR(extack, tb,
> + "no trk, so no other flag can be set");
I just tested iproute2 and it can't report based on the attr here.
Nonetheless, that would be iproute2 job and not the errmsg, I think.
Reviewed-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Thanks!
> + return -EINVAL;
> + }
> +
> + if (state & TCA_FLOWER_KEY_CT_FLAGS_NEW &&
> + state & TCA_FLOWER_KEY_CT_FLAGS_ESTABLISHED) {
> + NL_SET_ERR_MSG_ATTR(extack, tb,
> + "new and est are mutually exclusive");
> + return -EINVAL;
> + }
> +
> + return 0;
> +}
> +
> static int fl_set_key_ct(struct nlattr **tb,
> struct flow_dissector_key_ct *key,
> struct flow_dissector_key_ct *mask,
> struct netlink_ext_ack *extack)
> {
> if (tb[TCA_FLOWER_KEY_CT_STATE]) {
> + int err;
> +
> if (!IS_ENABLED(CONFIG_NF_CONNTRACK)) {
> NL_SET_ERR_MSG(extack, "Conntrack isn't enabled");
> return -EOPNOTSUPP;
> @@ -1403,6 +1431,13 @@ static int fl_set_key_ct(struct nlattr **tb,
> fl_set_key_val(tb, &key->ct_state, TCA_FLOWER_KEY_CT_STATE,
> &mask->ct_state, TCA_FLOWER_KEY_CT_STATE_MASK,
> sizeof(key->ct_state));
> +
> + err = fl_validate_ct_state(mask->ct_state,
> + tb[TCA_FLOWER_KEY_CT_STATE_MASK],
> + extack);
> + if (err)
> + return err;
> +
> }
> if (tb[TCA_FLOWER_KEY_CT_ZONE]) {
> if (!IS_ENABLED(CONFIG_NF_CONNTRACK_ZONES)) {
> --
> 1.8.3.1
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net v5] net/sched: cls_flower: Reject invalid ct_state flags rules
2021-02-09 6:37 [PATCH net v5] net/sched: cls_flower: Reject invalid ct_state flags rules wenxu
2021-02-10 0:12 ` Marcelo Ricardo Leitner
@ 2021-02-10 18:56 ` Jakub Kicinski
2021-02-10 23:40 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Jakub Kicinski @ 2021-02-10 18:56 UTC (permalink / raw)
To: wenxu; +Cc: jhs, mleitner, netdev
On Tue, 9 Feb 2021 14:37:49 +0800 wenxu@ucloud.cn wrote:
> From: wenxu <wenxu@ucloud.cn>
>
> Reject the unsupported and invalid ct_state flags of cls flower rules.
>
> Fixes: e0ace68af2ac ("net/sched: cls_flower: Add matching on conntrack info")
> Signed-off-by: wenxu <wenxu@ucloud.cn>
As long as Cong is okay with the messages:
Reviewed-by: Jakub Kicinski <kuba@kernel.org>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net v5] net/sched: cls_flower: Reject invalid ct_state flags rules
2021-02-09 6:37 [PATCH net v5] net/sched: cls_flower: Reject invalid ct_state flags rules wenxu
2021-02-10 0:12 ` Marcelo Ricardo Leitner
2021-02-10 18:56 ` Jakub Kicinski
@ 2021-02-10 23:40 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-02-10 23:40 UTC (permalink / raw)
To: wenxu; +Cc: jhs, mleitner, kuba, netdev
Hello:
This patch was applied to netdev/net.git (refs/heads/master):
On Tue, 9 Feb 2021 14:37:49 +0800 you wrote:
> From: wenxu <wenxu@ucloud.cn>
>
> Reject the unsupported and invalid ct_state flags of cls flower rules.
>
> Fixes: e0ace68af2ac ("net/sched: cls_flower: Add matching on conntrack info")
> Signed-off-by: wenxu <wenxu@ucloud.cn>
>
> [...]
Here is the summary with links:
- [net,v5] net/sched: cls_flower: Reject invalid ct_state flags rules
https://git.kernel.org/netdev/net/c/1bcc51ac0731
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:[~2021-02-10 23:41 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-09 6:37 [PATCH net v5] net/sched: cls_flower: Reject invalid ct_state flags rules wenxu
2021-02-10 0:12 ` Marcelo Ricardo Leitner
2021-02-10 18:56 ` Jakub Kicinski
2021-02-10 23:40 ` patchwork-bot+netdevbpf
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.