Skip to contentSkip to conversation

sctp: full support for ipv6 ip_nonlocal_bind & IP_FREEBIND

PATCH Applied Laszlo Toth 3 participants 3 messages Oct 23, 2017 – Oct 24, 2017

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

PATCH v2 1/1 sctp: full support for ipv6 ip_nonlocal_bind & IP_FREEBIND

Commit 9b9742022888 ("sctp: support ipv6 nonlocal bind") introduced support for the above options as v4 sctp did, so patched sctp_v6_available().

In the v4 implementation it's enough, because sctp_inet_bind_verify() just returns with sctp_v4_available(). However sctp_inet6_bind_verify() has an extra check before that for link-local scope_id, which won't respect the above options.

Added the checks before calling ipv6_chk_addr(), but not before the validation of scope_id.

before (w/ both options):
./v6test fe80::10 sctp
bind failed, errno: 99 (Cannot assign requested address) ./v6test fe80::10 tcp
bind success, errno: 0 (Success)

after (w/ both options):
./v6test fe80::10 sctp
bind success, errno: 0 (Success)

---
changed in v2:
- fixed indentation

 net/sctp/ipv6.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
net/sctp/ipv6.c +4 -2
index 51c4887..7fe9e1d1 100644
@@ -882,8 +882,10 @@ static int sctp_inet6_bind_verify(struct sctp_sock *opt, union sctp_addr *addr)
 			net = sock_net(&opt->inet.sk);
 			rcu_read_lock();
 			dev = dev_get_by_index_rcu(net, addr->v6.sin6_scope_id);
-			if (!dev ||
-			    !ipv6_chk_addr(net, &addr->v6.sin6_addr, dev, 0)) {
+			if (!dev || !(opt->inet.freebind ||
+				      net->ipv6.sysctl.ip_nonlocal_bind ||
+				      ipv6_chk_addr(net, &addr->v6.sin6_addr,
+						    dev, 0))) {
 				rcu_read_unlock();
 				return 0;
 			}
Signature · 1 line
2.7.4
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 48 lines · Laszlo Toth

Commit 9b9742022888 ("sctp: support ipv6 nonlocal bind") introduced support for the above options as v4 sctp did, so patched sctp_v6_available().

In the v4 implementation it's enough, because sctp_inet_bind_verify() just returns with sctp_v4_available(). However sctp_inet6_bind_verify() has an extra check before that for link-local scope_id, which won't respect the above options.

Added the checks before calling ipv6_chk_addr(), but not before the validation of scope_id.

before (w/ both options):
./v6test fe80::10 sctp
bind failed, errno: 99 (Cannot assign requested address) ./v6test fe80::10 tcp
bind success, errno: 0 (Success)

after (w/ both options):
./v6test fe80::10 sctp
bind success, errno: 0 (Success)

---
changed in v2:
- fixed indentation

 net/sctp/ipv6.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
net/sctp/ipv6.c +4 -3
index 51c4887..7fe9e1d1 100644
@@ -882,8 +882,10 @@ static int sctp_inet6_bind_verify(struct sctp_sock *opt, union sctp_addr *addr)
                        net = sock_net(&opt->inet.sk);
                        rcu_read_lock();
                        dev = dev_get_by_index_rcu(net, addr->v6.sin6_scope_id);
-                       if (!dev ||
-                           !ipv6_chk_addr(net, &addr->v6.sin6_addr, dev, 0)) {
+                       if (!dev || !(opt->inet.freebind ||
+                                     net->ipv6.sysctl.ip_nonlocal_bind ||
+                                     ipv6_chk_addr(net, &addr->v6.sin6_addr,
+                                                   dev, 0))) {
                                rcu_read_unlock();
                                return 0;
                        }
--
Quoted 2 lines

2.7.4

Thanks.

maintainer Applied
#2 lore raw
In reply to Laszlo Toth

From: Laszlo Toth <[email protected]>
Date: Mon, 23 Oct 2017 19:19:33 +0200

Quoted 18 lines

Commit 9b9742022888 ("sctp: support ipv6 nonlocal bind") introduced support for the above options as v4 sctp did, so patched sctp_v6_available().

In the v4 implementation it's enough, because sctp_inet_bind_verify() just returns with sctp_v4_available(). However sctp_inet6_bind_verify() has an extra check before that for link-local scope_id, which won't respect the above options.

Added the checks before calling ipv6_chk_addr(), but not before the validation of scope_id.

before (w/ both options):
./v6test fe80::10 sctp
bind failed, errno: 99 (Cannot assign requested address) ./v6test fe80::10 tcp
bind success, errno: 0 (Success)

Quoted 5 lines

after (w/ both options):
./v6test fe80::10 sctp
bind success, errno: 0 (Success)

Applied.