netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] Netfilter/IPVS fixes for 3.8-rc7
@ 2013-02-09 12:03 pablo
  2013-02-09 12:03 ` [PATCH 1/5] ipvs: freeing uninitialized pointer on error pablo
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: pablo @ 2013-02-09 12:03 UTC (permalink / raw)
  To: netfilter-devel; +Cc: davem, netdev

From: Pablo Neira Ayuso <pablo@netfilter.org>

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(-)

-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/5] ipvs: freeing uninitialized pointer on error
  2013-02-09 12:03 [PATCH 0/5] Netfilter/IPVS fixes for 3.8-rc7 pablo
@ 2013-02-09 12:03 ` pablo
  2013-02-09 12:03 ` [PATCH 2/5] ipvs: sctp: fix checksumming on snat and dnat handlers pablo
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pablo @ 2013-02-09 12:03 UTC (permalink / raw)
  To: netfilter-devel; +Cc: davem, netdev

From: Dan Carpenter <dan.carpenter@oracle.com>

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.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Julian Anastasov <ja@ssi.bg>
Signed-off-by: Simon Horman <horms@verge.net.au>
---
 net/netfilter/ipvs/ip_vs_sync.c |    2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
index effa10c..44fd10c 100644
--- a/net/netfilter/ipvs/ip_vs_sync.c
+++ b/net/netfilter/ipvs/ip_vs_sync.c
@@ -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;
 
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/5] ipvs: sctp: fix checksumming on snat and dnat handlers
  2013-02-09 12:03 [PATCH 0/5] Netfilter/IPVS fixes for 3.8-rc7 pablo
  2013-02-09 12:03 ` [PATCH 1/5] ipvs: freeing uninitialized pointer on error pablo
@ 2013-02-09 12:03 ` pablo
  2013-02-09 12:03 ` [PATCH 3/5] netfilter: ip6t_NPT: Fix adjustment calculation pablo
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pablo @ 2013-02-09 12:03 UTC (permalink / raw)
  To: netfilter-devel; +Cc: davem, netdev

From: Daniel Borkmann <dborkman@redhat.com>

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.

Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Acked-by: Julian Anastasov <ja@ssi.bg>
Signed-off-by: Simon Horman <horms@verge.net.au>
---
 net/netfilter/ipvs/ip_vs_proto_sctp.c |   35 ++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 18 deletions(-)

diff --git a/net/netfilter/ipvs/ip_vs_proto_sctp.c b/net/netfilter/ipvs/ip_vs_proto_sctp.c
index 746048b..ae8ec6f 100644
--- a/net/netfilter/ipvs/ip_vs_proto_sctp.c
+++ b/net/netfilter/ipvs/ip_vs_proto_sctp.c
@@ -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;
 }
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/5] netfilter: ip6t_NPT: Fix adjustment calculation
  2013-02-09 12:03 [PATCH 0/5] Netfilter/IPVS fixes for 3.8-rc7 pablo
  2013-02-09 12:03 ` [PATCH 1/5] ipvs: freeing uninitialized pointer on error pablo
  2013-02-09 12:03 ` [PATCH 2/5] ipvs: sctp: fix checksumming on snat and dnat handlers pablo
@ 2013-02-09 12:03 ` pablo
  2013-02-09 12:03 ` [PATCH 4/5] netfilter: ip6t_NPT: Fix prefix mangling pablo
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pablo @ 2013-02-09 12:03 UTC (permalink / raw)
  To: netfilter-devel; +Cc: davem, netdev

From: YOSHIFUJI Hideaki / 吉藤英明 <yoshfuji@linux-ipv6.org>

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. ]

Signed-off-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/ipv6/netfilter/ip6t_NPT.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/net/ipv6/netfilter/ip6t_NPT.c b/net/ipv6/netfilter/ip6t_NPT.c
index 7302b0b..68788c8 100644
--- a/net/ipv6/netfilter/ip6t_NPT.c
+++ b/net/ipv6/netfilter/ip6t_NPT.c
@@ -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;
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 4/5] netfilter: ip6t_NPT: Fix prefix mangling
  2013-02-09 12:03 [PATCH 0/5] Netfilter/IPVS fixes for 3.8-rc7 pablo
                   ` (2 preceding siblings ...)
  2013-02-09 12:03 ` [PATCH 3/5] netfilter: ip6t_NPT: Fix adjustment calculation pablo
@ 2013-02-09 12:03 ` pablo
  2013-02-09 12:04 ` [PATCH 5/5] netfilter: ip6t_NPT: Ensure to check lower part of prefixes are zero pablo
  2013-02-11  1:44 ` [PATCH 0/5] Netfilter/IPVS fixes for 3.8-rc7 David Miller
  5 siblings, 0 replies; 7+ messages in thread
From: pablo @ 2013-02-09 12:03 UTC (permalink / raw)
  To: netfilter-devel; +Cc: davem, netdev

From: YOSHIFUJI Hideaki / 吉藤英明 <yoshfuji@linux-ipv6.org>

Make sure only the bits that are part of the prefix are mangled.

Signed-off-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/ipv6/netfilter/ip6t_NPT.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/ipv6/netfilter/ip6t_NPT.c b/net/ipv6/netfilter/ip6t_NPT.c
index 68788c8..87b759c 100644
--- a/net/ipv6/netfilter/ip6t_NPT.c
+++ b/net/ipv6/netfilter/ip6t_NPT.c
@@ -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)
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 5/5] netfilter: ip6t_NPT: Ensure to check lower part of prefixes are zero
  2013-02-09 12:03 [PATCH 0/5] Netfilter/IPVS fixes for 3.8-rc7 pablo
                   ` (3 preceding siblings ...)
  2013-02-09 12:03 ` [PATCH 4/5] netfilter: ip6t_NPT: Fix prefix mangling pablo
@ 2013-02-09 12:04 ` pablo
  2013-02-11  1:44 ` [PATCH 0/5] Netfilter/IPVS fixes for 3.8-rc7 David Miller
  5 siblings, 0 replies; 7+ messages in thread
From: pablo @ 2013-02-09 12:04 UTC (permalink / raw)
  To: netfilter-devel; +Cc: davem, netdev

From: YOSHIFUJI Hideaki / 吉藤英明 <yoshfuji@linux-ipv6.org>

RFC 6296 points that address bits that are not part of the prefix
has to be zeroed.

Signed-off-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/ipv6/netfilter/ip6t_NPT.c |   10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/net/ipv6/netfilter/ip6t_NPT.c b/net/ipv6/netfilter/ip6t_NPT.c
index 87b759c..83acc14 100644
--- a/net/ipv6/netfilter/ip6t_NPT.c
+++ b/net/ipv6/netfilter/ip6t_NPT.c
@@ -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]);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/5] Netfilter/IPVS fixes for 3.8-rc7
  2013-02-09 12:03 [PATCH 0/5] Netfilter/IPVS fixes for 3.8-rc7 pablo
                   ` (4 preceding siblings ...)
  2013-02-09 12:04 ` [PATCH 5/5] netfilter: ip6t_NPT: Ensure to check lower part of prefixes are zero pablo
@ 2013-02-11  1:44 ` David Miller
  5 siblings, 0 replies; 7+ messages in thread
From: David Miller @ 2013-02-11  1:44 UTC (permalink / raw)
  To: pablo; +Cc: netfilter-devel, netdev

From: pablo@netfilter.org
Date: Sat,  9 Feb 2013 13:03:55 +0100

> 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

Pulled, thanks Pablo.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-02-11  1:44 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-09 12:03 [PATCH 0/5] Netfilter/IPVS fixes for 3.8-rc7 pablo
2013-02-09 12:03 ` [PATCH 1/5] ipvs: freeing uninitialized pointer on error pablo
2013-02-09 12:03 ` [PATCH 2/5] ipvs: sctp: fix checksumming on snat and dnat handlers pablo
2013-02-09 12:03 ` [PATCH 3/5] netfilter: ip6t_NPT: Fix adjustment calculation pablo
2013-02-09 12:03 ` [PATCH 4/5] netfilter: ip6t_NPT: Fix prefix mangling pablo
2013-02-09 12:04 ` [PATCH 5/5] netfilter: ip6t_NPT: Ensure to check lower part of prefixes are zero pablo
2013-02-11  1:44 ` [PATCH 0/5] Netfilter/IPVS fixes for 3.8-rc7 David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).