Skip to contentSkip to conversation

Do not use loopback as source address on other interfaces

PATCH In review Karsten Keil 3 participants 8 messages Jun 18, 2008 – Jun 19, 2008

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Do not use loopback as source address on other interfaces

RFC 4291 forbit the use of the loopback address as source outside a node (paragraph 2.5.3).

The latest TAHI test release 4.0.1 does have a check for this (ICMPv6 test v6LC.5.1.2 Part F), so it fails currently on Linux.

---
 net/ipv6/icmp.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
net/ipv6/icmp.c +4 -1
index d42dd16..a571437 100644
@@ -698,7 +698,10 @@ static int icmpv6_rcv(struct sk_buff *skb)
 
 	switch (type) {
 	case ICMPV6_ECHO_REQUEST:
-		icmpv6_echo_reply(skb);
+		/* check that the query is not for loopback address (PSE SPB) */
+		if (!(ipv6_addr_type(daddr) & IPV6_ADDR_LOOPBACK) ||
+		    (dev->flags & IFF_LOOPBACK))
+			icmpv6_echo_reply(skb);
 		break;
 
 	case ICMPV6_ECHO_REPLY:
Signature · 4 lines
Karsten Keil
SuSE Labs
ISDN and VOIP development
SUSE LINUX Products GmbH, Maxfeldstr.5 90409 Nuernberg, GF: Markus Rex, HRB 16746 (AG Nuernberg)
#1 lore raw

In article <[email protected]> (at Wed, 18 Jun 2008 15:23:12 +0200), Karsten Keil <[email protected]> says:

Quoted 8 lines

RFC 4291 forbit the use of the loopback address as source outside a node (paragraph 2.5.3).

The latest TAHI test release 4.0.1 does have a check for this (ICMPv6 test v6LC.5.1.2 Part F), so it fails currently on Linux.

I disagree this approach - too ad-hoc fix just to pass the tests.

--yoshfuji

#2 lore raw
Quoted 5 lines · YOSHIFUJI Hideaki / 吉藤英明

In article <[email protected]> (at Wed, 18 Jun 2008 15:23:12 +0200), Karsten Keil <[email protected]> says:

Quoted 3 lines

RFC 4291 forbit the use of the loopback address as source outside a node (paragraph 2.5.3).

Quoted 8 lines
Quoted 5 lines

The latest TAHI test release 4.0.1 does have a check for this (ICMPv6 test v6LC.5.1.2 Part F), so it fails currently on Linux.

I disagree this approach - too ad-hoc fix just to pass the tests.

So you would prefer a more general test in some common place (like __ip6_local_out() ) to avoid any packets with ::1 on other devices as loopback ?

Signature · 4 lines
Karsten Keil
SuSE Labs
ISDN and VOIP development
SUSE LINUX Products GmbH, Maxfeldstr.5 90409 Nuernberg, GF: Markus Rex, HRB 16746 (AG Nuernberg)
#3 lore raw
Quoted 12 lines · Karsten Keil
Quoted 11 lines · YOSHIFUJI Hideaki / 吉藤英明

In article <[email protected]> (at Wed, 18 Jun 2008 15:23:12 +0200), Karsten Keil <[email protected]> says:

Quoted 8 lines

RFC 4291 forbit the use of the loopback address as source outside a node (paragraph 2.5.3).

The latest TAHI test release 4.0.1 does have a check for this (ICMPv6 test v6LC.5.1.2 Part F), so it fails currently on Linux.

Quoted 7 lines
Quoted 2 lines

I disagree this approach - too ad-hoc fix just to pass the tests.

So you would prefer a more general test in some common place (like __ip6_local_out() ) to avoid any packets with ::1 on other devices as loopback ?

I think that dropping pakets with destination ::1 in ipv6_rcv() for devices != loopback would be better reflect what RFC 4291 2.5.3 says.

Signature · 4 lines
Karsten Keil
SuSE Labs
ISDN and VOIP development
SUSE LINUX Products GmbH, Maxfeldstr.5 90409 Nuernberg, GF: Markus Rex, HRB 16746 (AG Nuernberg)
#4 lore raw
In reply to Karsten Keil

In article <[email protected]> (at Wed, 18 Jun 2008 16:05:58 +0200), Karsten Keil <[email protected]> says:

Quoted 12 lines · YOSHIFUJI Hideaki / 吉藤英明
Quoted 11 lines

In article <[email protected]> (at Wed, 18 Jun 2008 15:23:12 +0200), Karsten Keil <[email protected]> says:

Quoted 8 lines

RFC 4291 forbit the use of the loopback address as source outside a node (paragraph 2.5.3).

The latest TAHI test release 4.0.1 does have a check for this (ICMPv6 test v6LC.5.1.2 Part F), so it fails currently on Linux.

Quoted 6 lines
Quoted 2 lines

I disagree this approach - too ad-hoc fix just to pass the tests.

So you would prefer a more general test in some common place (like __ip6_local_out() ) to avoid any packets with ::1 on other devices as loopback ?

No, we should not even accept packets for ::1 from outside of the box. Something like this.

---
ipv6: Drop packets for loopback address from outside of the box.

include/net/ipv6.h +6 -0
index e0a612b..f422f72 100644
@@ -367,6 +367,12 @@ static inline int ipv6_addr_any(const struct in6_addr *a)
 		 a->s6_addr32[2] | a->s6_addr32[3] ) == 0); 
 }
 
+static inline int ipv6_addr_loopback(const struct in6_addr *a)
+{
+	return ((a->s6_addr32[0] | a->s6_addr32[1] |
+		 a->s6_addr32[2] | (a->s6_addr32[3] ^ htonl(1))) == 0);
+}
+
 static inline int ipv6_addr_v4mapped(const struct in6_addr *a)
 {
 	return ((a->s6_addr32[0] | a->s6_addr32[1] |
net/ipv6/ip6_input.c +9 -0
index 4e5c861..17eb48b 100644
@@ -102,6 +102,15 @@ int ipv6_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt
 	if (hdr->version != 6)
 		goto err;
 
+	/*
+	 * RFC4291 2.5.3
+	 * A packet received on an interface with a destination address
+	 * of loopback must be dropped.
+	 */
+	if (!(dev->flags & IFF_LOOPBACK) &&
+	    ipv6_addr_loopback(&hdr->daddr))
+		goto err;
+
 	skb->transport_header = skb->network_header + sizeof(*hdr);
 	IP6CB(skb)->nhoff = offsetof(struct ipv6hdr, nexthdr);
 

--yoshfuji

#5 lore raw
Quoted 17 lines · YOSHIFUJI Hideaki / 吉藤英明

In article <[email protected]> (at Wed, 18 Jun 2008 16:05:58 +0200), Karsten Keil <[email protected]> says:

Quoted 15 lines · YOSHIFUJI Hideaki / 吉藤英明
Quoted 13 lines

In article <[email protected]> (at Wed, 18 Jun 2008 15:23:12 +0200), Karsten Keil <[email protected]> says:

Quoted 8 lines

RFC 4291 forbit the use of the loopback address as source outside a node (paragraph 2.5.3).

The latest TAHI test release 4.0.1 does have a check for this (ICMPv6 test v6LC.5.1.2 Part F), so it fails currently on Linux.

I disagree this approach - too ad-hoc fix just to pass the tests.

Quoted 7 lines
Quoted 3 lines

So you would prefer a more general test in some common place (like __ip6_local_out() ) to avoid any packets with ::1 on other devices as loopback ?

No, we should not even accept packets for ::1 from outside of the box. Something like this.

Yes I was thinking about nearly the same patch now :-)

Quoted 46 lines

---
ipv6: Drop packets for loopback address from outside of the box.

include/net/ipv6.h +6 -0
index e0a612b..f422f72 100644
@@ -367,6 +367,12 @@ static inline int ipv6_addr_any(const struct in6_addr *a)
 		 a->s6_addr32[2] | a->s6_addr32[3] ) == 0); 
 }
 
+static inline int ipv6_addr_loopback(const struct in6_addr *a)
+{
+	return ((a->s6_addr32[0] | a->s6_addr32[1] |
+		 a->s6_addr32[2] | (a->s6_addr32[3] ^ htonl(1))) == 0);
+}
+
 static inline int ipv6_addr_v4mapped(const struct in6_addr *a)
 {
 	return ((a->s6_addr32[0] | a->s6_addr32[1] |
net/ipv6/ip6_input.c +9 -1
index 4e5c861..17eb48b 100644
@@ -102,6 +102,15 @@ int ipv6_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt
 	if (hdr->version != 6)
 		goto err;
 
+	/*
+	 * RFC4291 2.5.3
+	 * A packet received on an interface with a destination address
+	 * of loopback must be dropped.
+	 */
+	if (!(dev->flags & IFF_LOOPBACK) &&
+	    ipv6_addr_loopback(&hdr->daddr))
+		goto err;
+
 	skb->transport_header = skb->network_header + sizeof(*hdr);
 	IP6CB(skb)->nhoff = offsetof(struct ipv6hdr, nexthdr);
 
 
 
--yoshfuji
Signature · 4 lines
Karsten Keil
SuSE Labs
ISDN and VOIP development
SUSE LINUX Products GmbH, Maxfeldstr.5 90409 Nuernberg, GF: Markus Rex, HRB 16746 (AG Nuernberg)
#6 lore raw
In reply to YOSHIFUJI Hideaki / 吉藤英明

Hi Yoshfuji,

On Wed, Jun 18, 2008 at 11:36:07PM +0900, YOSHIFUJI Hideaki / 吉藤英明 wrote:

Verified that this patch fix the TAHI issue and that ping6 ::1 still works. So this should go in.

...

Quoted 49 lines

ipv6: Drop packets for loopback address from outside of the box.

include/net/ipv6.h +6 -0
index e0a612b..f422f72 100644
@@ -367,6 +367,12 @@ static inline int ipv6_addr_any(const struct in6_addr *a)
 		 a->s6_addr32[2] | a->s6_addr32[3] ) == 0); 
 }
 
+static inline int ipv6_addr_loopback(const struct in6_addr *a)
+{
+	return ((a->s6_addr32[0] | a->s6_addr32[1] |
+		 a->s6_addr32[2] | (a->s6_addr32[3] ^ htonl(1))) == 0);
+}
+
 static inline int ipv6_addr_v4mapped(const struct in6_addr *a)
 {
 	return ((a->s6_addr32[0] | a->s6_addr32[1] |
net/ipv6/ip6_input.c +9 -2
index 4e5c861..17eb48b 100644
@@ -102,6 +102,15 @@ int ipv6_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt
 	if (hdr->version != 6)
 		goto err;
 
+	/*
+	 * RFC4291 2.5.3
+	 * A packet received on an interface with a destination address
+	 * of loopback must be dropped.
+	 */
+	if (!(dev->flags & IFF_LOOPBACK) &&
+	    ipv6_addr_loopback(&hdr->daddr))
+		goto err;
+
 	skb->transport_header = skb->network_header + sizeof(*hdr);
 	IP6CB(skb)->nhoff = offsetof(struct ipv6hdr, nexthdr);
 
 
 
--yoshfuji
--

To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 4 lines
Karsten Keil
SuSE Labs
ISDN and VOIP development
SUSE LINUX Products GmbH, Maxfeldstr.5 90409 Nuernberg, GF: Markus Rex, HRB 16746 (AG Nuernberg)
maintainer
#7 lore raw

From: Karsten Keil <[email protected]>
Date: Wed, 18 Jun 2008 19:49:07 +0200

Quoted 2 lines

Verified that this patch fix the TAHI issue and that ping6 ::1 still works. So this should go in.

I've added the patch to net-2.6, as below. Thanks everyone!

ipv6: Drop packets for loopback address from outside of the box.

[ Based upon original report and patch by Karsten Keil. Karsten
has verified that this fixes the TAHI test case "ICMPv6 test v6LC.5.1.2 Part F". -DaveM ]

---
 include/net/ipv6.h   |    6 ++++++
 net/ipv6/ip6_input.c |    9 +++++++++
 2 files changed, 15 insertions(+), 0 deletions(-)
include/net/ipv6.h +6 -0
index e0a612b..f422f72 100644
@@ -367,6 +367,12 @@ static inline int ipv6_addr_any(const struct in6_addr *a)
 		 a->s6_addr32[2] | a->s6_addr32[3] ) == 0); 
 }
 
+static inline int ipv6_addr_loopback(const struct in6_addr *a)
+{
+	return ((a->s6_addr32[0] | a->s6_addr32[1] |
+		 a->s6_addr32[2] | (a->s6_addr32[3] ^ htonl(1))) == 0);
+}
+
 static inline int ipv6_addr_v4mapped(const struct in6_addr *a)
 {
 	return ((a->s6_addr32[0] | a->s6_addr32[1] |
net/ipv6/ip6_input.c +9 -0
index 4e5c861..17eb48b 100644
@@ -102,6 +102,15 @@ int ipv6_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt
 	if (hdr->version != 6)
 		goto err;
 
+	/*
+	 * RFC4291 2.5.3
+	 * A packet received on an interface with a destination address
+	 * of loopback must be dropped.
+	 */
+	if (!(dev->flags & IFF_LOOPBACK) &&
+	    ipv6_addr_loopback(&hdr->daddr))
+		goto err;
+
 	skb->transport_header = skb->network_header + sizeof(*hdr);
 	IP6CB(skb)->nhoff = offsetof(struct ipv6hdr, nexthdr);
 
Signature · 1 line
1.5.6.rc3.21.g8c6b5