public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Chris Wright <chrisw@sous-sol.org>
To: linux-kernel@vger.kernel.org, stable@kernel.org
Cc: Justin Forbes <jmforbes@linuxtx.org>,
	Zwane Mwaikambo <zwane@arm.linux.org.uk>,
	"Theodore Ts'o" <tytso@mit.edu>,
	Randy Dunlap <rdunlap@xenotime.net>,
	Dave Jones <davej@redhat.com>,
	Chuck Wolber <chuckw@quantumlinux.com>,
	Chris Wedgwood <reviews@ml.cw.f00f.org>,
	Michael Krufky <mkrufky@linuxtv.org>,
	torvalds@osdl.org, akpm@osdl.org, alan@lxorguk.ukuu.org.uk,
	Patrick McHardy <kaber@trash.net>,
	davem@davemloft.net, Bart De Schuymer <bdschuym@pandora.be>
Subject: [patch 14/32] NETFILTER: bridge netfilter: deal with martians correctly
Date: Fri, 08 Dec 2006 15:58:05 -0800	[thread overview]
Message-ID: <20061209000030.357789000@sous-sol.org> (raw)
In-Reply-To: 20061208235751.890503000@sous-sol.org

[-- Attachment #1: netfilter-bridge-netfilter-deal-with-martians-correctly.patch --]
[-- Type: text/plain, Size: 4594 bytes --]

-stable review patch.  If anyone has any objections, please let us know.
------------------

From: Bart De Schuymer <bdschuym@pandora.be>

The attached patch resolves an issue where a IP DNATed packet with a
martian source is forwarded while it's better to drop it. It also
resolves messages complaining about ip forwarding being disabled while
it's actually enabled. Thanks to lepton <ytht.net@gmail.com> for
reporting this problem.

This is probably a candidate for the -stable release.

Signed-off-by: Bart De Schuymer <bdschuym@pandora.be>
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
---
commit bb01f827bae980efdecc33fbcdc1b90f1c355b3e
tree 432a8f2843b47ccac094efea35da6f19731ed834
parent 14f5487cb9bd34cd59360d2cac7dccac9b27e8ce
author Bart De Schuymer <bdschuym@pandora.be> Mon, 04 Dec 2006 12:19:46 +0100
committer Patrick McHardy <kaber@trash.net> Mon, 04 Dec 2006 12:19:46 +0100

 net/bridge/br_netfilter.c |   36 ++++++++++++++++++++++++++++--------
 1 file changed, 28 insertions(+), 8 deletions(-)

--- linux-2.6.19.orig/net/bridge/br_netfilter.c
+++ linux-2.6.19/net/bridge/br_netfilter.c
@@ -34,6 +34,7 @@
 #include <linux/netfilter_ipv6.h>
 #include <linux/netfilter_arp.h>
 #include <linux/in_route.h>
+#include <linux/inetdevice.h>
 
 #include <net/ip.h>
 #include <net/ipv6.h>
@@ -222,10 +223,14 @@ static void __br_dnat_complain(void)
  *
  * Otherwise, the packet is considered to be routed and we just
  * change the destination MAC address so that the packet will
- * later be passed up to the IP stack to be routed.
+ * later be passed up to the IP stack to be routed. For a redirected
+ * packet, ip_route_input() will give back the localhost as output device,
+ * which differs from the bridge device.
  *
  * Let us now consider the case that ip_route_input() fails:
  *
+ * This can be because the destination address is martian, in which case
+ * the packet will be dropped.
  * After a "echo '0' > /proc/sys/net/ipv4/ip_forward" ip_route_input()
  * will fail, while __ip_route_output_key() will return success. The source
  * address for __ip_route_output_key() is set to zero, so __ip_route_output_key
@@ -238,7 +243,8 @@ static void __br_dnat_complain(void)
  *
  * --Lennert, 20020411
  * --Bart, 20020416 (updated)
- * --Bart, 20021007 (updated) */
+ * --Bart, 20021007 (updated)
+ * --Bart, 20062711 (updated) */
 static int br_nf_pre_routing_finish_bridge(struct sk_buff *skb)
 {
 	if (skb->pkt_type == PACKET_OTHERHOST) {
@@ -265,15 +271,15 @@ static int br_nf_pre_routing_finish(stru
 	struct net_device *dev = skb->dev;
 	struct iphdr *iph = skb->nh.iph;
 	struct nf_bridge_info *nf_bridge = skb->nf_bridge;
+	int err;
 
 	if (nf_bridge->mask & BRNF_PKT_TYPE) {
 		skb->pkt_type = PACKET_OTHERHOST;
 		nf_bridge->mask ^= BRNF_PKT_TYPE;
 	}
 	nf_bridge->mask ^= BRNF_NF_BRIDGE_PREROUTING;
-
 	if (dnat_took_place(skb)) {
-		if (ip_route_input(skb, iph->daddr, iph->saddr, iph->tos, dev)) {
+		if ((err = ip_route_input(skb, iph->daddr, iph->saddr, iph->tos, dev))) {
 			struct rtable *rt;
 			struct flowi fl = {
 				.nl_u = {
@@ -284,19 +290,33 @@ static int br_nf_pre_routing_finish(stru
 				},
 				.proto = 0,
 			};
+			struct in_device *in_dev = in_dev_get(dev);
+
+			/* If err equals -EHOSTUNREACH the error is due to a
+			 * martian destination or due to the fact that
+			 * forwarding is disabled. For most martian packets,
+			 * ip_route_output_key() will fail. It won't fail for 2 types of
+			 * martian destinations: loopback destinations and destination
+			 * 0.0.0.0. In both cases the packet will be dropped because the
+			 * destination is the loopback device and not the bridge. */
+			if (err != -EHOSTUNREACH || !in_dev || IN_DEV_FORWARD(in_dev))
+				goto free_skb;
 
 			if (!ip_route_output_key(&rt, &fl)) {
 				/* - Bridged-and-DNAT'ed traffic doesn't
-				 *   require ip_forwarding.
-				 * - Deal with redirected traffic. */
-				if (((struct dst_entry *)rt)->dev == dev ||
-				    rt->rt_type == RTN_LOCAL) {
+				 *   require ip_forwarding. */
+				if (((struct dst_entry *)rt)->dev == dev) {
 					skb->dst = (struct dst_entry *)rt;
 					goto bridged_dnat;
 				}
+				/* we are sure that forwarding is disabled, so printing
+				 * this message is no problem. Note that the packet could
+				 * still have a martian destination address, in which case
+				 * the packet could be dropped even if forwarding were enabled */
 				__br_dnat_complain();
 				dst_release((struct dst_entry *)rt);
 			}
+free_skb:
 			kfree_skb(skb);
 			return 0;
 		} else {

--

  parent reply	other threads:[~2006-12-09  0:09 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-08 23:57 [patch 00/32] -stable review Chris Wright
2006-12-08 23:57 ` [patch 01/32] IPV6 NDISC: Calculate packet length correctly for allocation Chris Wright
2006-12-08 23:57 ` [patch 02/32] softmac: remove netif_tx_disable when scanning Chris Wright
2006-12-08 23:57 ` [patch 03/32] EBTABLES: Fix wraparounds in ebt_entries verification Chris Wright
2006-12-08 23:57 ` [patch 04/32] EBTABLES: Verify that ebt_entries have zero ->distinguisher Chris Wright
2006-12-08 23:57 ` [patch 05/32] EBTABLES: Deal with the worst-case behaviour in loop checks Chris Wright
2006-12-08 23:57 ` [patch 06/32] EBTABLES: Prevent wraparounds in checks for entry components sizes Chris Wright
2006-12-08 23:57 ` [patch 07/32] NET_SCHED: policer: restore compatibility with old iproute binaries Chris Wright
2006-12-08 23:57 ` [patch 08/32] cryptoloop: Select CRYPTO_CBC Chris Wright
2006-12-09  6:32   ` Rene Herman
2006-12-09 22:50     ` Herbert Xu
2006-12-08 23:58 ` [patch 09/32] Revert "ACPI: SCI interrupt source override" Chris Wright
2006-12-08 23:58 ` [patch 10/32] PKT_SCHED act_gact: division by zero Chris Wright
2006-12-08 23:58 ` [patch 11/32] SUNHME: Fix for sunhme failures on x86 Chris Wright
2006-12-08 23:58 ` [patch 12/32] NETFILTER: Fix {ip, ip6, arp}_tables hook validation Chris Wright
2006-12-08 23:58 ` [patch 13/32] NETFILTER: Fix iptables compat " Chris Wright
2006-12-08 23:58 ` Chris Wright [this message]
2006-12-08 23:58 ` [patch 15/32] softmac: fix unbalanced mutex_lock/unlock in ieee80211softmac_wx_set_mlme Chris Wright
2006-12-08 23:58 ` [patch 16/32] IB/ucm: Fix deadlock in cleanup Chris Wright
2006-12-08 23:58 ` [patch 17/32] do_coredump() and not stopping rewrite attacks? (CVE-2006-6304) Chris Wright
2006-12-08 23:58 ` [patch 18/32] TOKENRING: Remote memory corruptor in ibmtr.c Chris Wright
2006-12-08 23:58 ` [patch 19/32] XFRM: Use output device disable_xfrm for forwarded packets Chris Wright
2006-12-08 23:58 ` [patch 20/32] USB: Fix oops in PhidgetServo Chris Wright
2006-12-08 23:58 ` [patch 21/32] IPSEC: Fix inetpeer leak in ipv4 xfrm dst entries Chris Wright
2006-12-08 23:58 ` [patch 22/32] IrDA: Incorrect TTP header reservation Chris Wright
2006-12-08 23:58 ` [patch 23/32] NETLINK: Restore API compatibility of address and neighbour bits Chris Wright
2006-12-08 23:58 ` [patch 24/32] add bottom_half.h Chris Wright
2006-12-09 13:50   ` Thomas Backlund
2006-12-08 23:58 ` [patch 25/32] drm-sis linkage fix Chris Wright
2006-12-08 23:58 ` [patch 26/32] compat: skip data conversion in compat_sys_mount when data_page is NULL Chris Wright
2006-12-08 23:58 ` [patch 27/32] PM: Fix swsusp debug mode testproc Chris Wright
2006-12-08 23:58 ` [patch 28/32] autofs: fix error code path in autofs_fill_sb() Chris Wright
2006-12-09  3:48   ` Ian Kent
2006-12-09 18:58     ` Chris Wright
2006-12-08 23:58 ` [patch 29/32] softirq: remove BUG_ONs which can incorrectly trigger Chris Wright
2006-12-08 23:58 ` [patch 30/32] m32r: make userspace headers platform-independent Chris Wright
2006-12-08 23:58 ` [patch 31/32] x86_64: fix boot hang due to nmi watchdog init code Chris Wright
2006-12-11 18:33   ` [stable] " Chris Wright
2006-12-08 23:58 ` [patch 32/32] forcedeth: Disable INTx when enabling MSI in forcedeth Chris Wright
2006-12-09  0:38 ` [stable] [patch 00/32] -stable review Chris Wright
2006-12-09  1:36 ` [patch 33/32] NETLINK: Put {IFA,IFLA}_{RTA,PAYLOAD} macros back for userspace Chris Wright
2006-12-09 11:26 ` [patch 00/32] -stable review Stefan Lippers-Hollmann
2006-12-09 21:42   ` Chris Wright

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20061209000030.357789000@sous-sol.org \
    --to=chrisw@sous-sol.org \
    --cc=akpm@osdl.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=bdschuym@pandora.be \
    --cc=chuckw@quantumlinux.com \
    --cc=davej@redhat.com \
    --cc=davem@davemloft.net \
    --cc=jmforbes@linuxtx.org \
    --cc=kaber@trash.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mkrufky@linuxtv.org \
    --cc=rdunlap@xenotime.net \
    --cc=reviews@ml.cw.f00f.org \
    --cc=stable@kernel.org \
    --cc=torvalds@osdl.org \
    --cc=tytso@mit.edu \
    --cc=zwane@arm.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox