From: Shan Wei <shanwei@cn.fujitsu.com>
To: Albert Pretorius <albertpretorius@yahoo.co.uk>
Cc: netdev@vger.kernel.org,
"yoshfuji@linux-ipv6.org >> YOSHIFUJI Hideaki"
<yoshfuji@linux-ipv6.org>, David Miller <davem@davemloft.net>,
pekkas@netcore.fi, jmorris@namei.org
Subject: Re: IPV6 loopback bound socket succeeds connecting to remote host
Date: Wed, 01 Dec 2010 16:18:35 +0800 [thread overview]
Message-ID: <4CF604DB.8000302@cn.fujitsu.com> (raw)
In-Reply-To: <328335.88387.qm@web29006.mail.ird.yahoo.com>
Albert Pretorius wrote, at 11/29/2010 06:55 PM:
> Hi
> I found a problem with ipv6 when a UDP socket is bound to loopback (::1) and connecting to a remote address. The same applies to TCP.
> Any data sent ends up on the remote host with a source address of loopback. The expected result of the connect should be EINVAL just like it is for ipv4.
> Here is a possible patch that fixes this problem below. I tested it on 2.6.37-rc3 using a tool I put on http://www.gitorious.org/bindconnect
Indeed, there is an guide in RFC4291 for us to use IPv6 loopback address.
See RFC4291 2.5.3 section:
The loopback address must not be used as the source address in IPv6
packets that are sent outside of a single node. An IPv6 packet with
a destination address of loopback must never be sent outside of a
single node and must never be forwarded by an IPv6 router. A packet
received on an interface with a destination address of loopback must
be dropped.
I think it make nonsense to translate data between loopback device and
other e.g. eth0 device in same machine. With your patch, also can't establish
a tcp connection from loopback device to other device in same host.
=====
[PATCH] ipv6: forbid to send ipv6 packet from loopback to other device in same host
According to 2.5.3 section of RFC4291, commit f630e43 dropped the received packet with
loopback as destination address. Now forbid to send packet from loopback to other
device. Original patch is provided by Albert Pretorius.
Reported-by: Albert Pretorius <albertpretorius@yahoo.co.uk>
Signed-off-by: Shan Wei <shanwei@cn.fujitsu.com>
---
net/ipv6/ip6_output.c | 8 ++++++++
1 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
index 99157b4..6b6cf84 100644
--- a/net/ipv6/ip6_output.c
+++ b/net/ipv6/ip6_output.c
@@ -927,6 +927,7 @@ static int ip6_dst_lookup_tail(struct sock *sk,
{
int err;
struct net *net = sock_net(sk);
+ struct net_device *dev_out;
if (*dst == NULL)
*dst = ip6_route_output(net, sk, fl);
@@ -934,6 +935,13 @@ static int ip6_dst_lookup_tail(struct sock *sk,
if ((err = (*dst)->error))
goto out_err_release;
+ dev_out = ip6_dst_idev(*dst)->dev;
+ if (dev_out && ipv6_addr_loopback(&fl->fl6_src) &&
+ !(dev_out->flags & IFF_LOOPBACK)) {
+ err = -EINVAL;
+ goto out_err_release;
+ }
+
if (ipv6_addr_any(&fl->fl6_src)) {
err = ipv6_dev_get_saddr(net, ip6_dst_idev(*dst)->dev,
&fl->fl6_dst,
--
1.6.3.3
next prev parent reply other threads:[~2010-12-01 8:20 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-29 10:55 IPV6 loopback bound socket succeeds connecting to remote host Albert Pretorius
2010-12-01 8:18 ` Shan Wei [this message]
2010-12-02 7:45 ` Albert Pretorius
2010-12-02 8:41 ` Shan Wei
2010-12-16 20:18 ` David Miller
2010-12-20 6:31 ` Shan Wei
2010-12-20 6:43 ` David Miller
2010-12-22 7:06 ` Shan Wei
2010-12-29 16:53 ` Albert Pretorius
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=4CF604DB.8000302@cn.fujitsu.com \
--to=shanwei@cn.fujitsu.com \
--cc=albertpretorius@yahoo.co.uk \
--cc=davem@davemloft.net \
--cc=jmorris@namei.org \
--cc=netdev@vger.kernel.org \
--cc=pekkas@netcore.fi \
--cc=yoshfuji@linux-ipv6.org \
/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;
as well as URLs for NNTP newsgroup(s).