mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-29 03:01:39 -04:00
ipv6: protect protocols not handling ipv4 from v4 connection/bind attempts
Some ipv6 protocols cannot handle ipv4 addresses, so we must not allow connecting and binding to them. sendmsg logic does already check msg->name for this but must trust already connected sockets which could be set up for connection to ipv4 address family. Per-socket flag ipv6only is of no use here, as it is under users control by setsockopt. Signed-off-by: Hannes Frederic Sowa <[email protected]> Signed-off-by: David S. Miller <[email protected]>
This commit is contained in:
parent
446fab5933
commit
82b276cd2b
6 changed files with 24 additions and 2 deletions
|
|
@ -205,6 +205,16 @@ out:
|
|||
}
|
||||
EXPORT_SYMBOL_GPL(ip6_datagram_connect);
|
||||
|
||||
int ip6_datagram_connect_v6_only(struct sock *sk, struct sockaddr *uaddr,
|
||||
int addr_len)
|
||||
{
|
||||
DECLARE_SOCKADDR(struct sockaddr_in6 *, sin6, uaddr);
|
||||
if (sin6->sin6_family != AF_INET6)
|
||||
return -EAFNOSUPPORT;
|
||||
return ip6_datagram_connect(sk, uaddr, addr_len);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(ip6_datagram_connect_v6_only);
|
||||
|
||||
void ipv6_icmp_error(struct sock *sk, struct sk_buff *skb, int err,
|
||||
__be16 port, u32 info, u8 *payload)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ struct proto pingv6_prot = {
|
|||
.owner = THIS_MODULE,
|
||||
.init = ping_init_sock,
|
||||
.close = ping_close,
|
||||
.connect = ip6_datagram_connect,
|
||||
.connect = ip6_datagram_connect_v6_only,
|
||||
.disconnect = udp_disconnect,
|
||||
.setsockopt = ipv6_setsockopt,
|
||||
.getsockopt = ipv6_getsockopt,
|
||||
|
|
|
|||
|
|
@ -250,6 +250,10 @@ static int rawv6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
|
|||
|
||||
if (addr_len < SIN6_LEN_RFC2133)
|
||||
return -EINVAL;
|
||||
|
||||
if (addr->sin6_family != AF_INET6)
|
||||
return -EINVAL;
|
||||
|
||||
addr_type = ipv6_addr_type(&addr->sin6_addr);
|
||||
|
||||
/* Raw sockets are IPv6 only */
|
||||
|
|
@ -1209,7 +1213,7 @@ struct proto rawv6_prot = {
|
|||
.owner = THIS_MODULE,
|
||||
.close = rawv6_close,
|
||||
.destroy = raw6_destroy,
|
||||
.connect = ip6_datagram_connect,
|
||||
.connect = ip6_datagram_connect_v6_only,
|
||||
.disconnect = udp_disconnect,
|
||||
.ioctl = rawv6_ioctl,
|
||||
.init = rawv6_init_sk,
|
||||
|
|
|
|||
Loading…
Reference in a new issue