Netfilter/IPVS fixes for 3.8-rc7
Subsystems (4)
[email protected]
maintainercover Netfilter/IPVS fixes for 3.8-rc7
From: Pablo Neira Ayuso <[email protected]>
Hi David,
The following patchset contains Netfilter/IPVS fixes for 3.8-rc7, they are:
* Fix oops in IPVS state-sync due to releasing a random memory area due to unitialized pointer, from Dan Carpenter.
* Fix SCTP flow establishment due to bad checksumming mangling in IPVS, from Daniel Borkmann.
* Three fixes for the recently added IPv6 NPT, all from YOSHIFUJI Hideaki, with an amendment collapsed into those patches from Ulrich Weber. They fiix adjustment calculation, fix prefix mangling and ensure LSB of prefixes are zeroes (as required by RFC).
Specifically, it took me a while to validate the 1's complement arithmetics/ checksumming approach in the IPv6 NPT code.
It's fairly late stage, so let me know if you can still pull these from:
git://1984.lsi.us.es/nf master
Thanks!
Dan Carpenter (1):
ipvs: freeing uninitialized pointer on error
Daniel Borkmann (1):
ipvs: sctp: fix checksumming on snat and dnat handlers
YOSHIFUJI Hideaki / 吉藤英明 (3):
netfilter: ip6t_NPT: Fix adjustment calculation
netfilter: ip6t_NPT: Fix prefix mangling
netfilter: ip6t_NPT: Ensure to check lower part of prefixes are zero
net/ipv6/netfilter/ip6t_NPT.c | 18 +++++++++++++---- net/netfilter/ipvs/ip_vs_proto_sctp.c | 35 ++++++++++++++++----------------- net/netfilter/ipvs/ip_vs_sync.c | 2 ++ 3 files changed, 33 insertions(+), 22 deletions(-)
Signature · 6 lines
1.7.10.4 -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
[email protected]
maintainerPATCH 1/5 ipvs: freeing uninitialized pointer on error
From: Dan Carpenter <[email protected]>
If state != IP_VS_STATE_BACKUP then tinfo->buf is uninitialized. If kthread_run() fails then it means we free random memory resulting in an oops.
--- net/netfilter/ipvs/ip_vs_sync.c | 2 ++ 1 file changed, 2 insertions(+)
net/netfilter/ipvs/ip_vs_sync.c +2 -0
@@ -1795,6 +1795,8 @@ int start_sync_thread(struct net *net, int state, char *mcast_ifn, __u8 syncid) GFP_KERNEL);if (!tinfo->buf) goto outtinfo; + }else { + tinfo->buf =NULL ; } tinfo->id = id;
Signature · 1 line
1.7.10.4
[email protected]
maintainerPATCH 2/5 ipvs: sctp: fix checksumming on snat and dnat handlers
In reply to [email protected]From: Daniel Borkmann <[email protected]>
In our test lab, we have a simple SCTP client connecting to a SCTP server via an IPVS load balancer. On some machines, load balancing works, but on others the initial handshake just fails, thus no SCTP connection whatsoever can be established!
We observed that the SCTP INIT-ACK handshake reply from the IPVS machine to the client had a correct IP checksum, but corrupt SCTP checksum when forwarded, thus on the client-side the packet was dropped and an intial handshake retriggered until all attempts run into the void.
To fix this issue, this patch i) adds a missing CHECKSUM_UNNECESSARY after the full checksum (re-)calculation (as done in IPVS TCP and UDP code as well), ii) calculates the checksum in little-endian format (as fixed with the SCTP code in commit 4458f04c: sctp: Clean up sctp checksumming code) and iii) refactors duplicate checksum code into a common function. Tested by myself.
--- net/netfilter/ipvs/ip_vs_proto_sctp.c | 35 ++++++++++++++++----------------- 1 file changed, 17 insertions(+), 18 deletions(-)
net/netfilter/ipvs/ip_vs_proto_sctp.c +17 -18
@@ -61,14 +61,27 @@ sctp_conn_schedule(int af, struct sk_buff *skb, struct ip_vs_proto_data *pd,return 1 ; } +static void sctp_nat_csum (struct sk_buff *skb,sctp_sctphdr_t *sctph, +unsigned int sctphoff) +{ +__u32 crc32; +struct sk_buff *iter; + + crc32 =sctp_start_cksum ((__u8 *)sctph,skb_headlen (skb) - sctphoff); +skb_walk_frags (skb, iter) + crc32 = sctp_update_cksum((u8 *) iter->data, +skb_headlen (iter), crc32); + sctph->checksum =sctp_end_cksum (crc32); + + skb->ip_summed =CHECKSUM_UNNECESSARY ; +} +static int sctp_snat_handler (struct sk_buff *skb,struct ip_vs_protocol *pp,struct ip_vs_conn *cp,struct ip_vs_iphdr *iph) {sctp_sctphdr_t *sctph;unsigned int sctphoff = iph->len; -struct sk_buff *iter; -__be32 crc32;#ifdef CONFIG_IP_VS_IPV6 if (cp->af ==AF_INET6 && iph->fragoffs)
@@ -92,13 +105,7 @@ sctp_snat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp, sctph = (void *)skb_network_header (skb) + sctphoff; sctph->source = cp->vport; -/* Calculate the checksum */ - crc32 =sctp_start_cksum ((u8 *) sctph,skb_headlen (skb) - sctphoff); -skb_walk_frags (skb, iter) - crc32 = sctp_update_cksum((u8 *) iter->data, skb_headlen(iter), - crc32); - crc32 =sctp_end_cksum (crc32); - sctph->checksum = crc32; +sctp_nat_csum (skb, sctph, sctphoff);return 1 ; }
@@ -109,8 +116,6 @@ sctp_dnat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp, {sctp_sctphdr_t *sctph;unsigned int sctphoff = iph->len; -struct sk_buff *iter; -__be32 crc32;#ifdef CONFIG_IP_VS_IPV6 if (cp->af ==AF_INET6 && iph->fragoffs)
@@ -134,13 +139,7 @@ sctp_dnat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp, sctph = (void *)skb_network_header (skb) + sctphoff; sctph->dest = cp->dport; -/* Calculate the checksum */ - crc32 =sctp_start_cksum ((u8 *) sctph,skb_headlen (skb) - sctphoff); -skb_walk_frags (skb, iter) - crc32 = sctp_update_cksum((u8 *) iter->data, skb_headlen(iter), - crc32); - crc32 =sctp_end_cksum (crc32); - sctph->checksum = crc32; +sctp_nat_csum (skb, sctph, sctphoff);return 1 ; }
Signature · 1 line
1.7.10.4
[email protected]
maintainerPATCH 3/5 netfilter: ip6t_NPT: Fix adjustment calculation
In reply to [email protected]From: YOSHIFUJI Hideaki / 吉藤英明 <[email protected]>
Cast __wsum from/to __sum16 is wrong. Instead, apply appropriate conversion function: csum_unfold() or csum_fold().
[ The original patch has been modified to undo the final ~ that
csum_fold returns. We only need to fold the 32-bit word that results from the checksum calculation into a 16-bit to ensure that the original subnet is restored appropriately. Spotted by Ulrich Weber. ]
--- net/ipv6/netfilter/ip6t_NPT.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/ipv6/netfilter/ip6t_NPT.c +3 -3
@@ -30,7 +30,7 @@ static int ip6t_npt_checkentry(const struct xt_tgchk_param *par) (__force __wsum)npt->dst_pfx.in6.s6_addr16[i]); } - npt->adjustment = (__force __sum16 )csum_sub (src_sum, dst_sum); + npt->adjustment = ~csum_fold (csum_sub (src_sum, dst_sum));return 0 ; }
@@ -66,8 +66,8 @@ static bool ip6t_npt_map_pfx(const struct ip6t_npt_tginfo *npt,return false; } - sum = (__force __sum16 )csum_add ((__force __wsum )addr->s6_addr16[idx], - npt->adjustment); + sum = ~csum_fold (csum_add (csum_unfold ((__force __sum16 )addr->s6_addr16[idx]), +csum_unfold (npt->adjustment)));if (sum ==CSUM_MANGLED_0 ) sum =0 ; *(__force __sum16 *)&addr->s6_addr16[idx] = sum;
Signature · 6 lines
1.7.10.4 -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
[email protected]
maintainerPATCH 4/5 netfilter: ip6t_NPT: Fix prefix mangling
In reply to [email protected]From: YOSHIFUJI Hideaki / 吉藤英明 <[email protected]>
Make sure only the bits that are part of the prefix are mangled.
--- net/ipv6/netfilter/ip6t_NPT.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/netfilter/ip6t_NPT.c +1 -1
@@ -51,7 +51,7 @@ static bool ip6t_npt_map_pfx(const struct ip6t_npt_tginfo *npt, idx = i /32 ; addr->s6_addr32[idx] &= mask; - addr->s6_addr32[idx] |= npt->dst_pfx.in6.s6_addr32[idx]; + addr->s6_addr32[idx] |= ~mask & npt->dst_pfx.in6.s6_addr32[idx]; }if (pfx_len <=48 )
Signature · 6 lines
1.7.10.4 -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
[email protected]
maintainerPATCH 5/5 netfilter: ip6t_NPT: Ensure to check lower part of prefixes are zero
In reply to [email protected]From: YOSHIFUJI Hideaki / 吉藤英明 <[email protected]>
RFC 6296 points that address bits that are not part of the prefix has to be zeroed.
--- net/ipv6/netfilter/ip6t_NPT.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
net/ipv6/netfilter/ip6t_NPT.c +10 -0
@@ -9,6 +9,7 @@#include <linux/module.h> #include <linux/skbuff.h> #include <linux/ipv6.h> +#include <net/ipv6.h> #include <linux/netfilter.h> #include <linux/netfilter_ipv6.h> #include <linux/netfilter_ipv6/ip6t_NPT.h>
@@ -18,11 +19,20 @@ static int ip6t_npt_checkentry(const struct xt_tgchk_param *par) {struct ip6t_npt_tginfo *npt = par->targinfo;__wsum src_sum =0 , dst_sum =0 ; +struct in6_addr pfx;unsigned int i;if (npt->src_pfx_len >64 || npt->dst_pfx_len >64 )return -EINVAL ; +/* Ensure that LSB of prefix is zero */ +ipv6_addr_prefix (&pfx, &npt->src_pfx.in6, npt->src_pfx_len); +if (!ipv6_addr_equal (&pfx, &npt->src_pfx.in6)) +return -EINVAL ; +ipv6_addr_prefix (&pfx, &npt->dst_pfx.in6, npt->dst_pfx_len); +if (!ipv6_addr_equal (&pfx, &npt->dst_pfx.in6)) +return -EINVAL ; +for (i =0 ; i <ARRAY_SIZE (npt->src_pfx.in6.s6_addr16); i++) { src_sum =csum_add (src_sum, (__force __wsum )npt->src_pfx.in6.s6_addr16[i]);
Signature · 6 lines
1.7.10.4 -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
David Miller
maintainerFrom: [email protected]
Date: Sat, 9 Feb 2013 13:03:55 +0100
Quoted 13 lines
The following patchset contains Netfilter/IPVS fixes for 3.8-rc7, they are:
* Fix oops in IPVS state-sync due to releasing a random memory area due to unitialized pointer, from Dan Carpenter.
* Fix SCTP flow establishment due to bad checksumming mangling in IPVS, from Daniel Borkmann.
* Three fixes for the recently added IPv6 NPT, all from YOSHIFUJI Hideaki, with an amendment collapsed into those patches from Ulrich Weber. They fiix adjustment calculation, fix prefix mangling and ensure LSB of prefixes are zeroes (as required by RFC).
Quoted 6 lines
Specifically, it took me a while to validate the 1's complement arithmetics/ checksumming approach in the IPv6 NPT code.
It's fairly late stage, so let me know if you can still pull these from:
git://1984.lsi.us.es/nfmaster
Pulled, thanks Pablo.