smoltcp-rs / smoltcp

a smol tcp/ip stack
BSD Zero Clause License
3.63k stars 402 forks source link

ARP Request Packets generated with source address of triggering packet instead of interface #940

Open samueljero opened 3 weeks ago

samueljero commented 3 weeks ago

This is most relevant when using Raw sockets.

If you attempt to send a packet via a raw socket with a source address that does not match the interface address (i.e. a spoofed packet), smoltcp may generate an ARP request if it doesn't have the destination MAC address cached. This ARP request will have a source address matching the spoofed packet NOT the interface. As a result, smoltcp will ignore the ARP response.

The problem appears to be that InterfaceInnner::lookup_hardware_addr() uses the packet's source IPv4 address instead of looking up the interfaces's source IPv4 address at 989: https://github.com/smoltcp-rs/smoltcp/blob/57b1dd4b158327c31edebd3260d90bf5c3b1452d/src/iface/interface/mod.rs#L977-L992

It seems likely that self.get_source_address_ipv4(dst_addr) should be used instead.