diff mbox series

[net-next,v1] net/ipv6: allow any source address for sendmsg pktinfo with ip_nonlocal_bind

Message ID 20180725111914.28093-1-vincent@bernat.im
State Accepted, archived
Delegated to: David Miller
Headers show
Series [net-next,v1] net/ipv6: allow any source address for sendmsg pktinfo with ip_nonlocal_bind | expand

Commit Message

Vincent Bernat July 25, 2018, 11:19 a.m. UTC
When freebind feature is set of an IPv6 socket, any source address can
be used when sending UDP datagrams using IPv6 PKTINFO ancillary
message. Global non-local bind feature was added in commit
35a256fee52c ("ipv6: Nonlocal bind") for IPv6. This commit also allows
IPv6 source address spoofing when non-local bind feature is enabled.

Signed-off-by: Vincent Bernat <vincent@bernat.im>
---
 net/ipv6/datagram.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

David Miller July 29, 2018, 7:28 p.m. UTC | #1
From: Vincent Bernat <vincent@bernat.im>
Date: Wed, 25 Jul 2018 13:19:13 +0200

> When freebind feature is set of an IPv6 socket, any source address can
> be used when sending UDP datagrams using IPv6 PKTINFO ancillary
> message. Global non-local bind feature was added in commit
> 35a256fee52c ("ipv6: Nonlocal bind") for IPv6. This commit also allows
> IPv6 source address spoofing when non-local bind feature is enabled.
> 
> Signed-off-by: Vincent Bernat <vincent@bernat.im>

This definitely seems to make sense.  And is consistent with the other
tests involving freebind and transparent.

This test involving ip_nonlocal_bind, freeebind, and transparent happens
in several locations.  Perhaps we should add a helper function for this?

Thanks.
Vincent Bernat July 30, 2018, 6:08 a.m. UTC | #2
❦ 29 juillet 2018 12:28 -0700, David Miller <davem@davemloft.net> :

>> When freebind feature is set of an IPv6 socket, any source address can
>> be used when sending UDP datagrams using IPv6 PKTINFO ancillary
>> message. Global non-local bind feature was added in commit
>> 35a256fee52c ("ipv6: Nonlocal bind") for IPv6. This commit also allows
>> IPv6 source address spoofing when non-local bind feature is enabled.
>> 
>> Signed-off-by: Vincent Bernat <vincent@bernat.im>
>
> This definitely seems to make sense.  And is consistent with the other
> tests involving freebind and transparent.
>
> This test involving ip_nonlocal_bind, freeebind, and transparent happens
> in several locations.  Perhaps we should add a helper function for
> this?

Yes, I can do that. Should I also include one for SCTP?
David Miller July 30, 2018, 4:08 p.m. UTC | #3
From: Vincent Bernat <vincent@bernat.im>
Date: Mon, 30 Jul 2018 08:08:12 +0200

>  ❦ 29 juillet 2018 12:28 -0700, David Miller <davem@davemloft.net> :
> 
>>> When freebind feature is set of an IPv6 socket, any source address can
>>> be used when sending UDP datagrams using IPv6 PKTINFO ancillary
>>> message. Global non-local bind feature was added in commit
>>> 35a256fee52c ("ipv6: Nonlocal bind") for IPv6. This commit also allows
>>> IPv6 source address spoofing when non-local bind feature is enabled.
>>> 
>>> Signed-off-by: Vincent Bernat <vincent@bernat.im>
>>
>> This definitely seems to make sense.  And is consistent with the other
>> tests involving freebind and transparent.
>>
>> This test involving ip_nonlocal_bind, freeebind, and transparent happens
>> in several locations.  Perhaps we should add a helper function for
>> this?
> 
> Yes, I can do that. Should I also include one for SCTP?

If the helper for SCTP needs to be different and thus will only be
used in one place, probably not.  The whole idea is to remove
duplicated code, and prevent someone in the future from forgetting
to test all three values in these situations.

Thanks.
diff mbox series

Patch

diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
index 201306b9b5ea..c46936563b15 100644
--- a/net/ipv6/datagram.c
+++ b/net/ipv6/datagram.c
@@ -800,7 +800,8 @@  int ip6_datagram_send_ctl(struct net *net, struct sock *sk,
 
 			if (addr_type != IPV6_ADDR_ANY) {
 				int strict = __ipv6_addr_src_scope(addr_type) <= IPV6_ADDR_SCOPE_LINKLOCAL;
-				if (!(inet_sk(sk)->freebind || inet_sk(sk)->transparent) &&
+				if (!(net->ipv6.sysctl.ip_nonlocal_bind ||
+				      inet_sk(sk)->freebind || inet_sk(sk)->transparent) &&
 				    !ipv6_chk_addr_and_flags(net, &src_info->ipi6_addr,
 							     dev, !strict, 0,
 							     IFA_F_TENTATIVE) &&