All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hannes Frederic Sowa <hannes@stressinduktion.org>
To: netdev@vger.kernel.org
Subject: [PATCH net-next RFC v1 14/27] afnetns: check for afnetns in inet6_bind
Date: Mon, 13 Mar 2017 00:01:38 +0100	[thread overview]
Message-ID: <20170312230151.5185-15-hannes@stressinduktion.org> (raw)
In-Reply-To: <20170312230151.5185-1-hannes@stressinduktion.org>

Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
---
 include/net/addrconf.h |  3 ++-
 net/ipv6/addrconf.c    | 12 ++++++++++--
 net/ipv6/af_inet6.c    |  7 +++++--
 net/ipv6/ndisc.c       |  4 ++--
 net/ipv6/route.c       |  2 +-
 5 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/include/net/addrconf.h b/include/net/addrconf.h
index 17c6fd84e28780..e3f1920ca57968 100644
--- a/include/net/addrconf.h
+++ b/include/net/addrconf.h
@@ -63,7 +63,8 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg);
 
 int ipv6_chk_addr(struct net *net, const struct in6_addr *addr,
 		  const struct net_device *dev, int strict);
-int ipv6_chk_addr_and_flags(struct net *net, const struct in6_addr *addr,
+int ipv6_chk_addr_and_flags(struct net *net, struct afnetns *afnetns,
+			    const struct in6_addr *addr,
 			    const struct net_device *dev, int strict,
 			    u32 banned_flags);
 
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index c67f6d3c5b9a7a..2e546584695118 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -1776,11 +1776,13 @@ static int ipv6_count_addresses(struct inet6_dev *idev)
 int ipv6_chk_addr(struct net *net, const struct in6_addr *addr,
 		  const struct net_device *dev, int strict)
 {
-	return ipv6_chk_addr_and_flags(net, addr, dev, strict, IFA_F_TENTATIVE);
+	return ipv6_chk_addr_and_flags(net, NULL, addr, dev, strict,
+				       IFA_F_TENTATIVE);
 }
 EXPORT_SYMBOL(ipv6_chk_addr);
 
-int ipv6_chk_addr_and_flags(struct net *net, const struct in6_addr *addr,
+int ipv6_chk_addr_and_flags(struct net *net, struct afnetns *afnetns,
+			    const struct in6_addr *addr,
 			    const struct net_device *dev, int strict,
 			    u32 banned_flags)
 {
@@ -1792,6 +1794,12 @@ int ipv6_chk_addr_and_flags(struct net *net, const struct in6_addr *addr,
 	hlist_for_each_entry_rcu(ifp, &inet6_addr_lst[hash], addr_lst) {
 		if (!net_eq(dev_net(ifp->idev->dev), net))
 			continue;
+
+#if IS_ENABLED(CONFIG_AFNETNS)
+		if (afnetns && ifp->afnetns != afnetns)
+			continue;
+#endif
+
 		/* Decouple optimistic from tentative for evaluation here.
 		 * Ban optimistic addresses explicitly, when required.
 		 */
diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
index f9367c507573bc..ffb116297c0950 100644
--- a/net/ipv6/af_inet6.c
+++ b/net/ipv6/af_inet6.c
@@ -362,8 +362,11 @@ int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
 			if (!(addr_type & IPV6_ADDR_MULTICAST))	{
 				if (!net->ipv6.sysctl.ip_nonlocal_bind &&
 				    !(inet->freebind || inet->transparent) &&
-				    !ipv6_chk_addr(net, &addr->sin6_addr,
-						   dev, 0)) {
+				    !ipv6_chk_addr_and_flags(net,
+							     sock_afnetns(sk),
+							     &addr->sin6_addr,
+							     dev, 0,
+							     IFA_F_TENTATIVE)) {
 					err = -EADDRNOTAVAIL;
 					goto out_unlock;
 				}
diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c
index 7ebac630d3c603..4415659f8cfb0d 100644
--- a/net/ipv6/ndisc.c
+++ b/net/ipv6/ndisc.c
@@ -693,8 +693,8 @@ static void ndisc_solicit(struct neighbour *neigh, struct sk_buff *skb)
 	struct in6_addr *target = (struct in6_addr *)&neigh->primary_key;
 	int probes = atomic_read(&neigh->probes);
 
-	if (skb && ipv6_chk_addr_and_flags(dev_net(dev), &ipv6_hdr(skb)->saddr,
-					   dev, 1,
+	if (skb && ipv6_chk_addr_and_flags(dev_net(dev), NULL,
+					   &ipv6_hdr(skb)->saddr, dev, 1,
 					   IFA_F_TENTATIVE|IFA_F_OPTIMISTIC))
 		saddr = &ipv6_hdr(skb)->saddr;
 	probes -= NEIGH_VAR(neigh->parms, UCAST_PROBES);
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 229bfcc451ef50..87d87c5413d71e 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -2007,7 +2007,7 @@ static struct rt6_info *ip6_route_info_create(struct fib6_config *cfg)
 		 * prefix route was assigned to, which might be non-loopback.
 		 */
 		err = -EINVAL;
-		if (ipv6_chk_addr_and_flags(net, gw_addr,
+		if (ipv6_chk_addr_and_flags(net, NULL, gw_addr,
 					    gwa_type & IPV6_ADDR_LINKLOCAL ?
 					    dev : NULL, 0, 0))
 			goto out;
-- 
2.9.3

  parent reply	other threads:[~2017-03-12 23:02 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-12 23:01 [PATCH net-next RFC v1 00/27] afnetns: new namespace type for separation on protocol level Hannes Frederic Sowa
2017-03-12 23:01 ` [PATCH net-next RFC v1 01/27] afnetns: add CLONE_NEWAFNET flag Hannes Frederic Sowa
2017-03-12 23:01 ` [PATCH net-next RFC v1 02/27] afnetns: basic namespace operations and representations Hannes Frederic Sowa
2017-03-12 23:01 ` [PATCH net-next RFC v1 03/27] afnetns: prepare for integration into ipv4 Hannes Frederic Sowa
2017-03-12 23:01 ` [PATCH net-next RFC v1 04/27] afnetns: add net_afnetns Hannes Frederic Sowa
2017-03-12 23:01 ` [PATCH net-next RFC v1 05/27] afnetns: ipv6 integration Hannes Frederic Sowa
2017-03-12 23:01 ` [PATCH net-next RFC v1 06/27] afnetns: put afnetns pointer into struct sock Hannes Frederic Sowa
2017-03-12 23:01 ` [PATCH net-next RFC v1 07/27] ipv4: introduce ifa_find_rcu Hannes Frederic Sowa
2017-03-12 23:01 ` [PATCH net-next RFC v1 08/27] afnetns: factor out inet_allow_bind Hannes Frederic Sowa
2017-03-12 23:01 ` [PATCH net-next RFC v1 09/27] afnetns: add sock_afnetns Hannes Frederic Sowa
2017-03-12 23:01 ` [PATCH net-next RFC v1 10/27] afnetns: add ifa_find_afnetns_rcu Hannes Frederic Sowa
2017-03-12 23:01 ` [PATCH net-next RFC v1 11/27] afnetns: validate afnetns in inet_allow_bind Hannes Frederic Sowa
2017-03-12 23:01 ` [PATCH net-next RFC v1 12/27] afnetns: ipv4/udp integration Hannes Frederic Sowa
2017-03-12 23:01 ` [PATCH net-next RFC v1 13/27] afnetns: use inet_allow_bind in inet6_bind Hannes Frederic Sowa
2017-03-12 23:01 ` Hannes Frederic Sowa [this message]
2017-03-12 23:01 ` [PATCH net-next RFC v1 15/27] afnetns: add ipv6_get_ifaddr_afnetns_rcu Hannes Frederic Sowa
2017-03-12 23:01 ` [PATCH net-next RFC v1 16/27] afnetns: add udpv6 support Hannes Frederic Sowa
2017-03-12 23:01 ` [PATCH net-next RFC v1 17/27] afnetns: introduce __inet_select_addr Hannes Frederic Sowa
2017-03-12 23:01 ` [PATCH net-next RFC v1 18/27] afnetns: afnetns should influence source address selection Hannes Frederic Sowa
2017-03-12 23:01 ` [PATCH net-next RFC v1 19/27] afnetns: add afnetns support for tcpv4 Hannes Frederic Sowa
2017-03-12 23:01 ` [PATCH net-next RFC v1 20/27] ipv6: move ipv6_get_ifaddr to vmlinux in case ipv6 is build as module Hannes Frederic Sowa
2017-03-12 23:01 ` [PATCH net-next RFC v1 21/27] afnetns: add support for tcpv6 Hannes Frederic Sowa
2017-03-12 23:01 ` [PATCH net-next RFC v1 22/27] afnetns: track owning namespace for inet_bind Hannes Frederic Sowa
2017-03-12 23:01 ` [PATCH net-next RFC v1 23/27] afnetns: use user_ns from afnetns for checking for binding to port < 1024 Hannes Frederic Sowa
2017-03-12 23:01 ` [PATCH net-next RFC v1 24/27] afnetns: check afnetns user_ns in inet6_bind Hannes Frederic Sowa
2017-03-12 23:01 ` [PATCH net-next RFC v1 25/27] afnetns: ipv4: inherit afnetns from calling application Hannes Frederic Sowa
2017-03-12 23:01 ` [PATCH net-next RFC v1 26/27] afnetns: ipv6: " Hannes Frederic Sowa
2017-03-12 23:01 ` [PATCH net-next RFC v1 27/27] afnetns: allow only whitelisted protocols to operate inside afnetns Hannes Frederic Sowa
2017-03-12 23:26 ` [PATCH net-next RFC v1 00/27] afnetns: new namespace type for separation on protocol level David Miller
2017-03-12 23:44   ` Hannes Frederic Sowa
     [not found]     ` <1489362279.2283.1.camel-tFNcAqjVMyqKXQKiL6tip0B+6BGkLq7r@public.gmane.org>
2017-03-13 19:56       ` Michael Kerrisk
     [not found]         ` <CAHO5Pa1s949dohzEEE68Ux=mXA7N7sR-U98Jwjvx1a_A5AhFEw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-03-13 22:06           ` Eric W. Biederman
2017-03-14 10:18             ` Hannes Frederic Sowa
     [not found]               ` <cc9229f8-a389-87cc-2512-ee00e200a7c3-tFNcAqjVMyqKXQKiL6tip0B+6BGkLq7r@public.gmane.org>
2017-03-14 17:46                 ` Eric W. Biederman

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=20170312230151.5185-15-hannes@stressinduktion.org \
    --to=hannes@stressinduktion.org \
    --cc=netdev@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.