netstack: verify stack supports protocol before finding route

Not doing so breaks the assumption of later code that netProto is supported by
the stack.

PiperOrigin-RevId: 571436763
This commit is contained in:
Kevin Krakauer
2023-10-06 14:36:44 -07:00
committed by gVisor bot
parent ba1c60263e
commit 9cb26fd34f
+5
View File
@@ -1305,6 +1305,11 @@ func (s *Stack) FindRoute(id tcpip.NICID, localAddr, remoteAddr tcpip.Address, n
s.mu.RLock()
defer s.mu.RUnlock()
// Reject attempts to use unsupported protocols.
if !s.CheckNetworkProtocol(netProto) {
return nil, &tcpip.ErrUnknownProtocol{}
}
isLinkLocal := header.IsV6LinkLocalUnicastAddress(remoteAddr) || header.IsV6LinkLocalMulticastAddress(remoteAddr)
isLocalBroadcast := remoteAddr == header.IPv4Broadcast
isMulticast := header.IsV4MulticastAddress(remoteAddr) || header.IsV6MulticastAddress(remoteAddr)