Skip to contentSkip to conversation

netfilter: ctlink: Return error directly when create expect without help

PATCH In review [email protected] 2 participants 4 messages Mar 28, 2017 – Apr 6, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 netfilter: ctlink: Return error directly when create expect without help

From: Gao Feng <[email protected]>

The expect check func "__nf_ct_expect_check" asks the master_help is necessary. So it is unnecessary to go ahead in ctnetlink_alloc_expect when there is no help.

Actually the commit bc01befdcf3e ("netfilter: ctnetlink: add support for user-space expectation helpers") permits ctlink create one expect even though there is no master help. But the latter commit 3d058d7bc2c5 ("netfilter: rework user-space expectation helper support") disables it again.

---
 net/netfilter/nf_conntrack_netlink.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)
net/netfilter/nf_conntrack_netlink.c +2 -12
index d49cc1e..c9af545 100644
@@ -3049,18 +3049,8 @@ static int ctnetlink_del_expect(struct net *net, struct sock *ctnl,
 
 	help = nfct_help(ct);
 	if (!help) {
-		if (!cda[CTA_EXPECT_TIMEOUT]) {
-			err = -EINVAL;
-			goto err_out;
-		}
-		exp->timeout.expires =
-		  jiffies + ntohl(nla_get_be32(cda[CTA_EXPECT_TIMEOUT])) * HZ;
-
-		exp->flags = NF_CT_EXPECT_USERSPACE;
-		if (cda[CTA_EXPECT_FLAGS]) {
-			exp->flags |=
-				ntohl(nla_get_be32(cda[CTA_EXPECT_FLAGS]));
-		}
+		err = -EOPNOTSUPP;
+		goto err_out;
 	} else {
 		if (cda[CTA_EXPECT_FLAGS]) {
 			exp->flags = ntohl(nla_get_be32(cda[CTA_EXPECT_FLAGS]));
Signature · 1 line
1.9.1
#1 lore raw
Quoted 11 lines · On Tue, Mar 28, 2017 at 09:52:52AM +0800, [email protected] wrote:

From: Gao Feng <[email protected]>

The expect check func "__nf_ct_expect_check" asks the master_help is necessary. So it is unnecessary to go ahead in ctnetlink_alloc_expect when there is no help.

Actually the commit bc01befdcf3e ("netfilter: ctnetlink: add support for user-space expectation helpers") permits ctlink create one expect even though there is no master help. But the latter commit 3d058d7bc2c5 ("netfilter: rework user-space expectation helper support") disables it again.

Probably reject this upfront if no nfct_help(ct) is there.

See patch attached.

commit 543b8a39eaacef70822f23f8e8de336c18761c40

Author: Gao Feng <[email protected]>
Date:   Tue Mar 28 09:52:52 2017 +0800

netfilter: ctnetlink: Expectations must have a conntrack helper area

The expect check function __nf_ct_expect_check() asks the master_help is necessary. So it is unnecessary to go ahead in ctnetlink_alloc_expect when there is no help.

Actually the commit bc01befdcf3e ("netfilter: ctnetlink: add support for user-space expectation helpers") permits ctnetlink create one expect even though there is no master help. But the latter commit 3d058d7bc2c5 ("netfilter: rework user-space expectation helper support") disables it again.

net/netfilter/nf_conntrack_netlink.c +8 -19
index ecdc324c7785..cd0a6d270ebe 100644
@@ -3038,6 +3038,10 @@ ctnetlink_alloc_expect(const struct nlattr * const cda[], struct nf_conn *ct,
 	struct nf_conn_help *help;
 	int err;
 
+	help = nfct_help(ct);
+	if (!help)
+		return ERR_PTR(-EOPNOTSUPP);
+
 	if (cda[CTA_EXPECT_CLASS] && helper) {
 		class = ntohl(nla_get_be32(cda[CTA_EXPECT_CLASS]));
 		if (class > helper->expect_class_max)
@@ -3047,26 +3051,11 @@ ctnetlink_alloc_expect(const struct nlattr * const cda[], struct nf_conn *ct,
 	if (!exp)
 		return ERR_PTR(-ENOMEM);
 
-	help = nfct_help(ct);
-	if (!help) {
-		if (!cda[CTA_EXPECT_TIMEOUT]) {
-			err = -EINVAL;
-			goto err_out;
-		}
-		exp->timeout.expires =
-		  jiffies + ntohl(nla_get_be32(cda[CTA_EXPECT_TIMEOUT])) * HZ;
-
-		exp->flags = NF_CT_EXPECT_USERSPACE;
-		if (cda[CTA_EXPECT_FLAGS]) {
-			exp->flags |=
-				ntohl(nla_get_be32(cda[CTA_EXPECT_FLAGS]));
-		}
+	if (cda[CTA_EXPECT_FLAGS]) {
+		exp->flags = ntohl(nla_get_be32(cda[CTA_EXPECT_FLAGS]));
+		exp->flags &= ~NF_CT_EXPECT_USERSPACE;
 	} else {
-		if (cda[CTA_EXPECT_FLAGS]) {
-			exp->flags = ntohl(nla_get_be32(cda[CTA_EXPECT_FLAGS]));
-			exp->flags &= ~NF_CT_EXPECT_USERSPACE;
-		} else
-			exp->flags = 0;
+		exp->flags = 0;
 	}
 	if (cda[CTA_EXPECT_FN]) {
 		const char *name = nla_data(cda[CTA_EXPECT_FN]);
author
#2 lore raw

Hi Pablo,

Quoted 6 lines

-----Original Message-----
From: Pablo Neira Ayuso [mailto:[email protected]]
Sent: Friday, April 7, 2017 3:55 AM
To: [email protected]
Cc: [email protected]; Gao Feng <[email protected]>
Subject: Re: [PATCH nf-next 1/1] netfilter: ctlink: Return error directly

when

Quoted 16 lines

create expect without help

Quoted 6 lines · On Tue, Mar 28, 2017 at 09:52:52AM +0800, [email protected] wrote:

From: Gao Feng <[email protected]>

The expect check func "__nf_ct_expect_check" asks the master_help is necessary. So it is unnecessary to go ahead in ctnetlink_alloc_expect when there is no help.

Quoted 6 lines

Actually the commit bc01befdcf3e ("netfilter: ctnetlink: add support for user-space expectation helpers") permits ctlink create one expect even though there is no master help. But the latter commit 3d058d7bc2c5
("netfilter: rework user-space expectation helper support") disables it again.

Quoted 3 lines

Probably reject this upfront if no nfct_help(ct) is there.

See patch attached.

Yes, it is better.
Would you apply this patch which you attached directly, or need I send another v2 update?

Best Regards
Feng

#3 lore raw
Quoted 3 lines · Gao Feng

Yes, it is better.
Would you apply this patch which you attached directly, or need I send another v2 update?

I'll apply this one. No need to send v2.