From f66145c6bd8178a68fb3e0e702d0473469722fba Mon Sep 17 00:00:00 2001 From: Yaroslav Tykhiy Date: Tue, 27 Jul 2004 16:35:09 +0000 Subject: [PATCH] Don't consider TCP connections beyond LISTEN state (i.e. with the foreign address being not wildcard) when checking for possible port theft since such connections cannot be stolen. The port theft check is FreeBSD-specific and isn't in the KAME tree. PR: bin/65928 (in the audit trail) Reviewed by: -net, -hackers (silence) Tested by: Nick Leuta MFC after: 1 month --- sys/netinet6/in6_pcb.c | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/sys/netinet6/in6_pcb.c b/sys/netinet6/in6_pcb.c index 16a45556d808..8a66e4f7a1c1 100644 --- a/sys/netinet6/in6_pcb.c +++ b/sys/netinet6/in6_pcb.c @@ -194,14 +194,10 @@ in6_pcbbind(inp, nam, cred) t = in6_pcblookup_local(pcbinfo, &sin6->sin6_addr, lport, INPLOOKUP_WILDCARD); - if (t && (t->inp_vflag & INP_TIMEWAIT)) { - if ((!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr) || - !IN6_IS_ADDR_UNSPECIFIED(&t->in6p_laddr) || - !(intotw(t)->tw_so_options & SO_REUSEPORT)) - && so->so_cred->cr_uid != - intotw(t)->tw_cred->cr_uid) - return (EADDRINUSE); - } else if (t && + if (t && + ((t->inp_vflag & INP_TIMEWAIT) == 0) && + (so->so_type != SOCK_STREAM || + IN6_IS_ADDR_UNSPECIFIED(&t->in6p_faddr)) && (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr) || !IN6_IS_ADDR_UNSPECIFIED(&t->in6p_laddr) || (t->inp_socket->so_options & SO_REUSEPORT) @@ -216,17 +212,12 @@ in6_pcbbind(inp, nam, cred) t = in_pcblookup_local(pcbinfo, sin.sin_addr, lport, INPLOOKUP_WILDCARD); - if (t && (t->inp_vflag & INP_TIMEWAIT)) { - if (so->so_cred->cr_uid != - intotw(t)->tw_cred->cr_uid && - (ntohl(t->inp_laddr.s_addr) != - INADDR_ANY || - ((inp->inp_vflag & - INP_IPV6PROTO) == - (t->inp_vflag & - INP_IPV6PROTO)))) - return (EADDRINUSE); - } else if (t && + if (t && + ((t->inp_vflag & + INP_TIMEWAIT) == 0) && + (so->so_type != SOCK_STREAM || + ntohl(t->inp_faddr.s_addr) == + INADDR_ANY) && (so->so_cred->cr_uid != t->inp_socket->so_cred->cr_uid) && (ntohl(t->inp_laddr.s_addr) !=