From: David Ahern Date: Thu, 3 Jan 2019 02:57:09 +0000 (-0800) Subject: ipv6: Consider sk_bound_dev_if when binding a socket to an address X-Git-Tag: rel_imx_4.19.35_1.1.0~6945 X-Git-Url: https://git.somdevices.com/?a=commitdiff_plain;h=7e9a6476aaf5b03bcebbcc37ae9802f1525d329d;p=linux.git ipv6: Consider sk_bound_dev_if when binding a socket to an address [ Upstream commit c5ee066333ebc322a24a00a743ed941a0c68617e ] IPv6 does not consider if the socket is bound to a device when binding to an address. The result is that a socket can be bound to eth0 and then bound to the address of eth1. If the device is a VRF, the result is that a socket can only be bound to an address in the default VRF. Resolve by considering the device if sk_bound_dev_if is set. This problem exists from the beginning of git history. Signed-off-by: David Ahern Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c index 506b2ae07bb3..79fcd9550fd2 100644 --- a/net/ipv6/af_inet6.c +++ b/net/ipv6/af_inet6.c @@ -361,6 +361,9 @@ static int __inet6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len, err = -EINVAL; goto out_unlock; } + } + + if (sk->sk_bound_dev_if) { dev = dev_get_by_index_rcu(net, sk->sk_bound_dev_if); if (!dev) { err = -ENODEV;