diff options
author | Nayana Bidari <nybidari@google.com> | 2020-12-11 13:29:05 -0800 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-12-11 13:31:28 -0800 |
commit | d45420b1528b8ad23e8f12fe81fb9cc148b83012 (patch) | |
tree | 35df2b3965fbe23b8772e49a4deae0ffb14ddd10 /pkg/tcpip | |
parent | 5bdc167d174515eb51ba1bb0f4b4d1e484e8996c (diff) |
Fix panic when IPv4 address is used in sendmsg for IPv6 sockets
We do not rely on error for getsockopt options(which have boolean values)
anymore. This will cause issue in sendmsg where we used to return error
for IPV6_V6Only option. Fix the panic by returning error (for sockets other
than TCP and UDP) if the address does not match the type(AF_INET/AF_INET6) of
the socket.
PiperOrigin-RevId: 347063838
Diffstat (limited to 'pkg/tcpip')
-rw-r--r-- | pkg/tcpip/transport/raw/endpoint.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/pkg/tcpip/transport/raw/endpoint.go b/pkg/tcpip/transport/raw/endpoint.go index 90b032d85..d9a664c03 100644 --- a/pkg/tcpip/transport/raw/endpoint.go +++ b/pkg/tcpip/transport/raw/endpoint.go @@ -227,6 +227,13 @@ func (e *endpoint) Write(p tcpip.Payloader, opts tcpip.WriteOptions) (int64, <-c return 0, nil, tcpip.ErrInvalidOptionValue } + if opts.To != nil { + // Raw sockets do not support sending to a IPv4 address on a IPv6 endpoint. + if e.TransportEndpointInfo.NetProto == header.IPv6ProtocolNumber && len(opts.To.Addr) != header.IPv6AddressSize { + return 0, nil, tcpip.ErrInvalidOptionValue + } + } + n, ch, err := e.write(p, opts) switch err { case nil: @@ -397,6 +404,11 @@ func (*endpoint) Disconnect() *tcpip.Error { // Connect implements tcpip.Endpoint.Connect. func (e *endpoint) Connect(addr tcpip.FullAddress) *tcpip.Error { + // Raw sockets do not support connecting to a IPv4 address on a IPv6 endpoint. + if e.TransportEndpointInfo.NetProto == header.IPv6ProtocolNumber && len(addr.Addr) != header.IPv6AddressSize { + return tcpip.ErrInvalidOptionValue + } + e.mu.Lock() defer e.mu.Unlock() |