Skip to contentSkip to conversation

netfilter: expect: Make sure the max_expected limit is effective

PATCH Superseded [email protected] 2 participants 3 messages Mar 24, 2017

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 netfilter: expect: Make sure the max_expected limit is effective

From: Gao Feng <[email protected]>

Because the type of expecting, the member of nf_conn_help, is u8, it would overflow after reach U8_MAX(255). So it doesn't work when we configure the max_expected exceeds 255 with expect policy.

Now add the check for max_expected. Return the -EINVAL when it exceeds the limit.

---
 include/net/netfilter/nf_conntrack_expect.h | 1 +
 net/netfilter/nf_conntrack_helper.c         | 3 +++
 net/netfilter/nfnetlink_cthelper.c          | 4 ++++
 3 files changed, 8 insertions(+)
include/net/netfilter/nf_conntrack_expect.h +1 -0
index 5ed33ea..aa36a31 100644
@@ -71,6 +71,7 @@ struct nf_conntrack_expect_policy {
 };
 
 #define NF_CT_EXPECT_CLASS_DEFAULT	0
+#define NF_CT_EXPECT_MAX_CNT		U8_MAX
 
 int nf_conntrack_expect_pernet_init(struct net *net);
 void nf_conntrack_expect_pernet_fini(struct net *net);
net/netfilter/nf_conntrack_helper.c +3 -0
index 6dc44d9..752a977 100644
@@ -385,6 +385,9 @@ int nf_conntrack_helper_register(struct nf_conntrack_helper *me)
 	BUG_ON(me->expect_class_max >= NF_CT_MAX_EXPECT_CLASSES);
 	BUG_ON(strlen(me->name) > NF_CT_HELPER_NAME_LEN - 1);
 
+	if (me->expect_policy->max_expected > NF_CT_EXPECT_MAX_CNT)
+		return -EINVAL;
+
 	mutex_lock(&nf_ct_helper_mutex);
 	hlist_for_each_entry(cur, &nf_ct_helper_hash[h], hnode) {
 		if (nf_ct_tuple_src_mask_cmp(&cur->tuple, &me->tuple, &mask)) {
net/netfilter/nfnetlink_cthelper.c +4 -0
index 2b987d2..de841b3 100644
@@ -143,6 +143,8 @@
 		nla_data(tb[NFCTH_POLICY_NAME]), NF_CT_HELPER_NAME_LEN);
 	expect_policy->max_expected =
 		ntohl(nla_get_be32(tb[NFCTH_POLICY_EXPECT_MAX]));
+	if (expect_policy->max_expected > NF_CT_EXPECT_MAX_CNT)
+		return -EINVAL;
 	expect_policy->timeout =
 		ntohl(nla_get_be32(tb[NFCTH_POLICY_EXPECT_TIMEOUT]));
 
@@ -280,6 +282,8 @@
 
 	new_policy->max_expected =
 		ntohl(nla_get_be32(tb[NFCTH_POLICY_EXPECT_MAX]));
+	if (new_policy->max_expected > NF_CT_EXPECT_MAX_CNT)
+		return -EINVAL;
 	new_policy->timeout =
 		ntohl(nla_get_be32(tb[NFCTH_POLICY_EXPECT_TIMEOUT]));
 
Signature · 1 line
1.9.1
#1 lore raw
Quoted 21 lines · On Fri, Mar 24, 2017 at 09:38:37AM +0800, [email protected] wrote:

From: Gao Feng <[email protected]>

Because the type of expecting, the member of nf_conn_help, is u8, it would overflow after reach U8_MAX(255). So it doesn't work when we configure the max_expected exceeds 255 with expect policy.

Now add the check for max_expected. Return the -EINVAL when it exceeds the limit.

---
 include/net/netfilter/nf_conntrack_expect.h | 1 +
 net/netfilter/nf_conntrack_helper.c         | 3 +++
 net/netfilter/nfnetlink_cthelper.c          | 4 ++++
 3 files changed, 8 insertions(+)
include/net/netfilter/nf_conntrack_expect.h +0 -0
index 5ed33ea..aa36a31 100644

include/net/netfilter/nf_conntrack_expect.h struct nf_conntrack_expect_policy { · line 74

Quoted 4 lines
include/net/netfilter/nf_conntrack_expect.h +1 -0
@@ -71,6 +71,7 @@ struct nf_conntrack_expect_policy {
 };
 
 #define NF_CT_EXPECT_CLASS_DEFAULT	0
+#define NF_CT_EXPECT_MAX_CNT		U8_MAX

use NF_CT_EXPECT_MAX. We will expose this to userspace at some point now that we have infrastructure to configure helpers from nft (Florian's work already in nf-next) so use 255 instead of U8_MAX is fine.

net/netfilter/nf_conntrack_helper.c int nf_conntrack_helper_register(struct nf_conntrack_helper *me) · line 389

Quoted 12 lines
include/net/netfilter/nf_conntrack_expect.h +0 -0
 int nf_conntrack_expect_pernet_init(struct net *net);
 void nf_conntrack_expect_pernet_fini(struct net *net);
net/netfilter/nf_conntrack_helper.c +2 -0
index 6dc44d9..752a977 100644
@@ -385,6 +385,9 @@ int nf_conntrack_helper_register(struct nf_conntrack_helper *me)
 	BUG_ON(me->expect_class_max >= NF_CT_MAX_EXPECT_CLASSES);
 	BUG_ON(strlen(me->name) > NF_CT_HELPER_NAME_LEN - 1);
 
+	if (me->expect_policy->max_expected > NF_CT_EXPECT_MAX_CNT)
+		return -EINVAL;

I swear this is also exposed through modparams, right? So this patch may be missing something.

author
#2 lore raw

Hi Pablo,

Quoted 6 lines

-----Original Message-----
From: Pablo Neira Ayuso [mailto:[email protected]]
Sent: Friday, March 24, 2017 7:43 PM
To: [email protected]
Cc: [email protected]; Gao Feng <[email protected]>
Subject: Re: [PATCH nf 1/1] netfilter: expect: Make sure the max_expected

limit

Quoted 42 lines

is effective

Quoted 22 lines · On Fri, Mar 24, 2017 at 09:38:37AM +0800, [email protected] wrote:

From: Gao Feng <[email protected]>

Because the type of expecting, the member of nf_conn_help, is u8, it would overflow after reach U8_MAX(255). So it doesn't work when we configure the max_expected exceeds 255 with expect policy.

Now add the check for max_expected. Return the -EINVAL when it exceeds the limit.

---
 include/net/netfilter/nf_conntrack_expect.h | 1 +
 net/netfilter/nf_conntrack_helper.c         | 3 +++
 net/netfilter/nfnetlink_cthelper.c          | 4 ++++
 3 files changed, 8 insertions(+)
include/net/netfilter/nf_conntrack_expect.h +0 -0
index 5ed33ea..aa36a31 100644

include/net/netfilter/nf_conntrack_expect.h struct nf_conntrack_expect_policy { }; · line 73

Quoted 3 lines
include/net/netfilter/nf_conntrack_expect.h +1 -0
@@ -71,6 +71,7 @@ struct nf_conntrack_expect_policy {  };
 
 #define NF_CT_EXPECT_CLASS_DEFAULT	0
+#define NF_CT_EXPECT_MAX_CNT		U8_MAX

use NF_CT_EXPECT_MAX. We will expose this to userspace at some point now that we have infrastructure to configure helpers from nft (Florian's work already in nf-next) so use 255 instead of U8_MAX is fine.

net/netfilter/nf_conntrack_helper.c int nf_conntrack_helper_register(struct

Quoted 8 lines
include/net/netfilter/nf_conntrack_expect.h +0 -0
 int nf_conntrack_expect_pernet_init(struct net *net);  void

nf_conntrack_expect_pernet_fini(struct net *net); diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
index 6dc44d9..752a977 100644

net/netfilter/nf_conntrack_helper.c +0 -0
@@ -385,6 +385,9 @@ int nf_conntrack_helper_register(struct

nf_conntrack_helper *me)

Quoted 7 lines

net/netfilter/nf_conntrack_helper.c int nf_conntrack_helper_register(struct nf_conntrack_helper *me) · line 389

Quoted 5 lines
net/netfilter/nf_conntrack_helper.c +2 -0
 	BUG_ON(me->expect_class_max >= NF_CT_MAX_EXPECT_CLASSES);
 	BUG_ON(strlen(me->name) > NF_CT_HELPER_NAME_LEN - 1);
 
+	if (me->expect_policy->max_expected > NF_CT_EXPECT_MAX_CNT)
+		return -EINVAL;

I swear this is also exposed through modparams, right? So this patch may

be

Quoted 1 line

missing something.

I thought it could be covered by nf_conntrack_helper_register, it would return error when modparam specifies one invalid max_expected. So I didn't check the modparam before.

Now I think you are right. It is clear to report one error by checking the modparam.
I would send the v2 patch.
There is only one case. This is the nf_conntrack_irc.c.

Best Regards
Feng