Skip to content

Commit ec90ad3

Browse files
dsaherndavem330
authored andcommitted
ipv6: Consider sk_bound_dev_if when binding a socket to a v4 mapped address
Similar to c5ee066 ("ipv6: Consider sk_bound_dev_if when binding a socket to an address"), binding a socket to v4 mapped addresses needs to consider if the socket is bound to a device. This problem also exists from the beginning of git history. Signed-off-by: David Ahern <dsahern@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent ae84e4a commit ec90ad3

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

net/ipv6/af_inet6.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ static int __inet6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len,
310310

311311
/* Check if the address belongs to the host. */
312312
if (addr_type == IPV6_ADDR_MAPPED) {
313+
struct net_device *dev = NULL;
313314
int chk_addr_ret;
314315

315316
/* Binding to v4-mapped address on a v6-only socket
@@ -320,9 +321,17 @@ static int __inet6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len,
320321
goto out;
321322
}
322323

324+
if (sk->sk_bound_dev_if) {
325+
dev = dev_get_by_index_rcu(net, sk->sk_bound_dev_if);
326+
if (!dev) {
327+
err = -ENODEV;
328+
goto out;
329+
}
330+
}
331+
323332
/* Reproduce AF_INET checks to make the bindings consistent */
324333
v4addr = addr->sin6_addr.s6_addr32[3];
325-
chk_addr_ret = inet_addr_type(net, v4addr);
334+
chk_addr_ret = inet_addr_type_dev_table(net, dev, v4addr);
326335
if (!inet_can_nonlocal_bind(net, inet) &&
327336
v4addr != htonl(INADDR_ANY) &&
328337
chk_addr_ret != RTN_LOCAL &&

0 commit comments

Comments
 (0)