bug fixes and introducing skb_header_pointer() to ip6t_frag.c
Subsystems (2)
PATCH 1/1 bug fixes and introducing skb_header_pointer() to ip6t_frag.c
Hi,
The first patch fixes following bugs in ip6t_frag.c,
- Wrong cast the pointer to extension header.
- header length of Fragment Header is statically 8 octets. Then the option "--frag-len" doesn't make sense.
- There are endian issues where using frag->info.
- Reserved fields are not 2 bit but 8bit + 2 bit. (see RFC2460)
And the second patch enables ip6t_frag.c to work without skb_linearize().
Before trying these patches, don't forget to apply the patch which prepare to removing skb_linearize().
https://lists.netfilter.org/pipermail/netfilter-devel/2004-October/017028.html
Regards,
-----------------------------------------------------------------
Yasuyuki KOZAKAI @ USAGI Project <[email protected]>
net/ipv6/netfilter/ip6t_frag.c +37 -59
@@ -14,8 +14,6 @@#include <net/checksum.h> #include <net/ipv6.h> -#include <asm/byteorder.h> -#include <linux/netfilter_ipv6/ip6_tables.h> #include <linux/netfilter_ipv6/ip6t_frag.h>
@@ -29,29 +27,6 @@ MODULE_AUTHOR("Andras Kis-Szabo <kisza@s #define DEBUGP(format, args...)#endif -#if 0 -#if BYTE_ORDER ==BIG_ENDIAN -#define IP6F_OFF_MASK 0xfff8/* mask out offset from _offlg */ -#define IP6F_RESERVED_MASK 0x0006/* reserved bits in ip6f_offlg */ -#define IP6F_MORE_FRAG 0x0001/* more-fragments flag */ -#else /* BYTE_ORDER == LITTLE_ENDIAN */ -#define IP6F_OFF_MASK 0xf8ff/* mask out offset from _offlg */ -#define IP6F_RESERVED_MASK 0x0600/* reserved bits in ip6f_offlg */ -#define IP6F_MORE_FRAG 0x0100/* more-fragments flag */ -#endif -#endif - -#define IP6F_OFF_MASK 0xf8ff/* mask out offset from _offlg */ -#define IP6F_RESERVED_MASK 0x0600/* reserved bits in ip6f_offlg */ -#define IP6F_MORE_FRAG 0x0100/* more-fragments flag */ - -struct fraghdr { -__u8 nexthdr; -__u8 hdrlen; -__u16 info; -__u32 id; -}; -/* Returns 1 if the id is matched by the range, 0 otherwise */ static inline int id_match (u_int32_t min,u_int32_t max,u_int32_t id,int invert)
@@ -73,7 +48,7 @@ match(const struct sk_buff *skb,unsigned int protoff, int *hotdrop) { - struct fraghdr *frag = NULL; + struct frag_hdr *frag = NULL;const struct ip6t_frag *fraginfo = matchinfo;unsigned int temp;int len;
@@ -106,7 +81,7 @@ match(const struct sk_buff *skb,break ; } - hdr=(struct ipv6_opt_hdr *)skb->data+ptr; + hdr=(struct ipv6_opt_hdr *)(skb->data+ptr);/* Calculate the header length */ if (nexthdr ==NEXTHDR_FRAGMENT ) {
@@ -149,59 +124,62 @@ match(const struct sk_buff *skb,/* FRAG header not found */ if ( temp !=MASK_FRAGMENT )return 0 ; -if (len < (int )sizeof (struct fraghdr )){ +if (len <sizeof (struct frag_hdr )){ *hotdrop =1 ;return 0 ; } - frag = (struct fraghdr *) (skb->data + ptr); + frag = (struct frag_hdr *) (skb->data + ptr); -DEBUGP ("IPv6 FRAG LEN %u %u " , hdrlen, frag->hdrlen); -DEBUGP ("INFO %04X " , frag->info); -DEBUGP ("OFFSET %04X " , frag->info &IP6F_OFF_MASK ); -DEBUGP ("RES %04X " , frag->info &IP6F_RESERVED_MASK ); -DEBUGP ("MF %04X " , frag->info &IP6F_MORE_FRAG ); -DEBUGP ("ID %u %08X\n" ,ntohl (frag->id),ntohl (frag->id)); +DEBUGP ("INFO %04X " , frag->frag_off); +DEBUGP ("OFFSET %04X " ,ntohs (frag->frag_off) & ~0x7 ); +DEBUGP ("RES %02X %04X" , frag->reserved,ntohs (frag->frag_off) &0x6 ); +DEBUGP ("MF %04X " , frag->frag_off &htons (IP6_MF )); +DEBUGP ("ID %u %08X\n" ,ntohl (frag->identification), +ntohl (frag->identification));DEBUGP ("IPv6 FRAG id %02X " , (id_match (fraginfo->ids[0 ], fraginfo->ids[1 ], -ntohl (frag->id), +ntohl (frag->identification), !!(fraginfo->invflags &IP6T_FRAG_INV_IDS )))); -DEBUGP ("len %02X %04X %02X " , - fraginfo->hdrlen, hdrlen, - (!fraginfo->hdrlen || - (fraginfo->hdrlen == hdrlen) ^ - !!(fraginfo->invflags &IP6T_FRAG_INV_LEN ))); -DEBUGP ("res %02X %02X %02X " , - (fraginfo->flags &IP6T_FRAG_RES ), frag->info &IP6F_RESERVED_MASK , - !((fraginfo->flags &IP6T_FRAG_RES ) && (frag->info &IP6F_RESERVED_MASK ))); +DEBUGP ("res %02X %02X%04X %02X " , + (fraginfo->flags &IP6T_FRAG_RES ), frag->reserved, +ntohs (frag->frag_off) &0x6 , + !((fraginfo->flags &IP6T_FRAG_RES ) + && (frag->reserved || (ntohs (frag->frag_off) &0x6 ))));DEBUGP ("first %02X %02X %02X " , - (fraginfo->flags &IP6T_FRAG_FST ), frag->info &IP6F_OFF_MASK , - !((fraginfo->flags &IP6T_FRAG_FST ) && (frag->info &IP6F_OFF_MASK ))); + (fraginfo->flags &IP6T_FRAG_FST ), +ntohs (frag->frag_off) & ~0x7 , + !((fraginfo->flags &IP6T_FRAG_FST ) + && (ntohs (frag->frag_off) & ~0x7 )));DEBUGP ("mf %02X %02X %02X " , - (fraginfo->flags &IP6T_FRAG_MF ), frag->info &IP6F_MORE_FRAG , - !((fraginfo->flags &IP6T_FRAG_MF ) && !((frag->info &IP6F_MORE_FRAG )))); + (fraginfo->flags &IP6T_FRAG_MF ), +ntohs (frag->frag_off) &IP6_MF , + !((fraginfo->flags &IP6T_FRAG_MF ) + && !((ntohs (frag->frag_off) &IP6_MF ))));DEBUGP ("last %02X %02X %02X\n" , - (fraginfo->flags &IP6T_FRAG_NMF ), frag->info &IP6F_MORE_FRAG , - !((fraginfo->flags &IP6T_FRAG_NMF ) && (frag->info &IP6F_MORE_FRAG ))); + (fraginfo->flags &IP6T_FRAG_NMF ), +ntohs (frag->frag_off) &IP6_MF , + !((fraginfo->flags &IP6T_FRAG_NMF ) + && (ntohs (frag->frag_off) &IP6_MF )));return (frag !=NULL ) && (id_match (fraginfo->ids[0 ], fraginfo->ids[1 ], -ntohl (frag->id), +ntohl (frag->identification), !!(fraginfo->invflags &IP6T_FRAG_INV_IDS ))) && - (!fraginfo->hdrlen || - (fraginfo->hdrlen == hdrlen) ^ - !!(fraginfo->invflags &IP6T_FRAG_INV_LEN )) - && - !((fraginfo->flags &IP6T_FRAG_RES ) && (frag->info &IP6F_RESERVED_MASK )) + !((fraginfo->flags &IP6T_FRAG_RES ) + && (frag->reserved || (ntohs (frag->frag_off) &0x6 ))) && - !((fraginfo->flags &IP6T_FRAG_FST ) && (frag->info &IP6F_OFF_MASK )) + !((fraginfo->flags &IP6T_FRAG_FST ) + && (ntohs (frag->frag_off) & ~0x7 )) && - !((fraginfo->flags &IP6T_FRAG_MF ) && !((frag->info &IP6F_MORE_FRAG ))) + !((fraginfo->flags &IP6T_FRAG_MF ) + && !(ntohs (frag->frag_off) &IP6_MF )) && - !((fraginfo->flags &IP6T_FRAG_NMF ) && (frag->info &IP6F_MORE_FRAG )); + !((fraginfo->flags &IP6T_FRAG_NMF ) + && (ntohs (frag->frag_off) &IP6_MF )); }/* Called when user tries to insert an entry of this type. */
net/ipv6/netfilter/ip6t_frag.c +31 -29
124 lines not on this page · raw message
A message that is not in the archive (sent off-list or not yet received): [email protected]
Hi, Patrick,
From: Patrick McHardy <[email protected]>
Date: Wed, 13 Oct 2004 08:58:14 +0200
Quoted 14 lines
Quoted 12 lines · Yasuyuki Kozakai
Hi,
The first patch fixes following bugs in
ip6t_frag.c,- Wrong cast the pointer to extension header.
- header length of Fragment Header is statically 8 octets. Then the option "--frag-len" doesn't make sense.
- There are endian issues where usingfrag->info.
- Reserved fields are not 2 bit but 8bit + 2 bit. (see RFC2460)And the second patch enables
ip6t_frag.cto work withoutskb_linearize().
Quoted 8 lines
Quoted 3 lines
Before trying these patches, don't forget to apply the patch which prepare to removing
skb_linearize().Thanks Yasuyuki, your patches all look great. I've applied the prepare-to-remove-skb_linearize and
skb_header_pointerpatches to a post-2.6.9 tree and will push the fixes to Dave immediately. Just one thing, please sign off your patches next time.
Thanks a lot. Just in case...
Regards,
-----------------------------------------------------------------
Yasuyuki KOZAKAI @ USAGI Project <[email protected]>
A message that is not in the archive (sent off-list or not yet received): [email protected]
Hi, Patrick and all,
From: Yasuyuki Kozakai <[email protected]>
Date: Wed, 13 Oct 2004 16:19:27 +0900 (JST)
Quoted 2 lines
From: Patrick McHardy <[email protected]>
Date: Wed, 13 Oct 2004 08:58:14 +0200
(snip)
Quoted 4 lines
Quoted 4 lines
Thanks Yasuyuki, your patches all look great. I've applied the prepare-to-remove-skb_linearize and
skb_header_pointerpatches to a post-2.6.9 tree and will push the fixes to Dave immediately. Just one thing, please sign off your patches next time.
By the way, same fixes are needed to linux 2.4, too ? If so, I'll make patches which doesn't include skb_header_pointer(). But I wonder I can change the arguments of match/target functions in linux 2.4 so that ip6tables.c skips extension header correctly.
comments ?
-----------------------------------------------------------------
Yasuyuki KOZAKAI @ USAGI Project <[email protected]>