Skip to contentSkip to conversation

fix leak of fragment queue at unloading nf_conntrack_ipv6

PATCH Harald Welte 2 participants 6 messages Nov 13, 2005 3 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 4 lines · Yasuyuki KOZAKAI

This makes nf_conntrack_ipv6 free all IPv6 fragment queues at unloading. This also check inconsistency between memory tracking and actual usage to avoid endless loop at eviction.

I'm fine with this, but:

Review

Quoted 7 lines
(quoted diff) +6 -0
 		tmp = nf_ct_frag6_lru_list.next;
+		if (tmp == NULL) {
+			if (net_ratelimit())
+				printk(KERN_ERR
+				       "nf_ct_reasm: no queue to be evicted");
+			return;
+		}

Why is it an error if we don't have a defrag queue at unloading time? Isn't it possible that we never process any fragments (or finished processing of all fragments some time ago) and thus have an empty queue?

If I understand this correctly, it should be a DEBUG message, at most.

Please comment.

Signature · 5 lines
- Harald Welte <[email protected]>                 http://netfilter.org/
============================================================================
  "Fragmentation is like classful addressing -- an interesting early
   architectural error that shows how much experimentation was going
   on while IP was being designed."                    -- Paul Vixie
#2 lore raw

From: Harald Welte <[email protected]>
Date: Sun, 13 Nov 2005 11:08:37 +0100

Quoted 8 lines · Yasuyuki KOZAKAI
Quoted 4 lines

This makes nf_conntrack_ipv6 free all IPv6 fragment queues at unloading. This also check inconsistency between memory tracking and actual usage to avoid endless loop at eviction.

I'm fine with this, but:

Quoted 11 lines

Review

Quoted 7 lines
(quoted diff) +6 -0
 		tmp = nf_ct_frag6_lru_list.next;
+		if (tmp == NULL) {
+			if (net_ratelimit())
+				printk(KERN_ERR
+				       "nf_ct_reasm: no queue to be evicted");
+			return;
+		}

Why is it an error if we don't have a defrag queue at unloading time? Isn't it possible that we never process any fragments (or finished processing of all fragments some time ago) and thus have an empty queue?

Sorry for short explanation. This function may be called when memory usage exceeds threshold. And I just want to be noticed existence of bug in memory tracking and avoid NULL pointer access.

Quoted 1 line

If I understand this correctly, it should be a DEBUG message, at most.

OK.

Quoted 1 line

Please comment.

Is it overly cautions to avoid NULL pointer access in this case ? Indeed we can notice bug early if we doesn't introduce this check.

-- Yasuyuki kozakai

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw
Quoted 24 lines · Yasuyuki KOZAKAI

From: Harald Welte <[email protected]>
Date: Sun, 13 Nov 2005 11:08:37 +0100

Quoted 8 lines · Yasuyuki KOZAKAI
Quoted 4 lines

This makes nf_conntrack_ipv6 free all IPv6 fragment queues at unloading. This also check inconsistency between memory tracking and actual usage to avoid endless loop at eviction.

I'm fine with this, but:

Quoted 11 lines

Review

Quoted 7 lines
(quoted diff) +6 -0
 		tmp = nf_ct_frag6_lru_list.next;
+		if (tmp == NULL) {
+			if (net_ratelimit())
+				printk(KERN_ERR
+				       "nf_ct_reasm: no queue to be evicted");
+			return;
+		}

Why is it an error if we don't have a defrag queue at unloading time? Isn't it possible that we never process any fragments (or finished processing of all fragments some time ago) and thus have an empty queue?

Quoted 3 lines

Sorry for short explanation. This function may be called when memory usage exceeds threshold. And I just want to be noticed existence of bug in memory tracking and avoid NULL pointer access.

ok, in this case I think the error message should be more verbose.

Quoted 3 lines
Quoted 1 line

Please comment.

Is it overly cautions to avoid NULL pointer access in this case ?

I'd have to study the code in more detail. It depends on the question:
Under which circumstances can we have a NULL pointer?

Quoted 1 line

Indeed we can notice bug early if we doesn't introduce this check.

Please explain.

Signature · 5 lines
- Harald Welte <[email protected]>                 http://netfilter.org/
============================================================================
  "Fragmentation is like classful addressing -- an interesting early
   architectural error that shows how much experimentation was going
   on while IP was being designed."                    -- Paul Vixie
#5 lore raw
Quoted 4 lines · Harald Welte
Quoted 3 lines

Sorry for short explanation. This function may be called when memory usage exceeds threshold. And I just want to be noticed existence of bug in memory tracking and avoid NULL pointer access.

Quoted 8 lines

ok, in this case I think the error message should be more verbose.

Quoted 3 lines
Quoted 1 line

Please comment.

Is it overly cautions to avoid NULL pointer access in this case ?

I'd have to study the code in more detail. It depends on the question:
Under which circumstances can we have a NULL pointer?

After looking at the code, this function is only called from
1) module unload time

Here it is clear, that there are valid cases where we would have a NULL pointer (empty fraq queue). Let's assume we've never even processed a single fragment [or even not a single ipv6 packet], e.g.

So in this case, it is a bug to print a KERN_ERR message.

2) when the amount of memory used by the defrag code is higher than the threshold

In this case, there's actually a bug in the memory usage accounting code. Do you suspect any such errors at the moment? I think this is a candidate for an ASSERT, or maybe even better a BUG_ON().

We're talking about a condition that should never happen, and if it does, we want to make sure to have users report it and fix it fast. If the kernel oopses, that condition is fulfilled ;)

So unless I'm missing some point (I'm not as familiar with the code as you), I'd suggest that you resubmit the patch with a BUG_ON(tmp == NULL) statement.

Thanks!

Signature · 5 lines
- Harald Welte <[email protected]>                 http://netfilter.org/
============================================================================
  "Fragmentation is like classful addressing -- an interesting early
   architectural error that shows how much experimentation was going
   on while IP was being designed."                    -- Paul Vixie
#6 lore raw

From: Harald Welte <[email protected]>
Date: Sun, 13 Nov 2005 14:03:34 +0100

Quoted 14 lines · Harald Welte
Quoted 4 lines
Quoted 3 lines

Sorry for short explanation. This function may be called when memory usage exceeds threshold. And I just want to be noticed existence of bug in memory tracking and avoid NULL pointer access.

Quoted 8 lines

ok, in this case I think the error message should be more verbose.

Quoted 3 lines
Quoted 1 line

Please comment.

Is it overly cautions to avoid NULL pointer access in this case ?

I'd have to study the code in more detail. It depends on the question:
Under which circumstances can we have a NULL pointer?

Quoted 6 lines

After looking at the code, this function is only called from
1) module unload time

Here it is clear, that there are valid cases where we would have a NULL pointer (empty fraq queue). Let's assume we've never even processed a single fragment [or even not a single ipv6 packet], e.g.

That's right.

Quoted 1 line

So in this case, it is a bug to print a KERN_ERR message.

OK.

Quoted 5 lines

2) when the amount of memory used by the defrag code is higher than the threshold

In this case, there's actually a bug in the memory usage accounting code. Do you suspect any such errors at the moment?

No, in the current ;) But nf_conntrack_reasm.c is newer than other part and I can not deny possibility.

Quoted 6 lines

I think this is a
candidate for an ASSERT, or maybe even better a BUG_ON().

We're talking about a condition that should never happen, and if it does, we want to make sure to have users report it and fix it fast. If the kernel oopses, that condition is fulfilled ;)

Yes.

Quoted 3 lines

So unless I'm missing some point (I'm not as familiar with the code as you), I'd suggest that you resubmit the patch with a BUG_ON(tmp == NULL) statement.

I totally agree. I attached new one.

Regards,

-- Yasuyuki Kozakai

[NETFILTER] fix leak of fragment queue at unloading nf_conntrack_ipv6

This makes nf_conntrack_ipv6 free all IPv6 fragment queues at unloading. This also check NULL pointer access due to bug of memory accounting. Thanks to Harald Welte for suggestion.

---
commit 753e55677dcce0ce44db7faab2dd175e185dd28d
tree f6ca90f3d756cd0ea827248be93de8b49f666ab2
parent 56fef247fc7259d0e554517c8c05d0e9c7b4619b
author Yasuyuki Kozakai <[email protected]> Sun, 13 Nov 2005 22:47:32 +0900 committer Yasuyuki Kozakai <[email protected]> Sun, 13 Nov 2005 22:47:32 +0900

 net/ipv6/netfilter/nf_conntrack_reasm.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
net/ipv6/netfilter/nf_conntrack_reasm.c +2 -0
index 2d0c49e..3e31903 100644
@@ -269,6 +269,7 @@ static void nf_ct_frag6_evictor(void)
 			return;
 		}
 		tmp = nf_ct_frag6_lru_list.next;
+		BUG_ON(tmp == NULL);
 		fq = list_entry(tmp, struct nf_ct_frag6_queue, lru_list);
 		atomic_inc(&fq->refcnt);
 		read_unlock(&nf_ct_frag6_lock);
@@ -878,5 +879,6 @@ int nf_ct_frag6_init(void)
 void nf_ct_frag6_cleanup(void)
 {
 	del_timer(&nf_ct_frag6_secret_timer);
+	nf_ct_frag6_low_thresh = 0;
 	nf_ct_frag6_evictor();
 }

A message that is not in the archive (sent off-list or not yet received): [email protected]

author Applied
#8 lore raw
Quoted 1 line · Yasuyuki KOZAKAI

I totally agree. I attached new one.

applied, thanks.

Signature · 5 lines
- Harald Welte <[email protected]>                 http://netfilter.org/
============================================================================
  "Fragmentation is like classful addressing -- an interesting early
   architectural error that shows how much experimentation was going
   on while IP was being designed."                    -- Paul Vixie