All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net v2] net/sched: cls_flower: Reject invalid ct_state flags rules
@ 2021-02-04 15:46 wenxu
  2021-02-04 15:51 ` Marcelo Ricardo Leitner
  0 siblings, 1 reply; 3+ messages in thread
From: wenxu @ 2021-02-04 15:46 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 |  7 +++++++
 net/sched/cls_flower.c       | 30 ++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+)

diff --git a/include/uapi/linux/pkt_cls.h b/include/uapi/linux/pkt_cls.h
index ee95f42..77df582 100644
--- a/include/uapi/linux/pkt_cls.h
+++ b/include/uapi/linux/pkt_cls.h
@@ -591,8 +591,15 @@ 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,
 };
 
+#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)
+
 enum {
 	TCA_FLOWER_KEY_ENC_OPTS_UNSPEC,
 	TCA_FLOWER_KEY_ENC_OPTS_GENEVE, /* Nested
diff --git a/net/sched/cls_flower.c b/net/sched/cls_flower.c
index 84f9325..1cfdbd4 100644
--- a/net/sched/cls_flower.c
+++ b/net/sched/cls_flower.c
@@ -1390,12 +1390,37 @@ 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 netlink_ext_ack *extack)
+{
+	if (state & ~TCA_FLOWER_KEY_CT_FLAGS_MASK) {
+		NL_SET_ERR_MSG_MOD(extack, "unsupported ct_state flags");
+		return -EINVAL;
+	}
+
+	if (state && !(state & TCA_FLOWER_KEY_CT_FLAGS_TRACKED)) {
+		NL_SET_ERR_MSG_MOD(extack,
+				   "ct_state trk unset, no other flag are set");
+		return -EINVAL;
+	}
+
+	if (state & TCA_FLOWER_KEY_CT_FLAGS_NEW &&
+	    state & TCA_FLOWER_KEY_CT_FLAGS_ESTABLISHED) {
+		NL_SET_ERR_MSG_MOD(extack,
+				   "ct_state new and est are 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 +1428,11 @@ 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, 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] 3+ messages in thread

* Re: [PATCH net v2] net/sched: cls_flower: Reject invalid ct_state flags rules
  2021-02-04 15:46 [PATCH net v2] net/sched: cls_flower: Reject invalid ct_state flags rules wenxu
@ 2021-02-04 15:51 ` Marcelo Ricardo Leitner
  2021-02-04 20:49   ` Jakub Kicinski
  0 siblings, 1 reply; 3+ messages in thread
From: Marcelo Ricardo Leitner @ 2021-02-04 15:51 UTC (permalink / raw)
  To: wenxu; +Cc: jhs, kuba, netdev, Ilya Maximets

On Thu, Feb 04, 2021 at 11:46:11PM +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")
> 

Hopefully Jakub can strip the blank line above.

> Signed-off-by: wenxu <wenxu@ucloud.cn>

Reviewed-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net v2] net/sched: cls_flower: Reject invalid ct_state flags rules
  2021-02-04 15:51 ` Marcelo Ricardo Leitner
@ 2021-02-04 20:49   ` Jakub Kicinski
  0 siblings, 0 replies; 3+ messages in thread
From: Jakub Kicinski @ 2021-02-04 20:49 UTC (permalink / raw)
  To: Marcelo Ricardo Leitner, wenxu; +Cc: jhs, netdev, Ilya Maximets

On Thu, 4 Feb 2021 12:51:01 -0300 Marcelo Ricardo Leitner wrote:
> On Thu, Feb 04, 2021 at 11:46:11PM +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")
> >   
> 
> Hopefully Jakub can strip the blank line above.

Let's do one more spin, actually. Please remove this empty line between
tags wenxu.

> > +	if (state & ~TCA_FLOWER_KEY_CT_FLAGS_MASK) {
> > +		NL_SET_ERR_MSG_MOD(extack, "unsupported ct_state flags");
> > +		return -EINVAL;
> > +	}

For this check - can we use NLA_POLICY_MASK() please?

I wonder if we should use NL_SET_ERR_MSG_ATTR() for other checks.
Sadly there's no macro for both MOD and ATTR, and this is a fix,
but ATTR is probably far more informative than the module name so
I'd go with ATTR.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-02-04 20:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-04 15:46 [PATCH net v2] net/sched: cls_flower: Reject invalid ct_state flags rules wenxu
2021-02-04 15:51 ` Marcelo Ricardo Leitner
2021-02-04 20:49   ` Jakub Kicinski

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.