F-Stack / f-stack

F-Stack is an user space network development kit with high performance based on DPDK, FreeBSD TCP/IP stack and coroutine API.
http://www.f-stack.org
Other
3.82k stars 891 forks source link

prevent ff_recvfrom() from corrupting *from passed by user in case of zero *fromlen #690

Closed sarosh-arif closed 2 years ago

sarosh-arif commented 2 years ago

currently if fromlen passed by user is zero the from structure is filled with garbage values. The reason behind is that struct sockaddr_storage bsdaddr is made inside ff_recvfrom() and is passed to kern_recvit() to be filled. kern_recvit() does not touch bsdaddr in case of zero fromlen hence it has garbadge values. Later in freebsd2linux_sockaddr(), bsdaddr is copied into from which corrupts *from.

The fix is to simply not copy bsdaddr into from in case of zero fromlen. This patch adds a simple check for that.