From nobody Fri Feb 03 19:34:23 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4P7m7N4VQkz3kgD1; Fri, 3 Feb 2023 19:34:24 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4P7m7N1J09z3CBG; Fri, 3 Feb 2023 19:34:24 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675452864; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=b6EhMftbOxXzKMC/N8BOe1G9CGw6J19jssiWxMbzS04=; b=if68uzJjWTa0KYoVEnya4L19tbNLIqGfBsWllUHux9B6uaur/w5DLSRPMiJ1Zm0GqM2Up+ CyU3OCRoO7fnYwOXCo6AZmvrkhPwqChkTWsWz/3jpZSUfWXAp9k+zc8V2odzPVj1qTlNtn VwPhk6ocdoEmdWQHCC4wc1r80pZrRblM8qirljVpWpWW9szRi2OipL3UZY9reJ7FsXImrZ uiJbhcbk+XeB+MrFu+C4BpWr6pf68C1MBCgZ0rkYxuPAxjRhvESyK98u5+KTDFI6L67C3w CXNVhg3UtZbn6aCoDX6L3YeBDFD4E1564OejXoYpoc7HJ7tUYBOfsdSG4qLIVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675452864; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=b6EhMftbOxXzKMC/N8BOe1G9CGw6J19jssiWxMbzS04=; b=vDrkCSgQmfaUnCAVyS8Q+x544g5+FM0RwnpvjFSJ83k+L31aRAtgCuFtmq5Q9Rq6kfOEL7 BeHiO+Rhld7GQ9jB2m/GCOXK3hfHfwXlKfNCf/+RejbEzN9n4IiaG5t7rv/fCzaoTwuYgv s6aN2HAGp7V67LGLq9GqRRyrsvLG6qAhkmzh9dIFzelzcTvYBxQ8T8XOHbO1HKJxhvzFRt SQ+BG3cs3Uc1ZeC1C9qnJcCyhcKv2bplXmRQNy4K4BH2oESfNY9JreTsL9TnFP6AiNyczu 02Vm5Rvlm3rSUxGX22lE0FSgp1kUplU3QIJkEb9uV6+a9U49leU9YDvCC5Uu7A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1675452864; a=rsa-sha256; cv=none; b=n2v0BHjNEZWWkm2Hc2EF6q+NuhXGd+l1uwGjUqwlxg2qCgsJkVllNwsWyi+oQhde2SAmoV oy3+/1Fb4JFNT8BL0Bbn6THjWYAn+cmJhXFrW9xiuPcOxuv5iajy9aXEZnHUNZcXAi24zW Cc45ruMu+xgnticbLleHvgVVjzy637p2mq6bZDDMy8zaVSbQjFY8KkA8DE2hbho0xwLL8F IGIax7O2g6C2NTuV6TdE5R5HT08X82CqethsZSWOZLSM6iNcXNf1EBhjFf9+cv20gOgncn R1OaS3/ZU/VLALno4fFDMetFN4BDG/3vFXdRC5XAW51QH57Zh4pjxuELFwLsfA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4P7m7N0BjRzn2L; Fri, 3 Feb 2023 19:34:24 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 313JYNvQ041494; Fri, 3 Feb 2023 19:34:23 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 313JYNv5041493; Fri, 3 Feb 2023 19:34:23 GMT (envelope-from git) Date: Fri, 3 Feb 2023 19:34:23 GMT Message-Id: <202302031934.313JYNv5041493@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: 9e46ff4d4cfa - main - netinet: don't return conflicting inpcb in in_pcbconnect_setup() List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 9e46ff4d4cfabb4836c84d97c639c169fd0a8aaa Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=9e46ff4d4cfabb4836c84d97c639c169fd0a8aaa commit 9e46ff4d4cfabb4836c84d97c639c169fd0a8aaa Author: Gleb Smirnoff AuthorDate: 2023-02-03 19:33:36 +0000 Commit: Gleb Smirnoff CommitDate: 2023-02-03 19:33:36 +0000 netinet: don't return conflicting inpcb in in_pcbconnect_setup() Last time this inpcb was actually used was in tcp_connect() before c94c54e4df9a. --- sys/netinet/in_pcb.c | 20 ++++---------------- sys/netinet/in_pcb.h | 3 +-- sys/netinet/tcp_usrreq.c | 22 ++++++++-------------- sys/netinet/udp_usrreq.c | 3 +-- 4 files changed, 14 insertions(+), 34 deletions(-) diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index ab8d0acbd9a7..2a775ff5fc31 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -1069,7 +1069,7 @@ in_pcbconnect(struct inpcb *inp, struct sockaddr_in *sin, struct ucred *cred, laddr = inp->inp_laddr.s_addr; anonport = (lport == 0); error = in_pcbconnect_setup(inp, sin, &laddr, &lport, &faddr, &fport, - NULL, cred); + cred); if (error) return (error); @@ -1320,19 +1320,13 @@ done: * * On success, *faddrp and *fportp will be set to the remote address * and port. These are not updated in the error case. - * - * If the operation fails because the connection already exists, - * *oinpp will be set to the PCB of that connection so that the - * caller can decide to override it. In all other cases, *oinpp - * is set to NULL. */ int in_pcbconnect_setup(struct inpcb *inp, struct sockaddr_in *sin, in_addr_t *laddrp, u_short *lportp, in_addr_t *faddrp, u_short *fportp, - struct inpcb **oinpp, struct ucred *cred) + struct ucred *cred) { struct in_ifaddr *ia; - struct inpcb *oinp; struct in_addr laddr, faddr; u_short lport, fport; int error; @@ -1350,8 +1344,6 @@ in_pcbconnect_setup(struct inpcb *inp, struct sockaddr_in *sin, INP_LOCK_ASSERT(inp); INP_HASH_LOCK_ASSERT(inp->inp_pcbinfo); - if (oinpp != NULL) - *oinpp = NULL; if (sin->sin_port == 0) return (EADDRNOTAVAIL); laddr.s_addr = *laddrp; @@ -1423,13 +1415,9 @@ in_pcbconnect_setup(struct inpcb *inp, struct sockaddr_in *sin, } if (lport != 0) { - oinp = in_pcblookup_hash_locked(inp->inp_pcbinfo, faddr, - fport, laddr, lport, 0, NULL, M_NODOM); - if (oinp != NULL) { - if (oinpp != NULL) - *oinpp = oinp; + if (in_pcblookup_hash_locked(inp->inp_pcbinfo, faddr, + fport, laddr, lport, 0, NULL, M_NODOM) != NULL) return (EADDRINUSE); - } } else { struct sockaddr_in lsin, fsin; diff --git a/sys/netinet/in_pcb.h b/sys/netinet/in_pcb.h index e0e630a8675e..dc248b275279 100644 --- a/sys/netinet/in_pcb.h +++ b/sys/netinet/in_pcb.h @@ -745,8 +745,7 @@ int in_pcbbind_setup(struct inpcb *, struct sockaddr *, in_addr_t *, int in_pcbconnect(struct inpcb *, struct sockaddr_in *, struct ucred *, bool); int in_pcbconnect_setup(struct inpcb *, struct sockaddr_in *, in_addr_t *, - u_short *, in_addr_t *, u_short *, struct inpcb **, - struct ucred *); + u_short *, in_addr_t *, u_short *, struct ucred *); void in_pcbdetach(struct inpcb *); void in_pcbdisconnect(struct inpcb *); void in_pcbdrop(struct inpcb *); diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c index b89cdd30a825..83804ac3525e 100644 --- a/sys/netinet/tcp_usrreq.c +++ b/sys/netinet/tcp_usrreq.c @@ -1394,7 +1394,7 @@ struct protosw tcp6_protosw = { static int tcp_connect(struct tcpcb *tp, struct sockaddr_in *sin, struct thread *td) { - struct inpcb *inp = tptoinpcb(tp), *oinp; + struct inpcb *inp = tptoinpcb(tp); struct socket *so = tptosocket(tp); struct in_addr laddr; u_short lport; @@ -1412,20 +1412,18 @@ tcp_connect(struct tcpcb *tp, struct sockaddr_in *sin, struct thread *td) laddr = inp->inp_laddr; lport = inp->inp_lport; error = in_pcbconnect_setup(inp, sin, &laddr.s_addr, &lport, - &inp->inp_faddr.s_addr, &inp->inp_fport, &oinp, td->td_ucred); - if (error && oinp == NULL) - goto out; - if (oinp) { - error = EADDRINUSE; - goto out; + &inp->inp_faddr.s_addr, &inp->inp_fport, td->td_ucred); + if (error) { + INP_HASH_WUNLOCK(&V_tcbinfo); + return (error); } /* Handle initial bind if it hadn't been done in advance. */ if (inp->inp_lport == 0) { inp->inp_lport = lport; if (in_pcbinshash(inp) != 0) { inp->inp_lport = 0; - error = EAGAIN; - goto out; + INP_HASH_WUNLOCK(&V_tcbinfo); + return (EAGAIN); } } inp->inp_laddr = laddr; @@ -1449,11 +1447,7 @@ tcp_connect(struct tcpcb *tp, struct sockaddr_in *sin, struct thread *td) tp->ts_offset = tcp_new_ts_offset(&inp->inp_inc); tcp_sendseqinit(tp); - return 0; - -out: - INP_HASH_WUNLOCK(&V_tcbinfo); - return (error); + return (0); } #endif /* INET */ diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index 540045fc3bc3..f911a79519b6 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -1253,8 +1253,7 @@ udp_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr, sin->sin_addr.s_addr == INADDR_BROADCAST) { INP_HASH_WLOCK(pcbinfo); error = in_pcbconnect_setup(inp, sin, &laddr.s_addr, - &lport, &faddr.s_addr, &fport, NULL, - td->td_ucred); + &lport, &faddr.s_addr, &fport, td->td_ucred); if (error) { INP_HASH_WUNLOCK(pcbinfo); goto release;