tcp, udp: improve input validation in handling bind()

Reported by:		syzbot+24fcfd8057e9bc339295@syzkaller.appspotmail.com
Reported by:		syzbot+6e90ceb5c89285b2655b@syzkaller.appspotmail.com
Reviewed by:		markj, rscheff
MFC after:		3 days
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D31422
This commit is contained in:
Michael Tuexen 2021-08-05 13:42:30 +02:00
parent 89ed2ecb14
commit 3f1f6b6ef7
2 changed files with 2 additions and 0 deletions

View File

@ -326,6 +326,7 @@ tcp_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
* Preserve compatibility with old programs.
*/
if (nam->sa_family != AF_UNSPEC ||
nam->sa_len < offsetof(struct sockaddr_in, sin_zero) ||
sinp->sin_addr.s_addr != INADDR_ANY)
return (EAFNOSUPPORT);
nam->sa_family = AF_INET;

View File

@ -1635,6 +1635,7 @@ udp_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
* Preserve compatibility with old programs.
*/
if (nam->sa_family != AF_UNSPEC ||
nam->sa_len < offsetof(struct sockaddr_in, sin_zero) ||
sinp->sin_addr.s_addr != INADDR_ANY)
return (EAFNOSUPPORT);
nam->sa_family = AF_INET;