Skip to contentSkip to conversation

fix nf_conntrack_netlink expectation dumping/event notification

PATCH In review Pablo Neira Ayuso 4 participants 21 messages Jan 13, 2006 – Feb 8, 2006 5 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/1 fix nf_conntrack_netlink expectation dumping/event notification

Hi Yasuyuki,

Currently we get an oops with nf_conntrack_netlink + nf_conntrack_ftp because l3num is set to 0xFFFF for the expectation mask. At first sight, this is correct because l3num is u_int16_t, but the size of the layer-3 array of protocol handlers is AF_MAX (32).

I could add some checking to verify that l3num is less than 32 in nf_conntrack_find_l3proto, but such checking is only required for nf_conntrack_ftp and further application helpers. AFAICS, this is the cleanest way to fix this problem. Any other suggestion?

Cheers,
Pablo

Signature · 2 lines
The dawn of the fourth age of Linux firewalling is coming; a time of
great struggle and heroic deeds -- J.Kadlecsik got inspired by J.Morris

Set l3num to 0x1F (32) in expectation masks since the size of the layer 3 procotol handler array is AF_MAX. This fixes a panic at expectation dumping and event notification.

net/netfilter/nf_conntrack_ftp.c +1 -1
Index: netfilter-2.6.14.git/net/netfilter/nf_conntrack_ftp.c
===================================================================
@@ -574,7 +574,7 @@ static int help(struct sk_buff **pskb,
 	exp->tuple.dst.protonum = IPPROTO_TCP;
 
 	exp->mask = (struct nf_conntrack_tuple)
-		    { .src = { .l3num = 0xFFFF,
+		    { .src = { .l3num = 0x001F,
 			       .u = { .tcp = { 0 }},
 			     },
 		      .dst = { .protonum = 0xFF,
#1 lore raw
Quoted 11 lines · Pablo Neira Ayuso

Hi Yasuyuki,

Currently we get an oops with nf_conntrack_netlink + nf_conntrack_ftp because l3num is set to 0xFFFF for the expectation mask. At first sight, this is correct because l3num is u_int16_t, but the size of the layer-3 array of protocol handlers is AF_MAX (32).

I could add some checking to verify that l3num is less than 32 in nf_conntrack_find_l3proto, but such checking is only required for nf_conntrack_ftp and further application helpers. AFAICS, this is the cleanest way to fix this problem. Any other suggestion?

What is the exact cause for the crash? I looked over the code, but couldn't spot it.

#2 lore raw

Hi,

From: Patrick McHardy <[email protected]>
Date: Fri, 13 Jan 2006 09:58:15 +0100

Quoted 8 lines
Quoted 7 lines · Pablo Neira Ayuso

Hi Yasuyuki,

Currently we get an oops with nf_conntrack_netlink + nf_conntrack_ftp because l3num is set to 0xFFFF for the expectation mask. At first sight, this is correct because l3num is u_int16_t, but the size of the layer-3 array of protocol handlers is AF_MAX (32).

Quoted 7 lines
Quoted 4 lines

I could add some checking to verify that l3num is less than 32 in nf_conntrack_find_l3proto, but such checking is only required for nf_conntrack_ftp and further application helpers. AFAICS, this is the cleanest way to fix this problem. Any other suggestion?

What is the exact cause for the crash? I looked over the code, but couldn't spot it.

I think that root caurse is missing check at __nf_ct_{l3}proto_find(). I'll write patch for it. It will free people from taking care about expectation mask.

Regareds,

-- Yasuyuki Kozakai

#4 lore raw
In reply to a message not in the archive
Quoted 5 lines · Yasuyuki KOZAKAI
Quoted 5 lines
Quoted 5 lines

Currently we get an oops with nf_conntrack_netlink + nf_conntrack_ftp because l3num is set to 0xFFFF for the expectation mask. At first sight, this is correct because l3num is u_int16_t, but the size of the layer-3 array of protocol handlers is AF_MAX (32).

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

I could add some checking to verify that l3num is less than 32 in nf_conntrack_find_l3proto, but such checking is only required for nf_conntrack_ftp and further application helpers. AFAICS, this is the cleanest way to fix this problem. Any other suggestion?

What is the exact cause for the crash? I looked over the code, but couldn't spot it.

Ah I see now, see the reason is right there in Pablo's mail :)

Quoted 3 lines

I think that root caurse is missing check at __nf_ct_{l3}proto_find(). I'll write patch for it. It will free people from taking care about expectation mask.

I agree, that seems to be the best solution.

#5 lore raw

From: Patrick McHardy <[email protected]>
Date: Fri, 13 Jan 2006 10:04:34 +0100

Quoted 5 lines
Quoted 3 lines

I think that root caurse is missing check at __nf_ct_{l3}proto_find(). I'll write patch for it. It will free people from taking care about expectation mask.

I agree, that seems to be the best solution.

Here you are. How about this ?

-- Yasuyuki Kozakai

[NETFILTER] nf_conntrack: check address family when finding protocol module

__nf_conntrack_{l3}proto_find() doesn't check the passed protocol family, then it's possible to touch out of the array which has only AF_MAX items.

spotted by Pablo Neira Ayuso.

---
commit 878d327ca0ca7983e3876cbdeb03679e801b637e
tree f559501a7202e5ec10106821f927460e5cc2bc11
parent 2e4e6a17af35be359cc8f1c924f8f198fbd478cc
author Yasuyuki Kozakai <[email protected]> Fri, 13 Jan 2006 18:27:38 +0900 committer Yasuyuki Kozakai <[email protected]> Fri, 13 Jan 2006 18:27:38 +0900

 include/net/netfilter/nf_conntrack_l3proto.h |   15 +++++++++------
 net/netfilter/nf_conntrack_core.c            |    2 +-
 2 files changed, 10 insertions(+), 7 deletions(-)
include/net/netfilter/nf_conntrack_l3proto.h +9 -6
index 67856eb..417d6bd 100644
@@ -88,12 +88,6 @@ extern struct nf_conntrack_l3proto *nf_c
 extern int nf_conntrack_l3proto_register(struct nf_conntrack_l3proto *proto);
 extern void nf_conntrack_l3proto_unregister(struct nf_conntrack_l3proto *proto);
 
-static inline struct nf_conntrack_l3proto *
-__nf_ct_l3proto_find(u_int16_t l3proto)
-{
-	return nf_ct_l3protos[l3proto];
-}
-
 extern struct nf_conntrack_l3proto *
 nf_ct_l3proto_find_get(u_int16_t l3proto);
 
@@ -103,4 +97,13 @@ extern void nf_ct_l3proto_put(struct nf_
 extern struct nf_conntrack_l3proto nf_conntrack_l3proto_ipv4;
 extern struct nf_conntrack_l3proto nf_conntrack_l3proto_ipv6;
 extern struct nf_conntrack_l3proto nf_conntrack_generic_l3proto;
+
+static inline struct nf_conntrack_l3proto *
+__nf_ct_l3proto_find(u_int16_t l3proto)
+{
+	if (unlikely(l3proto > AF_MAX))
+		return &nf_conntrack_generic_l3proto;
+	return nf_ct_l3protos[l3proto];
+}
+
 #endif /*_NF_CONNTRACK_L3PROTO_H*/
net/netfilter/nf_conntrack_core.c +1 -1
index 62bb509..9a147dd 100644
@@ -188,7 +188,7 @@ extern struct nf_conntrack_protocol nf_c
 struct nf_conntrack_protocol *
 __nf_ct_proto_find(u_int16_t l3proto, u_int8_t protocol)
 {
-	if (unlikely(nf_ct_protos[l3proto] == NULL))
+	if (unlikely(l3proto > AF_MAX || nf_ct_protos[l3proto] == NULL))
 		return &nf_conntrack_generic_protocol;
 
 	return nf_ct_protos[l3proto][protocol];
#7 lore raw
In reply to a message not in the archive
Quoted 4 lines · Yasuyuki KOZAKAI

From: Patrick McHardy <[email protected]>
Date: Fri, 13 Jan 2006 10:04:34 +0100

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

I think that root caurse is missing check at __nf_ct_{l3}proto_find(). I'll write patch for it. It will free people from taking care about expectation mask.

I agree, that seems to be the best solution.

Here you are. How about this ?

Thanks, looks good. Applied.

#8 lore raw

In article <[email protected]> (at Fri, 13 Jan 2006 10:45:10 +0100), Patrick McHardy <[email protected]> says:

Quoted 9 lines
Quoted 8 lines · Yasuyuki KOZAKAI

From: Patrick McHardy <[email protected]>
Date: Fri, 13 Jan 2006 10:04:34 +0100

Quoted 4 lines
Quoted 3 lines

I think that root caurse is missing check at __nf_ct_{l3}proto_find(). I'll write patch for it. It will free people from taking care about expectation mask.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

I agree, that seems to be the best solution.

Here you are. How about this ?

Thanks, looks good. Applied.

Really? ;-)

include/net/netfilter/nf_conntrack_l3proto.h +1 -1
diff -u b/include/net/netfilter/nf_conntrack_l3proto.h b/include/net/netfilter/nf_conntrack_l3proto.h
@@ -101,7 +101,7 @@
 static inline struct nf_conntrack_l3proto *
 __nf_ct_l3proto_find(u_int16_t l3proto)
 {
-	if (unlikely(l3proto > AF_MAX))
+	if (unlikely(l3proto >= AF_MAX))
 		return &nf_conntrack_generic_l3proto;
 	return nf_ct_l3protos[l3proto];
 }
net/netfilter/nf_conntrack_core.c +1 -1
diff -u b/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
@@ -188,7 +188,7 @@
 struct nf_conntrack_protocol *
 __nf_ct_proto_find(u_int16_t l3proto, u_int8_t protocol)
 {
-	if (unlikely(l3proto > AF_MAX || nf_ct_protos[l3proto] == NULL))
+	if (unlikely(l3proto >= AF_MAX || nf_ct_protos[l3proto] == NULL))
 		return &nf_conntrack_generic_protocol;
 
 	return nf_ct_protos[l3proto][protocol];
Signature · 2 lines
YOSHIFUJI Hideaki @ USAGI Project  <[email protected]>
GPG-FP  : 9022 65EB 1ECF 3AD1 0BDF  80D8 4807 F894 E062 0EEA
#9 lore raw
Quoted 4 lines · YOSHIFUJI Hideaki / $B5HF#1QL@ wrote:
Quoted 1 line

Thanks, looks good. Applied.

Really? ;-)

Thanks for noticing, I'm somehow blind this morning.

author maintainer
#11 lore raw
In reply to a message not in the archive

net/netfilter/nf_conntrack_core.c extern struct nf_conntrack_protocol nf_c · line 191

Quoted 10 lines · Yasuyuki KOZAKAI
net/netfilter/nf_conntrack_core.c +1 -1
index 62bb509..9a147dd 100644
@@ -188,7 +188,7 @@ extern struct nf_conntrack_protocol nf_c
 struct nf_conntrack_protocol *
 __nf_ct_proto_find(u_int16_t l3proto, u_int8_t protocol)
 {
-	if (unlikely(nf_ct_protos[l3proto] == NULL))
+	if (unlikely(l3proto > AF_MAX || nf_ct_protos[l3proto] == NULL))

Could the unlikely statement be bad at expectation dumping?

cheers,
Pablo

Signature · 2 lines
The dawn of the fourth age of Linux firewalling is coming; a time of
great struggle and heroic deeds -- J.Kadlecsik got inspired by J.Morris
#12 lore raw

Hi, Pablo,

From: Pablo Neira Ayuso <[email protected]>
Date: Fri, 13 Jan 2006 12:17:16 +0100

Quoted 13 lines

net/netfilter/nf_conntrack_core.c extern struct nf_conntrack_protocol nf_c · line 191

Quoted 10 lines · Yasuyuki KOZAKAI
net/netfilter/nf_conntrack_core.c +1 -1
index 62bb509..9a147dd 100644
@@ -188,7 +188,7 @@ extern struct nf_conntrack_protocol nf_c
 struct nf_conntrack_protocol *
 __nf_ct_proto_find(u_int16_t l3proto, u_int8_t protocol)
 {
-	if (unlikely(nf_ct_protos[l3proto] == NULL))
+	if (unlikely(l3proto > AF_MAX || nf_ct_protos[l3proto] == NULL))

Could the unlikely statement be bad at expectation dumping?

Indeed. But please let me think about this some more.
I feel strange to find l3proto with 0xffff as address family or to find proto with 0xff as protocol number.

After all, ctnetlink_dump_tuples() gets nf_conntrack_l3proto_generic / nf_conntrack_proto_generic and they doesn't fill any contents, right ?

If so, I think that it's better to make ctnetlink_exp_dump_expect() use l3proto/proto for &exp->tuple to dump &exp->mask, and then we would not need to remove above unlikely().

Regards,

-- Yasuyuki Kozaki

#13 lore raw

expectation mask handling in nfctnetlink (Was Re: [PATCH] fix nf_conntrack_netlink expectation dumping/event notification)

Hi, Pablo,

From: Yasuyuki KOZAKAI <[email protected]>
Date: Sun, 15 Jan 2006 22:07:39 +0900 (JST)

Quoted 9 lines

I feel strange to find l3proto with 0xffff as address family or to find proto with 0xff as protocol number.

After all, ctnetlink_dump_tuples() gets nf_conntrack_l3proto_generic / nf_conntrack_proto_generic and they doesn't fill any contents, right ?

If so, I think that it's better to make ctnetlink_exp_dump_expect() use l3proto/proto for &exp->tuple to dump &exp->mask, and then we would not need to remove above unlikely().

I've re-visited this. For now, I'm not sure this is the best solution because I don't see how format and contents of expectation mask is required by libnetfilter_conntrack. It doesn't use dumped expectation mask at all.

Then the other idea can be considerd, too. For example, dumping union of l3part(mask->u3.all) and union of proto part(mask->u.all) without assumption of specific address family/protocol. Do you have any idea on this ?

BTW, Harald, I have not read your userspace conntrack helper yet, but I think that this issue might relate to it, too.

Regards,

-- Yasuyuki Kozakai

author maintainer
#14 lore raw

Re: expectation mask handling in nfctnetlink (Was Re: [PATCH] fix nf_conntrack_netlink expectation dumping/event notification)

Hi Yasuyuki,

I'd like to recover this thread.

Quoted 6 lines · Yasuyuki KOZAKAI
Quoted 6 lines

I feel strange to find l3proto with 0xffff as address family or to find proto with 0xff as protocol number.

After all, ctnetlink_dump_tuples() gets nf_conntrack_l3proto_generic / nf_conntrack_proto_generic and they doesn't fill any contents, right ?

Quoted 8 lines
Quoted 3 lines

If so, I think that it's better to make ctnetlink_exp_dump_expect() use l3proto/proto for &exp->tuple to dump &exp->mask, and then we would not need to remove above unlikely().

I've re-visited this. For now, I'm not sure this is the best solution because I don't see how format and contents of expectation mask is required by libnetfilter_conntrack. It doesn't use dumped expectation mask at all.

Maybe userspace helpers could need that information some day. I don't want to add limitations to libnetfilter_conntrack just because we have some assumptions.

Quoted 3 lines

Then the other idea can be considerd, too. For example, dumping union of l3part(mask->u3.all) and union of proto part(mask->u.all) without assumption of specific address family/protocol. Do you have any idea on this ?

We shouldn't send the whole union via netlink. If the union is modified further, it will break backward compatibility for userspace applications since the size could change.

So, the possibilities I see up to now are:

a) just remove the unlikely() statement.
Drawback: Not so efficient, since that checking isn't always required.

b) back to my idea: set l3num to the maximum known value (0x1F), and add a bug trap in nf_ct_expect_related to check that nobody uses a value >= AF_MAX.
Drawback: People surely will hit bug while writing their own helpers.

Signature · 2 lines
The dawn of the fourth age of Linux firewalling is coming; a time of
great struggle and heroic deeds -- J.Kadlecsik got inspired by J.Morris
#15 lore raw

Re: expectation mask handling in nfctnetlink (Was Re: [PATCH] fix nf_conntrack_netlink expectation dumping/event notification)

Quoted 2 lines · Pablo Neira Ayuso

a) just remove the unlikely() statement.
Drawback: Not so efficient, since that checking isn't always required.

I'm not sure I understand the problem. Is it about the unlikely in __nf_ct_proto_find? That one is most likely not making any difference at all, since there is no code to reorder.

#25 lore raw

Re: expectation mask handling in nfctnetlink

In reply to Pablo Neira Ayuso

From: Pablo Neira Ayuso <[email protected]>
Date: Wed, 01 Feb 2006 03:09:21 +0100

Quoted 9 lines
Quoted 4 lines

I've re-visited this. For now, I'm not sure this is the best solution because I don't see how format and contents of expectation mask is required by libnetfilter_conntrack. It doesn't use dumped expectation mask at all.

Maybe userspace helpers could need that information some day. I don't want to add limitations to libnetfilter_conntrack just because we have some assumptions.

Quoted 7 lines
Quoted 3 lines

Then the other idea can be considerd, too. For example, dumping union of l3part(mask->u3.all) and union of proto part(mask->u.all) without assumption of specific address family/protocol. Do you have any idea on this ?

We shouldn't send the whole union via netlink. If the union is modified further, it will break backward compatibility for userspace applications since the size could change.

I don't think so because we can use 'len' field for that. But anyway,

Quoted 10 lines

So, the possibilities I see up to now are:

a) just remove the unlikely() statement.
Drawback: Not so efficient, since that checking isn't always required.

b) back to my idea: set l3num to the maximum known value (0x1F), and add a bug trap in nf_ct_expect_related to check that nobody uses a value >= AF_MAX.
Drawback: People surely will hit bug while writing their own helpers.

I'm fine to do a) for current nfctnetlink. Let's re-visit this when it becomes clear about format to dump expectation mask.

-- Yasuyuki Kozakai

#16 lore raw

Re: expectation mask handling in nfctnetlink

In reply to Patrick McHardy

Hi,

From: Patrick McHardy <[email protected]>
Date: Wed, 01 Feb 2006 12:04:02 +0100

Quoted 6 lines
Quoted 2 lines · Pablo Neira Ayuso

a) just remove the unlikely() statement.
Drawback: Not so efficient, since that checking isn't always required.

I'm not sure I understand the problem. Is it about the unlikely in __nf_ct_proto_find?

Yes.

Quoted 2 lines

That one is most likely not making any difference
at all, since there is no code to reorder.

Pablo pointed out ...

From: Pablo Neira Ayuso <[email protected]>
Date: Fri, 13 Jan 2006 12:17:16 +0100

Quoted 13 lines

net/netfilter/nf_conntrack_core.c extern struct nf_conntrack_protocol nf_c · line 191

Quoted 10 lines · Yasuyuki KOZAKAI
net/netfilter/nf_conntrack_core.c +1 -1
index 62bb509..9a147dd 100644
@@ -188,7 +188,7 @@ extern struct nf_conntrack_protocol nf_c
 struct nf_conntrack_protocol *
 __nf_ct_proto_find(u_int16_t l3proto, u_int8_t protocol)
 {
-	if (unlikely(nf_ct_protos[l3proto] == NULL))
+	if (unlikely(l3proto > AF_MAX || nf_ct_protos[l3proto] == NULL))

Could the unlikely statement be bad at expectation dumping?

I thought unlikely() was ok but current ctnetlink_exp_dump_expect() was strange because it trys to find proto with 0xffff as address family and 0xff as protocol number.

But I understood from Pablo's mail, that we have not decided what contents should be included in netlink message for expectation mask yet, then I agreed to remove unlikely() for now.

-- Yasuyuki Kozakai

author maintainer
#18 lore raw

RFC PATCH 1/1 Fix expectation mask dumping (Was Re: expectation mask handling in nfctnetlink)

In reply to a message not in the archive

Hi,

This patch introduces the function ctnetlink_exp_dump_mask, that correctly dumps the expectation mask. Such function uses the l3num value from the expectation tuple that is a valid layer 3 protocol number.

Besides, this modification introduces the attribute CTA_IP_L3NUM. Although the layer 3 protocol information is sent in the nfnetlink header, if the message contains information about an expectation, it will contain information about the master conntrack (just one of the tuples), the expectation tuple and the expectation mask. In this case, the value of l3num in the expectation mask is not the same that is set in the nfnetlink message. That is why we need another field that contain the value of l3num.

Now libnetfilter_conntrack can use the CTA_IP_L3NUM attribute, but if this attribute is not present in the message, it can use the information available in the nfnetlink header message.

comments?

cheers,
Pablo

Signature · 2 lines
The dawn of the fourth age of Linux firewalling is coming; a time of
great struggle and heroic deeds -- J.Kadlecsik got inspired by J.Morris

[RFC][CTNETLINK] Fix expectaction mask dumping

The expectation mask has some particularities that make handle in a different way. The protocol number fields can be set to non-valid protocols, ie. l3num is set to 0xFFFF. Since that protocol does not exist, the mask tuple will not be dumped. Moreover, this results in a kernel panic when nf_conntrack accesses the array of protocol handlers, that is PF_MAX (0x1F) long.

This patch introduces the function ctnetlink_exp_dump_mask, that correctly dumps the expectation mask. Such function uses the l3num value from the expectation tuple that is a valid layer 3 protocol number.

Besides, this modification introduces the attribute CTA_IP_L3NUM. Although the layer 3 protocol information is sent in the nfnetlink header, if the message contains information about an expectation, it will contain information about the master conntrack (just one of the tuples), the expectation tuple and the expectation mask. In this case, the value of l3num in the expectation mask is not the same that is set in the nfnetlink message. That is why we need another field that contain the value of l3num.

net/netfilter/nf_conntrack_netlink.c +55 -21
Index: net-2.6.git/net/netfilter/nf_conntrack_netlink.c
===================================================================
@@ -55,20 +55,18 @@ static char __initdata version[] = "0.92
 
 static inline int
 ctnetlink_dump_tuples_proto(struct sk_buff *skb, 
-			    const struct nf_conntrack_tuple *tuple)
+			    const struct nf_conntrack_tuple *tuple,
+			    struct nf_conntrack_protocol *proto)
 {
-	struct nf_conntrack_protocol *proto;
 	int ret = 0;
+	struct nfattr *nest_parms = NFA_NEST(skb, CTA_TUPLE_PROTO);
 
 	NFA_PUT(skb, CTA_PROTO_NUM, sizeof(u_int8_t), &tuple->dst.protonum);
 
-	/* If no protocol helper is found, this function will return the
-	 * generic protocol helper, so proto won't *ever* be NULL */
-	proto = nf_ct_proto_find_get(tuple->src.l3num, tuple->dst.protonum);
 	if (likely(proto->tuple_to_nfattr))
 		ret = proto->tuple_to_nfattr(skb, tuple);
 	
-	nf_ct_proto_put(proto);
+	NFA_NEST_END(skb, nest_parms);	
 
 	return ret;
 
@@ -77,33 +75,46 @@ nfattr_failure:
 }
 
 static inline int
-ctnetlink_dump_tuples(struct sk_buff *skb, 
-		      const struct nf_conntrack_tuple *tuple)
+ctnetlink_dump_tuples_ip(struct sk_buff *skb,
+			 const struct nf_conntrack_tuple *tuple,
+			 struct nf_conntrack_l3proto *l3proto)
 {
-	struct nfattr *nest_parms;
-	struct nf_conntrack_l3proto *l3proto;
 	int ret = 0;
-	
-	l3proto = nf_ct_l3proto_find_get(tuple->src.l3num);
-	
-	nest_parms = NFA_NEST(skb, CTA_TUPLE_IP);
+	struct nfattr *nest_parms = NFA_NEST(skb, CTA_TUPLE_IP);
+
+	NFA_PUT(skb, CTA_IP_L3NUM, sizeof(u_int16_t), &tuple->src.l3num);
+
 	if (likely(l3proto->tuple_to_nfattr))
 		ret = l3proto->tuple_to_nfattr(skb, tuple);
+
 	NFA_NEST_END(skb, nest_parms);
 
+	return ret;
+
+nfattr_failure:
+	return -1;
+}
+
+static inline int
+ctnetlink_dump_tuples(struct sk_buff *skb, 
+		      const struct nf_conntrack_tuple *tuple)
+{
+	int ret = 0;
+	struct nf_conntrack_l3proto *l3proto;
+	struct nf_conntrack_protocol *proto;
+
+	l3proto = nf_ct_l3proto_find_get(tuple->src.l3num);
+	ret = ctnetlink_dump_tuples_ip(skb, tuple, l3proto);
 	nf_ct_l3proto_put(l3proto);
 
 	if (unlikely(ret < 0))
 		return ret;
 
-	nest_parms = NFA_NEST(skb, CTA_TUPLE_PROTO);
-	ret = ctnetlink_dump_tuples_proto(skb, tuple);
-	NFA_NEST_END(skb, nest_parms);
+	proto = nf_ct_proto_find_get(tuple->src.l3num, tuple->dst.protonum);
+	ret = ctnetlink_dump_tuples_proto(skb, tuple, proto);
+	nf_ct_proto_put(proto);
 
 	return ret;
-
-nfattr_failure:
-	return -1;
 }
 
 static inline int
@@ -1150,6 +1161,29 @@ nfattr_failure:
 }			
 
 static inline int
+ctnetlink_exp_dump_mask(struct sk_buff *skb, 
+			const struct nf_conntrack_tuple *tuple,
+			const struct nf_conntrack_tuple *mask)
+{
+	int ret = 0;
+	struct nf_conntrack_l3proto *l3proto;
+	struct nf_conntrack_protocol *proto;
+
+	l3proto = nf_ct_l3proto_find_get(tuple->src.l3num);
+	ret = ctnetlink_dump_tuples_ip(skb, mask, l3proto);
+	nf_ct_l3proto_put(l3proto);
+
+	if (unlikely(ret < 0))
+		return ret;
+
+	proto = nf_ct_proto_find_get(tuple->src.l3num, tuple->dst.protonum);
+	ret = ctnetlink_dump_tuples_proto(skb, mask, proto);
+	nf_ct_proto_put(proto);
+
+	return ret;
+}
+
+static inline int
 ctnetlink_exp_dump_expect(struct sk_buff *skb,
                           const struct nf_conntrack_expect *exp)
 {
@@ -1159,7 +1193,7 @@ ctnetlink_exp_dump_expect(struct sk_buff
 
 	if (ctnetlink_exp_dump_tuple(skb, &exp->tuple, CTA_EXPECT_TUPLE) < 0)
 		goto nfattr_failure;
-	if (ctnetlink_exp_dump_tuple(skb, &exp->mask, CTA_EXPECT_MASK) < 0)
+	if (ctnetlink_exp_dump_mask(skb, &exp->tuple, &exp->mask) < 0)
 		goto nfattr_failure;
 	if (ctnetlink_exp_dump_tuple(skb,
 				 &master->tuplehash[IP_CT_DIR_ORIGINAL].tuple,
include/linux/netfilter/nfnetlink_conntrack.h +1 -0
Index: net-2.6.git/include/linux/netfilter/nfnetlink_conntrack.h
===================================================================
@@ -52,6 +52,7 @@ enum ctattr_ip {
 	CTA_IP_V4_DST,
 	CTA_IP_V6_SRC,
 	CTA_IP_V6_DST,
+	CTA_IP_L3NUM,
 	__CTA_IP_MAX
 };
 #define CTA_IP_MAX (__CTA_IP_MAX - 1)
#19 lore raw

Re: [RFC] [PATCH] Fix expectation mask dumping

Hi, Pablo,

From: Pablo Neira Ayuso <[email protected]>
Date: Thu, 02 Feb 2006 01:45:09 +0100

Quoted 15 lines

Hi,

This patch introduces the function ctnetlink_exp_dump_mask, that correctly dumps the expectation mask. Such function uses the l3num value from the expectation tuple that is a valid layer 3 protocol number.

Besides, this modification introduces the attribute CTA_IP_L3NUM. Although the layer 3 protocol information is sent in the nfnetlink header, if the message contains information about an expectation, it will contain information about the master conntrack (just one of the tuples), the expectation tuple and the expectation mask. In this case, the value of l3num in the expectation mask is not the same that is set in the nfnetlink message. That is why we need another field that contain the value of l3num.

Quoted 5 lines

Now libnetfilter_conntrack can use the CTA_IP_L3NUM attribute, but if this attribute is not present in the message, it can use the information available in the nfnetlink header message.

comments?

sounds good idea.

Quoted 7 lines

static inline int

net/netfilter/nf_conntrack_netlink.c +3 -2
-ctnetlink_dump_tuples(struct sk_buff *skb, 
-		      const struct nf_conntrack_tuple *tuple)
+ctnetlink_dump_tuples_ip(struct sk_buff *skb,
+			 const struct nf_conntrack_tuple *tuple,
+			 struct nf_conntrack_l3proto *l3proto)
 {

net/netfilter/nf_conntrack_netlink.c nfattr_failure: · line 85

Quoted 10 lines
net/netfilter/nf_conntrack_netlink.c +3 -6
-	struct nfattr *nest_parms;
-	struct nf_conntrack_l3proto *l3proto;
 	int ret = 0;
-	
-	l3proto = nf_ct_l3proto_find_get(tuple->src.l3num);
-	
-	nest_parms = NFA_NEST(skb, CTA_TUPLE_IP);
+	struct nfattr *nest_parms = NFA_NEST(skb, CTA_TUPLE_IP);
+
+	NFA_PUT(skb, CTA_IP_L3NUM, sizeof(u_int16_t), &tuple->src.l3num);

Well, I think that 8bits are enough. It seems that it's time to change 'l3num' field in tuple to 8bits to avoid confusing.

If everyone has no objection, please just change this to 8bits, then I'll write a patch to do that on top of your patch.

-- Yasuyuki Kozakai

author maintainer
#20 lore raw

PATCH 1/1 Fix expectation mask dumping, take #2

In reply to Pablo Neira Ayuso

Hi,

@Patrick: this patch fixes the problem that `[NETFILTER 03/14]:
nf_conntrack: check address family when finding protocol module` works around. So I think that such patch needs to be reverted :(

Description:

This patch introduces the function ctnetlink_exp_dump_mask, that correctly dumps the expectation mask. Such function uses the l3num value from the expectation tuple that is a valid layer 3 protocol number.

Besides, this modification introduces the attribute CTA_IP_L3NUM. Although the layer 3 protocol information is sent in the nfnetlink header, if the message contains information about an expectation, it will contain information about the master conntrack (just one of the tuples), the expectation tuple and the expectation mask. In this case, the value of l3num in the expectation mask is not the same that is set in the nfnetlink message. That is why we need another field that contain the value of l3num.

Now libnetfilter_conntrack can use the CTA_IP_L3NUM attribute, but if this attribute is not present in the message, it can use the information available in the nfnetlink header message.

Signature · 2 lines
The dawn of the fourth age of Linux firewalling is coming; a time of
great struggle and heroic deeds -- J.Kadlecsik got inspired by J.Morris

[CTNETLINK] Fix expectaction mask dumping

The expectation mask has some particularities that make handle in a different way. The protocol number fields can be set to non-valid protocols, ie. l3num is set to 0xFFFF. Since that protocol does not exist, the mask tuple will not be dumped. Moreover, this results in a kernel panic when nf_conntrack accesses the array of protocol handlers, that is PF_MAX (0x1F) long.

This patch introduces the function ctnetlink_exp_dump_mask, that correctly dumps the expectation mask. Such function uses the l3num value from the expectation tuple that is a valid layer 3 protocol number.

Besides, this modification introduces the attribute CTA_IP_L3NUM. Although the layer 3 protocol information is sent in the nfnetlink header, if the message contains information about an expectation, it will contain information about the master conntrack (just one of the tuples), the expectation tuple and the expectation mask. In this case, the value of l3num in the expectation mask is not the same that is set in the nfnetlink message. That is why we need another field that contain the value of l3num.

net/netfilter/nf_conntrack_netlink.c +56 -22
Index: net-2.6.git/net/netfilter/nf_conntrack_netlink.c
===================================================================
@@ -4,7 +4,7 @@
  * (C) 2001 by Jay Schulist <[email protected]>
  * (C) 2002-2005 by Harald Welte <[email protected]>
  * (C) 2003 by Patrick Mchardy <[email protected]>
- * (C) 2005 by Pablo Neira Ayuso <[email protected]>
+ * (C) 2005-2006 by Pablo Neira Ayuso <[email protected]>
  *
  * I've reworked this stuff to use attributes instead of conntrack 
  * structures. 5.44 am. I need more tea. --pablo 05/07/11.
@@ -55,20 +55,18 @@ static char __initdata version[] = "0.92
 
 static inline int
 ctnetlink_dump_tuples_proto(struct sk_buff *skb, 
-			    const struct nf_conntrack_tuple *tuple)
+			    const struct nf_conntrack_tuple *tuple,
+			    struct nf_conntrack_protocol *proto)
 {
-	struct nf_conntrack_protocol *proto;
 	int ret = 0;
+	struct nfattr *nest_parms = NFA_NEST(skb, CTA_TUPLE_PROTO);
 
 	NFA_PUT(skb, CTA_PROTO_NUM, sizeof(u_int8_t), &tuple->dst.protonum);
 
-	/* If no protocol helper is found, this function will return the
-	 * generic protocol helper, so proto won't *ever* be NULL */
-	proto = nf_ct_proto_find_get(tuple->src.l3num, tuple->dst.protonum);
 	if (likely(proto->tuple_to_nfattr))
 		ret = proto->tuple_to_nfattr(skb, tuple);
 	
-	nf_ct_proto_put(proto);
+	NFA_NEST_END(skb, nest_parms);	
 
 	return ret;
 
@@ -77,33 +75,46 @@ nfattr_failure:
 }
 
 static inline int
-ctnetlink_dump_tuples(struct sk_buff *skb, 
-		      const struct nf_conntrack_tuple *tuple)
+ctnetlink_dump_tuples_ip(struct sk_buff *skb,
+			 const struct nf_conntrack_tuple *tuple,
+			 struct nf_conntrack_l3proto *l3proto)
 {
-	struct nfattr *nest_parms;
-	struct nf_conntrack_l3proto *l3proto;
 	int ret = 0;
-	
-	l3proto = nf_ct_l3proto_find_get(tuple->src.l3num);
-	
-	nest_parms = NFA_NEST(skb, CTA_TUPLE_IP);
+	struct nfattr *nest_parms = NFA_NEST(skb, CTA_TUPLE_IP);
+
+	NFA_PUT(skb, CTA_IP_L3NUM, sizeof(u_int8_t), &tuple->src.l3num);
+
 	if (likely(l3proto->tuple_to_nfattr))
 		ret = l3proto->tuple_to_nfattr(skb, tuple);
+
 	NFA_NEST_END(skb, nest_parms);
 
+	return ret;
+
+nfattr_failure:
+	return -1;
+}
+
+static inline int
+ctnetlink_dump_tuples(struct sk_buff *skb, 
+		      const struct nf_conntrack_tuple *tuple)
+{
+	int ret;
+	struct nf_conntrack_l3proto *l3proto;
+	struct nf_conntrack_protocol *proto;
+
+	l3proto = nf_ct_l3proto_find_get(tuple->src.l3num);
+	ret = ctnetlink_dump_tuples_ip(skb, tuple, l3proto);
 	nf_ct_l3proto_put(l3proto);
 
 	if (unlikely(ret < 0))
 		return ret;
 
-	nest_parms = NFA_NEST(skb, CTA_TUPLE_PROTO);
-	ret = ctnetlink_dump_tuples_proto(skb, tuple);
-	NFA_NEST_END(skb, nest_parms);
+	proto = nf_ct_proto_find_get(tuple->src.l3num, tuple->dst.protonum);
+	ret = ctnetlink_dump_tuples_proto(skb, tuple, proto);
+	nf_ct_proto_put(proto);
 
 	return ret;
-
-nfattr_failure:
-	return -1;
 }
 
 static inline int
@@ -1150,6 +1161,29 @@ nfattr_failure:
 }			
 
 static inline int
+ctnetlink_exp_dump_mask(struct sk_buff *skb, 
+			const struct nf_conntrack_tuple *tuple,
+			const struct nf_conntrack_tuple *mask)
+{
+	int ret;
+	struct nf_conntrack_l3proto *l3proto;
+	struct nf_conntrack_protocol *proto;
+
+	l3proto = nf_ct_l3proto_find_get(tuple->src.l3num);
+	ret = ctnetlink_dump_tuples_ip(skb, mask, l3proto);
+	nf_ct_l3proto_put(l3proto);
+
+	if (unlikely(ret < 0))
+		return ret;
+
+	proto = nf_ct_proto_find_get(tuple->src.l3num, tuple->dst.protonum);
+	ret = ctnetlink_dump_tuples_proto(skb, mask, proto);
+	nf_ct_proto_put(proto);
+
+	return ret;
+}
+
+static inline int
 ctnetlink_exp_dump_expect(struct sk_buff *skb,
                           const struct nf_conntrack_expect *exp)
 {
@@ -1159,7 +1193,7 @@ ctnetlink_exp_dump_expect(struct sk_buff
 
 	if (ctnetlink_exp_dump_tuple(skb, &exp->tuple, CTA_EXPECT_TUPLE) < 0)
 		goto nfattr_failure;
-	if (ctnetlink_exp_dump_tuple(skb, &exp->mask, CTA_EXPECT_MASK) < 0)
+	if (ctnetlink_exp_dump_mask(skb, &exp->tuple, &exp->mask) < 0)
 		goto nfattr_failure;
 	if (ctnetlink_exp_dump_tuple(skb,
 				 &master->tuplehash[IP_CT_DIR_ORIGINAL].tuple,
include/linux/netfilter/nfnetlink_conntrack.h +1 -0
Index: net-2.6.git/include/linux/netfilter/nfnetlink_conntrack.h
===================================================================
@@ -52,6 +52,7 @@ enum ctattr_ip {
 	CTA_IP_V4_DST,
 	CTA_IP_V6_SRC,
 	CTA_IP_V6_DST,
+	CTA_IP_L3NUM,
 	__CTA_IP_MAX
 };
 #define CTA_IP_MAX (__CTA_IP_MAX - 1)
net/ipv4/netfilter/ip_conntrack_netlink.c +47 -17

115 lines not on this page · raw message

#21 lore raw

Re: [PATCH] Fix expectation mask dumping, take #2

Hi, Pablo,

From: Pablo Neira Ayuso <[email protected]>
Date: Mon, 06 Feb 2006 00:54:54 +0100

Quoted 5 lines

Hi,

@Patrick: this patch fixes the problem that `[NETFILTER 03/14]:
nf_conntrack: check address family when finding protocol module` works around. So I think that such patch needs to be reverted :(

Please don't revert that. I've been thinking that both your and his patch are necessary. Even if your patch fixes oops triggered by nfctnetlink, other module might have same problem future.

I think he aim of 2 patches is different. His patch fixes the root of oops. Your patch fixes dumping expectation mask.

BTW, ah, his patch includes unlikely(). But fortunately, your patch looks that it makes unnecessary to remove it and I expect that it will be applied to net-2.6 tree. Great!

-- Yasuyuki Kozakai

#22 lore raw

Re: [PATCH] Fix expectation mask dumping, take #2

In reply to Pablo Neira Ayuso

Hi, Pablo,

From: Pablo Neira Ayuso <[email protected]>
Date: Mon, 06 Feb 2006 00:54:54 +0100

Quoted 15 lines

Description:

This patch introduces the function ctnetlink_exp_dump_mask, that correctly dumps the expectation mask. Such function uses the l3num value from the expectation tuple that is a valid layer 3 protocol number.

Besides, this modification introduces the attribute CTA_IP_L3NUM. Although the layer 3 protocol information is sent in the nfnetlink header, if the message contains information about an expectation, it will contain information about the master conntrack (just one of the tuples), the expectation tuple and the expectation mask. In this case, the value of l3num in the expectation mask is not the same that is set in the nfnetlink message. That is why we need another field that contain the value of l3num.

Quoted 3 lines

Now libnetfilter_conntrack can use the CTA_IP_L3NUM attribute, but if this attribute is not present in the message, it can use the information available in the nfnetlink header message.

Thanks for changing size of CTA_IP_L3NUM field. But it seems to have endian problem. This patch can save your time ?

Other parts are fine to me.

Regards,

-- Yasuyuki Kozakai

net/netfilter/nf_conntrack_netlink.c +2 -1
index ee814e1..150174f 100644
@@ -81,8 +81,9 @@ ctnetlink_dump_tuples_ip(struct sk_buff 
 {
 	int ret = 0;
 	struct nfattr *nest_parms = NFA_NEST(skb, CTA_TUPLE_IP);
+	u_int8_t l3num = (u_int8_t)tuple->src.l3num;
 
-	NFA_PUT(skb, CTA_IP_L3NUM, sizeof(u_int8_t), &tuple->src.l3num);
+	NFA_PUT(skb, CTA_IP_L3NUM, sizeof(u_int8_t), &l3num);
 
 	if (likely(l3proto->tuple_to_nfattr))
 		ret = l3proto->tuple_to_nfattr(skb, tuple);
author maintainer
#24 lore raw

Re: [PATCH] Fix expectation mask dumping, take #2

In reply to a message not in the archive
Quoted 10 lines · Yasuyuki KOZAKAI

Thanks for changing size of CTA_IP_L3NUM field. But it seems to have endian problem. This patch can save your time ?

------------------------------------------------------------------------

net/netfilter/nf_conntrack_netlink.c +0 -0
index ee814e1..150174f 100644

net/netfilter/nf_conntrack_netlink.c ctnetlink_dump_tuples_ip(struct sk_buff · line 89

Quoted 10 lines
net/netfilter/nf_conntrack_netlink.c +2 -1
@@ -81,8 +81,9 @@ ctnetlink_dump_tuples_ip(struct sk_buff 
 {
 	int ret = 0;
 	struct nfattr *nest_parms = NFA_NEST(skb, CTA_TUPLE_IP);
+	u_int8_t l3num = (u_int8_t)tuple->src.l3num;
 
-	NFA_PUT(skb, CTA_IP_L3NUM, sizeof(u_int8_t), &tuple->src.l3num);
+	NFA_PUT(skb, CTA_IP_L3NUM, sizeof(u_int8_t), &l3num);
 
 	if (likely(l3proto->tuple_to_nfattr))
 		ret = l3proto->tuple_to_nfattr(skb, tuple);

Oops, I understood in your previous email that you were going to send a patch that changes the type of l3num from u_int16_t to u_int8_t. In that case I'll resend a patch with this change. Thanks

Signature · 2 lines
The dawn of the fourth age of Linux firewalling is coming; a time of
great struggle and heroic deeds -- J.Kadlecsik got inspired by J.Morris