Skip to contentSkip to conversation

[Fwd: Re: "ip_conntrack_core: Frag of proto 17." error and memory leak?]

Fwd: Re: "ip_conntrack_core: Frag of proto 17." error and memory leak? Martin Josefsson 3 participants 3 messages Sep 20, 2003 – Sep 23, 2003 netfilter

lore
Share & tools
lore
#0 lore raw

Ok it was as I suspected.
ipt_NOTRACK calls ip_conntrack_get_tuple() which calls get_tuple() for all packets, even fragments and get_tuple() barfs and returns 0 so NOTRACK doesn't mark the packet as untracked.

The first packet of a stream of fragments will be marked as untracked and not handled by conntrack. The rest of the packets will fail in get_tuple() (it can't succeed for fragments) and nothing will be done. So conntrack gets the rest of the fragments and tries to defrag but the first packet has already passed through the machine without conntrack seeing it so the defrag will never succeed, the fragments will only consume memory until they are dropped by a timeout.

Jozsef, any ideas how to handle this?

One suggestion would be to call get_tuple() for the first packet. Lookup the tuple in conntrack, if not found mark packet as untracked. If found, don't do anything, give the packet to conntrack.

If IP_OFFSET is set this is a fragment, we can't call get_tuple() and do a lookup in conntrack since we only have the ipheader. Instead we split ip_find() in ip_fragment.c into two functions so we can do a lookup to see if the defrag is expecting this fragment or not. If it isn't expected we mark it as untracked.

But this makes the assumption that it's only conntrack that tries to defrag packets which isn't true, the ipstack does it for packets destined for the local machine. So if the first packet was destined for the local machine and was marked as untracked by NOTRACK the ipstack will try to defrag and when the rest of the fragments arrive we find that they are expected for defrag and give them to conntrack which isn't right.

A small variant of this is to still split ip_find() into two functions and if we find that the fragment is expected (either conntrack or the ipstack has seen the first packet and tries to defrag it) we simply continue the defraging on their behalf and rerun the now complete packet through ip_conntrack_tuple_taken() to see if conntrack should have it or not. This way I think everyone's happy. There will be some extra searching in the defrag-hashtable for all fragments handled by NOTRACK and one extra search in conntrack for each defragged packet. For the case where the arriving fragments are expected there will be two searches in the defrag-hashtable unless we split those things up a bit and modify them, I wonder how keen davem is on that.

/Martin

-----Forwarded Message-----
From: c0g <[email protected]>
To: Martin Josefsson <[email protected]>
Subject: Re: "ip_conntrack_core: Frag of proto 17." error and memory leak?
Date: Sat, 20 Sep 2003 21:45:06 +0200

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

| Are you using the NOTRACK target in raw/PREROUTING?

Yes I am. Policy of raw table is set to ACCEPT for all chains, and the rules are put in PREROUTING:
iptables -t raw -A PREROUTING -s ! 192.168.0.0/16 -j NOTRACK iptables -t raw -A PREROUTING -d ! 192.168.0.0/16 -j NOTRACK

Why I'm using raw table? This router doesn't need connection tracking of Internet traffic - this is being done on my next router. So I disabled it to save few bits of memory for other, cpu and memory consuming tasks.

The second use of raw patch is in FORWARD chain of filter table:
iptables -A FORWARD -m state --state UNTRACKED -j ACCEPT

| This is the only source of this I can see and it is indeed a bug. This
| message shouldn't be printed for this case. It doesn't defrag packets
| and calls get_tuple() for all packets, even the fragments and
| get_tuple() barfs. This causes only the first fragment to be marked as
| untracked and leaves the rest of the fragments to conntrack which tries
| to defrag them but that won't succeed since conntrack will never see the
| first packet. And thus the kernel keeps lots of fragments in memory
| until they time out and are dropped.
| We'll look into how to best solve this if this is what is causing the
| problem for you.

I see. This is production machine, so I can't test it too much, but I will try to help, if I can.

Greets

- --
[email protected]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQE/bK5CPqmVt5WhbA8RAmvTAJ43OhaO4/IzdK7DrzXQ/uavyLVIxgCcCt/H kW56eU4QQQAiMQn7E9FyCu4=
=yWKY
-----END PGP SIGNATURE-----

Signature · 1 line
/Martin
#1 lore raw
Quoted 2 lines · Martin Josefsson

Ok it was as I suspected.
Jozsef, any ideas how to handle this?

Please see my other mail on the subject. Unless I've missed something, removing that whole logic from ipt_NOTRACK should solve all our problems.

Quoted 1 line

/Martin

Signature · 5 lines
- Harald Welte <[email protected]>             http://www.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
In reply to Martin Josefsson
Quoted 4 lines · Martin Josefsson

Ok it was as I suspected.
ipt_NOTRACK calls ip_conntrack_get_tuple() which calls get_tuple() for all packets, even fragments and get_tuple() barfs and returns 0 so NOTRACK doesn't mark the packet as untracked.

Oh, my stupidity! I'll add the banner to the code:

/* Even when the intention was to write a code with the given
* functionality, any reseblance in the actual behavior to the
* intended one is due to pure luck.
*/

[...]

Quoted 11 lines

A small variant of this is to still split ip_find() into two functions and if we find that the fragment is expected (either conntrack or the ipstack has seen the first packet and tries to defrag it) we simply continue the defraging on their behalf and rerun the now complete packet through ip_conntrack_tuple_taken() to see if conntrack should have it or not. This way I think everyone's happy. There will be some extra searching in the defrag-hashtable for all fragments handled by NOTRACK and one extra search in conntrack for each defragged packet. For the case where the arriving fragments are expected there will be two searches in the defrag-hashtable unless we split those things up a bit and modify them, I wonder how keen davem is on that.

What about calling ip_ct_gather_frags directly in the NOTRACK target? It'd be straightforward and in the target we already depend on conntrack.

Best regards,
Jozsef
-
E-mail : [email protected], [email protected] PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : KFKI Research Institute for Particle and Nuclear Physics

          H-1525 Budapest 114, POB. 49, Hungary