Add bridged IPv6 packet filtering
Subsystems (4)
PATCH 1/1 Add bridged IPv6 packet filtering
Hi Dave,
From reading Yasuyuki's reply and the specific code, the IPv6 checks before giving a bridged packet to ip6tables should now be accurate.
These are the changes made to the original patch:
- * Aug 28 2004: add IPv6 filtering (bdschuym)
+ * Sep 01 2004: add IPv6 filtering (bdschuym)
@@ -321,11 +321,12 @@ static unsigned int br_nf_pre_routing_ip
goto inhdr_error;
}
if (hdr->nexthdr == NEXTHDR_HOP) {
- skb->h.raw = (u8*)(hdr+1);
-#if 0
- if (ipv6_parse_hopopts(skb, offsetof(struct ipv6hdr, nexthdr))<0)
+ /* We only check the length. A bridge shouldn't do any
+ * hop-by-hop stuff anyway. */
+ unsigned char *raw = (u8*)(skb->nh.ipv6h+1);
+
+ if ((raw + ((int)(raw[1]+1)<<3)) - skb->data > skb_headlen(skb))
goto inhdr_error;
-#endif
As the change to the original patch is minimal and the original patch has been tested, I suggest applying the patch below.
cheers,
Bart
include/linux/netfilter_ipv6.h renamed from include/linux/netfilter_ipv6.h.old +2 -0
@@ -58,8 +58,10 @@ enum nf_ip6_hook_priorities {NF_IP6_PRI_FIRST =INT_MIN ,NF_IP6_PRI_SELINUX_FIRST =-225 ,NF_IP6_PRI_CONNTRACK =-200 , +NF_IP6_PRI_BRIDGE_SABOTAGE_FORWARD =-175 ,NF_IP6_PRI_MANGLE =-150 ,NF_IP6_PRI_NAT_DST =-100 , +NF_IP6_PRI_BRIDGE_SABOTAGE_LOCAL_OUT =-50 ,NF_IP6_PRI_FILTER =0 ,NF_IP6_PRI_NAT_SRC =100 , NF_IP6_PRI_SELINUX_LAST = 225,
net/bridge/br_netfilter.c renamed from net/bridge/br_netfilter.c.old +257 -126
654 lines not on this page · raw message
Documentation/networking/ip-sysctl.txt renamed from Documentation/networking/ip-sysctl.txt.old +5 -0
@@ -837,6 +837,11 @@ bridge-nf-call-iptables - BOOLEAN 0 : disable this. Default: 1 +bridge-nf-call-ip6tables - BOOLEAN + 1 : pass bridged IPv6 traffic to ip6tables' chains. + 0 : disable this. + Default: 1 + bridge-nf-filter-vlan-tagged - BOOLEAN 1 : pass bridged vlan-tagged ARP/IP traffic to arptables/iptables. 0 : disable this.
David S. Miller
maintainerQuoted 2 lines · On Wed, 1 Sep 2004 22:34:26 +0200 Bart De Schuymer <[email protected]> wrote:
From reading Yasuyuki's reply and the specific code, the IPv6 checks before giving a bridged packet to ip6tables should now be accurate.
Looks fine, patch applied.
Thanks Bart.
Hi,
From: Bart De Schuymer <[email protected]>
Date: Wed, 1 Sep 2004 22:34:26 +0200
Quoted 14 lines
Hi Dave,
Quoted 1 line
From reading Yasuyuki's reply and the specific code, the IPv6 checks
before giving a bridged packet to ip6tables should now be accurate.
These are the changes made to the original patch:
- * Aug 28 2004: add IPv6 filtering (bdschuym)
+ * Sep 01 2004: add IPv6 filtering (bdschuym)(quoted diff) +0
-0@@ -321,11 +321,12 @@ static unsigned int br_nf_pre_routing_ip goto inhdr_error; } if (hdr->nexthdr == NEXTHDR_HOP) {
Review static unsigned int br_nf_pre_routing_ip · line 328
Quoted 10 lines
(quoted diff) +5
-4- skb->h.raw = (u8*)(hdr+1); -#if 0 - if (ipv6_parse_hopopts(skb, offsetof(struct ipv6hdr, nexthdr))<0) + /* We only check the length. A bridge shouldn't do any + * hop-by-hop stuff anyway. */ + unsigned char *raw = (u8*)(skb->nh.ipv6h+1); + + if ((raw + ((int)(raw[1]+1)<<3)) - skb->data > skb_headlen(skb)) goto inhdr_error; -#endif
You forgot to find "Jumbo Payload Option" in Hop-by-Hop Options header. Other options may exist in this header.
And please truncate packet if actual packet length is greater than Jumbo Payload Length + IPv6 header length.
Maybe you need to write the function that finds "Jumbo Payload Option" by parsing Hop-by-Hop Options header, checks the payload length, and truncates packet if necessary.
I think it is not preferable to call ipv6_parse_hopopts() at this point. Because Hop-by-Hop Options header may include other options and ipv6_hop_jumbo() may send ICMPv6 error.
Regards,
Quoted 5 lines · Yasuyuki Kozakai
You forgot to find "Jumbo Payload Option" in Hop-by-Hop Options header. Other options may exist in this header.
And please truncate packet if actual packet length is greater than Jumbo Payload Length + IPv6 header length.
Hmm.. a bridge should not touch the packet content unless absolutely needed to fulfill the Ethernet requirements. Why should it do this on IPv6?
Does Netfilter require that too large packets have been truncated?
Regards
Henrik
Hi,
From: Henrik Nordstrom <[email protected]>
Date: Thu, 2 Sep 2004 10:31:05 +0200 (CEST)
Quoted 11 lines · Yasuyuki Kozakai
Quoted 6 lines
You forgot to find "Jumbo Payload Option" in Hop-by-Hop Options header. Other options may exist in this header.
And please truncate packet if actual packet length is greater than Jumbo Payload Length + IPv6 header length.
Hmm.. a bridge should not touch the packet content unless absolutely needed to fulfill the Ethernet requirements. Why should it do this on IPv6?
Hmm... Indeed, I don't want br_netfilter to change the packet size when just loading it...
Maybe alternatives are as follows.
1. drop such packets. This approach is not different with truncating in that output is not same as input when loading it.
2. change netfilter modules to use payload length in IPv4 header/IPv6 header/Jumbogram option. Maybe many changes are necessary...
3. Just trust skb->len even if it doesn't consist with payload length in the headers. I'm not sure what happens in this case. At least, we have to be careful not to bring kernel panic and so on. The advantage of this case is that user can select to drop/truncate by inserting filtering rule.
other idea ?
Quoted 1 line
Does Netfilter require that too large packets have been truncated?
Many netfilter modules assume that skb->len is the right payload length. And some modules uses this value to calculate checksum.
Quoted 4 lines
Regards
Henrik
-----------------------------------------------------------------
Yasuyuki KOZAKAI @ USAGI Project <[email protected]>
Quoted 6 lines · Yasuyuki Kozakai
Quoted 6 lines · Yasuyuki Kozakai
Quoted 5 lines
You forgot to find "Jumbo Payload Option" in Hop-by-Hop Options header. Other options may exist in this header.
And please truncate packet if actual packet length is greater than Jumbo Payload Length + IPv6 header length.
The incremental patch below introduces this.
Quoted 6 lines
Quoted 3 lines
Hmm.. a bridge should not touch the packet content unless absolutely needed to fulfill the Ethernet requirements. Why should it do this on IPv6?
Hmm... Indeed, I don't want
br_netfilterto change the packet size when just loading it...
I'd prefer just doing the truncate. bridge-nf has been doing it for IPv4 for almost 2 years now in the 2.5/2.6 kernel.
Quoted 4 lines
Maybe alternatives are as follows.
1. drop such packets. This approach is not different with truncating in that output is not same as input when loading it.
Easily done if this is preferred over the truncate.
Quoted 3 lines
2. change netfilter modules to use payload length in IPv4 header/IPv6 header/Jumbogram option. Maybe many changes are necessary...
I don't like this approach and I think the netfilter guys will agree.
Quoted 5 lines
3. Just trust
skb->leneven if it doesn't consist with payload length in the headers. I'm not sure what happens in this case. At least, we have to be careful not to bring kernel panic and so on. The advantage of this case is that user can select to drop/truncate by inserting filtering rule.
I'm not in the mood to go through all the ip6tables modules :)
Dave, unless someone complains, please apply.
cheers,
Bart
PS: I noticed ipv6_hop_jumbo() doesn't check the return value of __pskb_trim().
net/bridge/br_netfilter.c renamed from net/bridge/br_netfilter.c.older +64 -10
@@ -290,6 +290,62 @@ static void setup_pre_routing(struct sk_ skb->dev =bridge_parent (skb->dev); } +/* We only check the length. A bridge shouldn't do any hop-by-hop stuff anyway */ +static int check_hbh_len (struct sk_buff *skb) +{ +unsigned char *raw = (u8 *)(skb->nh.ipv6h+1 ); +u32 pkt_len; +int off = raw - skb->nh.raw; +int len = (raw[1 ]+1 )<<3 ; + +if ((raw + len) - skb->data >skb_headlen (skb)) + goto bad; + + off +=2 ; + len -=2 ; + +while (len >0 ) { +int optlen = raw[off+1 ]+2 ; + +switch (skb->nh.raw[off]) { +case IPV6_TLV_PAD0 : + optlen =1 ; +break ; + +case IPV6_TLV_PADN : +break ; + +case IPV6_TLV_JUMBO : +if (skb->nh.raw[off+1 ] !=4 || (off&3 ) !=2 ) + goto bad; + + pkt_len =ntohl (*(u32 *)(skb->nh.raw+off+2 )); + +if (pkt_len > skb->len -sizeof (struct ipv6hdr )) + goto bad; +if (pkt_len +sizeof (struct ipv6hdr ) < skb->len) { +if (__pskb_trim (skb, + pkt_len +sizeof (struct ipv6hdr ))) + goto bad; +if (skb->ip_summed ==CHECKSUM_HW ) + skb->ip_summed =CHECKSUM_NONE ; + } +break ; +default : +if (optlen > len) + goto bad; +break ; + } + off += optlen; + len -= optlen; + } +if (len ==0 ) +return 0 ; +bad: +return -1 ; + +} +/* Replicate the checks that IPv6 does on packet reception and pass the packet * to ip6tables, which doesn't support NAT, so things are fairly simple. */ static unsigned int br_nf_pre_routing_ipv6(unsigned int hook,
@@ -316,18 +372,16 @@ static unsigned int br_nf_pre_routing_ipif (pkt_len || hdr->nexthdr !=NEXTHDR_HOP ) {if (pkt_len +sizeof (struct ipv6hdr ) > skb->len) goto inhdr_error; -if (pkt_len +sizeof (struct ipv6hdr ) < skb->len && -__pskb_trim (skb, pkt_len +sizeof (struct ipv6hdr ))) - goto inhdr_error; +if (pkt_len +sizeof (struct ipv6hdr ) < skb->len) { +if (__pskb_trim (skb, pkt_len +sizeof (struct ipv6hdr ))) + goto inhdr_error; +if (skb->ip_summed ==CHECKSUM_HW ) + skb->ip_summed =CHECKSUM_NONE ; + } } -if (hdr->nexthdr ==NEXTHDR_HOP ) { -/* We only check the length. A bridge shouldn't do any -* hop-by-hop stuff anyway. */ -unsigned char *raw = (u8 *)(skb->nh.ipv6h+1 ); - -if ((raw + ((int )(raw[1 ]+1 )<<3 )) - skb->data >skb_headlen (skb)) +if (hdr->nexthdr ==NEXTHDR_HOP &&check_hbh_len (skb)) goto inhdr_error; - } +#ifdef CONFIG_NETFILTER_DEBUG skb->nf_debug ^= (1 <<NF_IP6_PRE_ROUTING );#endif
Quoted 8 lines · Bart De Schuymer
Quoted 6 lines
Quoted 6 lines · Yasuyuki Kozakai
Quoted 5 lines
You forgot to find "Jumbo Payload Option" in Hop-by-Hop Options header. Other options may exist in this header.
And please truncate packet if actual packet length is greater than Jumbo Payload Length + IPv6 header length.
The incremental patch below introduces this.
<snip>
Quoted 1 line
Dave, unless someone complains, please apply.
Hi Dave,
I was wondering what your plans are on applying the patch I sent last Thursday. Noone has complained about it.
Quoted 1 line
--- linux-2.6.8.1/net/bridge/br_netfilter.c.older 2004-09-02
<snip>
David S. Miller
maintainerQuoted 2 lines · On Tue, 7 Sep 2004 20:41:27 +0200 Bart De Schuymer <[email protected]> wrote:
I was wondering what your plans are on applying the patch I sent last Thursday. Noone has complained about it.
Will apply, just slightly backlogged after the holiday weekend.
Quoted 10 lines · Henrik Nordstrom
Quoted 5 lines · Yasuyuki Kozakai
You forgot to find "Jumbo Payload Option" in Hop-by-Hop Options header. Other options may exist in this header.
And please truncate packet if actual packet length is greater than Jumbo Payload Length + IPv6 header length.
Hmm.. a bridge should not touch the packet content unless absolutely needed to fulfill the Ethernet requirements. Why should it do this on IPv6?
Well, it's the bridge-nf code that touches the packet, not the bridge code and bridge-nf can be disabled. I don't see any real difference between this and doing NAT (f.e.) on a bridged packet, except of course that the user doesn't have any control over it.
Note that bridge-nf for the IPv4 case does this:
if (skb->len > len) {
__pskb_trim(skb, len);
if (skb->ip_summed == CHECKSUM_HW)
skb->ip_summed = CHECKSUM_NONE;
}cheers,
Bart