scionproto / scion

SCION Internet Architecture
https://www.scion-architecture.net/
Apache License 2.0
369 stars 156 forks source link

snet: discard stray incoming packets on Dialed conn #4546

Open matzf opened 2 weeks ago

matzf commented 2 weeks ago

Follow up from #4344.

A connected UDP socket only receives packets from the connected address. All other packets are discarded. (See e.g. man 2 connect, "If the socket sockfd is of type SOCK_DGRAM, then addr [...] is the only address from which datagrams are received", analogous in BSD man connect).

In snet, this is not enforced. A Dialed snet connection will receive packets from any source address. If the caller uses Read (and not ReadFrom), it will have no way to tell whether the packet is from the connected host, or some other source.

Related note: the comment on snet.scionConnReader.Read() says: "If the remote address for the connection is unknown, Read returns an error." This is not implemented (it was, git blame shows removed in #2411). It appears that these issues are related; Read should check that the source of the packet is the connected remote address. Stray packets should be silently dropped. If there is no connected remote address, Read should error.