netfilter: ECN target corrupts packets (2.6 only)
Subsystems (2)
PATCH 1/1 netfilter: ECN target corrupts packets (2.6 only)
Name: ipt_ECN corrupt checksum fix
Status: Tested under nfsim
Nasty bug, caught while writing the ECN target test. Corrupts checksums of packets when target is used on them.
Let this be a warning on the evils of casts.
net/ipv4/netfilter/ipt_ECN.c +1 -1
@@ -67,7 +67,7 @@if (einfo->operation &IPT_ECN_OP_SET_CWR ) th->cwr = einfo->proto.tcp.cwr; - diffs[1 ] = ((u_int16_t *)&th)[6 ]; + diffs[1 ] = ((u_int16_t *)th)[6 ];/* Only mangle if it's changed. */ if (diffs[0 ] != diffs[1 ]) {
Signature · 1 line
A bad analogy is like a leaky screwdriver -- Richard Braakman
Hello Rusty,
Quoted 8 lines · you
Name:
ipt_ECNcorrupt checksum fix
Status: Tested under nfsimSigned-off-by Rusty Russell <[email protected]>Nasty bug, caught while writing the ECN target test. Corrupts checksums of packets when target is used on them.
Let this be a warning on the evils of casts.
Heh, so that's why ECN stopped working for me :-)
I will check that out.
I did tcpdumps but for some strange reason I could not see the problem there. Maybe tcpdump got premangled packets..
Regards,
Maciej
Quoted 4 lines · Maciej Soltysiak
Quoted 4 lines
Nasty bug, caught while writing the ECN target test. Corrupts checksums of packets when target is used on them.
Quoted 10 lines
Quoted 3 lines
Let this be a warning on the evils of casts.
Heh, so that's why ECN stopped working for me :-)
I will check that out.I did tcpdumps but for some strange reason I could not see the problem there. Maybe tcpdump got premangled packets..
There's more brokeness, it mangles the tcp header before making it writable and doesn't reload pointers after doing so. This patch should fix all of it and as a side-effect avoids some useless copying. Any voluteers for testing ? :)
Regards
Patrick
===== net/ipv4/netfilter/ipt_ECN.c 1.11 vs edited =====
net/ipv4/netfilter/ipt_ECN.c +16 -19
@@ -61,31 +61,28 @@if (th ==NULL )return 0 ; - diffs[0 ] = ((u_int16_t *)th)[6 ]; -if (einfo->operation &IPT_ECN_OP_SET_ECE ) - th->ece = einfo->proto.tcp.ece; - -if (einfo->operation &IPT_ECN_OP_SET_CWR ) - th->cwr = einfo->proto.tcp.cwr; - diffs[1 ] = ((u_int16_t *)&th)[6 ]; - -/* Only mangle if it's changed. */ -if (diffs[0 ] != diffs[1 ]) { - diffs[0 ] = diffs[0 ] ^0xFFFF ; +if ((einfo->operation &IPT_ECN_OP_SET_ECE && + th->ece != einfo->proto.tcp.ece) || + (einfo->operation &IPT_ECN_OP_SET_CWR && + th->cwr != einfo->proto.tcp.cwr)) {if (!skb_ip_make_writable (pskb, (*pskb)->nh.iph->ihl*4 +sizeof (_tcph)))return 0 ; + th = (void *)(*pskb)->nh.iph + (*pskb)->nh.iph->ihl*4 ; -if (th != &_tcph) -memcpy (&_tcph, th,sizeof (_tcph)); + diffs[0 ] = ((u_int16_t *)th)[6 ]; +if (einfo->operation &IPT_ECN_OP_SET_ECE ) + th->ece = einfo->proto.tcp.ece; +if (einfo->operation &IPT_ECN_OP_SET_CWR ) + th->cwr = einfo->proto.tcp.cwr; + diffs[1 ] = ((u_int16_t *)th)[6 ]; + diffs[0 ] = diffs[0 ] ^0xFFFF ;if ((*pskb)->ip_summed !=CHECKSUM_HW ) - _tcph.check =csum_fold (csum_partial ((char *)diffs, -sizeof (diffs), - _tcph.check^0xFFFF )); -memcpy ((*pskb)->data + (*pskb)->nh.iph->ihl*4 , - &_tcph,sizeof (_tcph)); -if ((*pskb)->ip_summed ==CHECKSUM_HW ) + th->check =csum_fold (csum_partial ((char *)diffs, +sizeof (diffs), + th->check^0xFFFF )); +else if (skb_checksum_help (*pskb, inward))return 0 ; (*pskb)->nfcache |=NFC_ALTERED ;
Quoted 4 lines · Patrick McHardy
There's more brokeness, it mangles the tcp header before making it writable and doesn't reload pointers after doing so. This patch should fix all of it and as a side-effect avoids some useless copying. Any voluteers for testing ? :)
I see more nfsim work coming up...
Thanks!
Rusty.
Signature · 1 line
A bad analogy is like a leaky screwdriver -- Richard Braakman