From nobody Tue Nov 08 18:24:56 2022 X-Original-To: dev-commits-src-all@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 4N6GjP1FJvz4V6nX; Tue, 8 Nov 2022 18:24:57 +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 4N6GjP0PsZz4KZV; Tue, 8 Nov 2022 18:24:57 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1667931897; 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=FkBCFfsrVZrSaUjtkhu4Sia48Hcq93VPt63PyfJ6wdM=; b=p535KYHxZxipZ4Dvj8miqoiCQfhhtPoNmM4PTK+ePA+ePG4PyTw+DJAf87AaM/A2ZMaxVq zs2p1P7RH9l4jypCQM9B2K27riTTH/Bk58WS22B4HxXgTtxba4PZ5zgu3enGnCp7fldWLz voE3vXAOdDRq1LZfTc2CbPVCu64jy1yHlwX2InKzY6E/jpz81B0D0re+XsZ35lavWF29Fq 079xfemLi6+NsCVolr1ojx9RUhXw2uKmDz1tbnaZ/RTiixXX+8AHVymWmae9ar4LR0IrFw fuEUxLpvgzYz2TPRRlTXfO5kwbGn60M7i69YHSLQs2mE9v+e9opjy+wegVddUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1667931897; 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=FkBCFfsrVZrSaUjtkhu4Sia48Hcq93VPt63PyfJ6wdM=; b=WzQ8zBKa+Ju/jYMfKU1Gyu665ku/+2Twh8vH2xmLilwTt8sXvDUx0e88tI+0dui54X4vaN hiIIa7qFqSBTJkkrUKFf3iwEl5+bAgQdhDLVD5ZgJcJ8JkY4pW+ro7gEgy9RUtb2Glzk/n asPh1SBvYMaXlt/QhBkEbte5sKWLBr3Qdmqf6r9V+THIHTL53RFB/5c4BVqLZeQr9UyEos 51x2J5wvKIHTwswwNw8HsAK4mctvJjJznf5HrvQUOnH65y0YF7CDd4w5kZQU/QNddYn7fe exVYszeoCzJKumpwaZ/cA7kxOCLLQKvVYEPXAWx3HXfOniQJSM+np7Tfo8+VfA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1667931897; a=rsa-sha256; cv=none; b=tbgOxlkVfQx8wj3+VFgPr6dHWKGtkv5ylsxBWdfll4K/iMdst8XEwq2TVHGlljduVrEeyq t099Phni/AGRtomwiwpxzNgtPW2mZeMkPAI64Iwx+o2/5x0j/CeGxiKi+Ib5MJdU9WnZtH fDEZkiE67BQF6JDPQRpek8UPdXH/63W+46894DxVk8aPOrkd8FkVeiw5JhyUnDK4VToV0A ZyUIFTFl4rEErlh6H9QjoOA02HwqyBtuGrV8UP7yWJQLXRGhZ/EKy/TSfePNShhInHXF6N Cn1AQg4vqJQAR1q3v+8i/PEGAMYdwr2U3GW4/8XMzRoMx7aHbvPuPKF7baXZxA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4N6GjN6KJgzsFL; Tue, 8 Nov 2022 18:24:56 +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 2A8IOuEM043409; Tue, 8 Nov 2022 18:24:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2A8IOuEi043408; Tue, 8 Nov 2022 18:24:56 GMT (envelope-from git) Date: Tue, 8 Nov 2022 18:24:56 GMT Message-Id: <202211081824.2A8IOuEi043408@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: f71cb9f74808 - main - tcp: inp_socket is valid through the lifetime of a TCP inpcb List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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: f71cb9f74808facc9d3e6854f96da2afbed8a1e3 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=f71cb9f74808facc9d3e6854f96da2afbed8a1e3 commit f71cb9f74808facc9d3e6854f96da2afbed8a1e3 Author: Gleb Smirnoff AuthorDate: 2022-11-08 18:24:39 +0000 Commit: Gleb Smirnoff CommitDate: 2022-11-08 18:24:39 +0000 tcp: inp_socket is valid through the lifetime of a TCP inpcb The inp_socket is cleared only in in_pcbdetach(), which for TCP is always accompanied with inp_pcbfree(). An inpcb that went through in_pcbfree() shall never be returned by any kind of pcb lookup. Reviewed by: tuexen Differential revision: https://reviews.freebsd.org/D37062 --- sys/netinet/tcp_input.c | 2 +- sys/netinet/tcp_subr.c | 177 ++++++++++++++++++++++-------------------------- sys/netinet/tcp_timer.c | 2 + 3 files changed, 83 insertions(+), 98 deletions(-) diff --git a/sys/netinet/tcp_input.c b/sys/netinet/tcp_input.c index eeed49681ec6..ad399b9042e2 100644 --- a/sys/netinet/tcp_input.c +++ b/sys/netinet/tcp_input.c @@ -940,7 +940,7 @@ findpcb: if ((inp->inp_flowtype == M_HASHTYPE_NONE) && (M_HASHTYPE_GET(m) != M_HASHTYPE_NONE) && - ((inp->inp_socket == NULL) || !SOLISTENING(inp->inp_socket))) { + !SOLISTENING(inp->inp_socket)) { inp->inp_flowid = m->m_pkthdr.flowid; inp->inp_flowtype = M_HASHTYPE_GET(m); } diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c index 999f52c9a339..e159bf81208b 100644 --- a/sys/netinet/tcp_subr.c +++ b/sys/netinet/tcp_subr.c @@ -2730,8 +2730,6 @@ tcp_getcred(SYSCTL_HANDLER_ARGS) addrs[0].sin_addr, addrs[0].sin_port, INPLOOKUP_RLOCKPCB, NULL); NET_EPOCH_EXIT(et); if (inp != NULL) { - if (inp->inp_socket == NULL) - error = ENOENT; if (error == 0) error = cr_canseeinpcb(req->td->td_ucred, inp); if (error == 0) @@ -2798,8 +2796,6 @@ tcp6_getcred(SYSCTL_HANDLER_ARGS) INPLOOKUP_RLOCKPCB, NULL); NET_EPOCH_EXIT(et); if (inp != NULL) { - if (inp->inp_socket == NULL) - error = ENOENT; if (error == 0) error = cr_canseeinpcb(req->td->td_ucred, inp); if (error == 0) @@ -2875,47 +2871,44 @@ tcp_ctlinput_with_port(struct icmp *icp, uint16_t port) inp = in_pcblookup(&V_tcbinfo, ip->ip_dst, th->th_dport, ip->ip_src, th->th_sport, INPLOOKUP_WLOCKPCB, NULL); if (inp != NULL) { - if (inp->inp_socket != NULL) { - tp = intotcpcb(inp); + tp = intotcpcb(inp); #ifdef TCP_OFFLOAD - if (tp->t_flags & TF_TOE && errno == EMSGSIZE) { + if (tp->t_flags & TF_TOE && errno == EMSGSIZE) { + /* + * MTU discovery for offloaded connections. Let + * the TOE driver verify seq# and process it. + */ + mtu = tcp_next_pmtu(icp, ip); + tcp_offload_pmtu_update(tp, icmp_tcp_seq, mtu); + goto out; + } +#endif + if (tp->t_port != port) + goto out; + if (SEQ_GEQ(ntohl(icmp_tcp_seq), tp->snd_una) && + SEQ_LT(ntohl(icmp_tcp_seq), tp->snd_max)) { + if (errno == EMSGSIZE) { /* - * MTU discovery for offloaded connections. Let - * the TOE driver verify seq# and process it. + * MTU discovery: we got a needfrag and + * will potentially try a lower MTU. */ mtu = tcp_next_pmtu(icp, ip); - tcp_offload_pmtu_update(tp, icmp_tcp_seq, mtu); - goto out; - } -#endif - if (tp->t_port != port) { - goto out; - } - if (SEQ_GEQ(ntohl(icmp_tcp_seq), tp->snd_una) && - SEQ_LT(ntohl(icmp_tcp_seq), tp->snd_max)) { - if (errno == EMSGSIZE) { - /* - * MTU discovery: we got a needfrag and - * will potentially try a lower MTU. - */ - mtu = tcp_next_pmtu(icp, ip); - - /* - * Only process the offered MTU if it - * is smaller than the current one. - */ - if (mtu < tp->t_maxseg + - sizeof(struct tcpiphdr)) { - bzero(&inc, sizeof(inc)); - inc.inc_faddr = ip->ip_dst; - inc.inc_fibnum = - inp->inp_inc.inc_fibnum; - tcp_hc_updatemtu(&inc, mtu); - inp = tcp_mtudisc(inp, mtu); - } - } else - inp = (*notify)(inp, errno); - } + + /* + * Only process the offered MTU if it + * is smaller than the current one. + */ + if (mtu < tp->t_maxseg + + sizeof(struct tcpiphdr)) { + bzero(&inc, sizeof(inc)); + inc.inc_faddr = ip->ip_dst; + inc.inc_fibnum = + inp->inp_inc.inc_fibnum; + tcp_hc_updatemtu(&inc, mtu); + inp = tcp_mtudisc(inp, mtu); + } + } else + inp = (*notify)(inp, errno); } } else { bzero(&inc, sizeof(inc)); @@ -3067,51 +3060,48 @@ tcp6_ctlinput_with_port(struct ip6ctlparam *ip6cp, uint16_t port) } m_copydata(m, off, sizeof(tcp_seq), (caddr_t)&icmp_tcp_seq); if (inp != NULL) { - if (inp->inp_socket != NULL) { - tp = intotcpcb(inp); + tp = intotcpcb(inp); #ifdef TCP_OFFLOAD - if (tp->t_flags & TF_TOE && errno == EMSGSIZE) { - /* MTU discovery for offloaded connections. */ - mtu = tcp6_next_pmtu(icmp6); - tcp_offload_pmtu_update(tp, icmp_tcp_seq, mtu); - goto out; - } + if (tp->t_flags & TF_TOE && errno == EMSGSIZE) { + /* MTU discovery for offloaded connections. */ + mtu = tcp6_next_pmtu(icmp6); + tcp_offload_pmtu_update(tp, icmp_tcp_seq, mtu); + goto out; + } #endif - if (tp->t_port != port) { - goto out; - } - if (SEQ_GEQ(ntohl(icmp_tcp_seq), tp->snd_una) && - SEQ_LT(ntohl(icmp_tcp_seq), tp->snd_max)) { - if (errno == EMSGSIZE) { - /* - * MTU discovery: - * If we got a needfrag set the MTU - * in the route to the suggested new - * value (if given) and then notify. - */ - mtu = tcp6_next_pmtu(icmp6); + if (tp->t_port != port) + goto out; + if (SEQ_GEQ(ntohl(icmp_tcp_seq), tp->snd_una) && + SEQ_LT(ntohl(icmp_tcp_seq), tp->snd_max)) { + if (errno == EMSGSIZE) { + /* + * MTU discovery: + * If we got a needfrag set the MTU + * in the route to the suggested new + * value (if given) and then notify. + */ + mtu = tcp6_next_pmtu(icmp6); - bzero(&inc, sizeof(inc)); - inc.inc_fibnum = M_GETFIB(m); - inc.inc_flags |= INC_ISIPV6; - inc.inc6_faddr = *dst; - if (in6_setscope(&inc.inc6_faddr, - m->m_pkthdr.rcvif, NULL)) - goto out; - /* - * Only process the offered MTU if it - * is smaller than the current one. - */ - if (mtu < tp->t_maxseg + - sizeof (struct tcphdr) + - sizeof (struct ip6_hdr)) { - tcp_hc_updatemtu(&inc, mtu); - tcp_mtudisc(inp, mtu); - ICMP6STAT_INC(icp6s_pmtuchg); - } - } else - inp = (*notify)(inp, errno); - } + bzero(&inc, sizeof(inc)); + inc.inc_fibnum = M_GETFIB(m); + inc.inc_flags |= INC_ISIPV6; + inc.inc6_faddr = *dst; + if (in6_setscope(&inc.inc6_faddr, + m->m_pkthdr.rcvif, NULL)) + goto out; + /* + * Only process the offered MTU if it + * is smaller than the current one. + */ + if (mtu < tp->t_maxseg + + sizeof (struct tcphdr) + + sizeof (struct ip6_hdr)) { + tcp_hc_updatemtu(&inc, mtu); + tcp_mtudisc(inp, mtu); + ICMP6STAT_INC(icp6s_pmtuchg); + } + } else + inp = (*notify)(inp, errno); } } else { bzero(&inc, sizeof(inc)); @@ -3806,19 +3796,14 @@ sysctl_switch_tls(SYSCTL_HANDLER_ARGS) } NET_EPOCH_EXIT(et); if (inp != NULL) { - if (inp->inp_socket == NULL) { - error = ECONNRESET; - INP_WUNLOCK(inp); - } else { - struct socket *so; + struct socket *so; - so = inp->inp_socket; - soref(so); - error = ktls_set_tx_mode(so, - arg2 == 0 ? TCP_TLS_MODE_SW : TCP_TLS_MODE_IFNET); - INP_WUNLOCK(inp); - sorele(so); - } + so = inp->inp_socket; + soref(so); + error = ktls_set_tx_mode(so, + arg2 == 0 ? TCP_TLS_MODE_SW : TCP_TLS_MODE_IFNET); + INP_WUNLOCK(inp); + sorele(so); } else error = ESRCH; return (error); @@ -4025,8 +4010,6 @@ tcp_inptoxtp(const struct inpcb *inp, struct xtcpcb *xt) xt->xt_len = sizeof(struct xtcpcb); in_pcbtoxinpcb(inp, &xt->xt_inp); - if (inp->inp_socket == NULL) - xt->xt_inp.xi_socket.xso_protocol = IPPROTO_TCP; } void diff --git a/sys/netinet/tcp_timer.c b/sys/netinet/tcp_timer.c index 391b9dfdbc05..bbf5331c1d7d 100644 --- a/sys/netinet/tcp_timer.c +++ b/sys/netinet/tcp_timer.c @@ -351,6 +351,8 @@ tcp_timer_2msl(void *xtp) * If fastrecycle of FIN_WAIT_2, in FIN_WAIT_2 and receiver has closed, * there's no point in hanging onto FIN_WAIT_2 socket. Just close it. * Ignore fact that there were recent incoming segments. + * + * XXXGL: check if inp_socket shall always be !NULL here? */ if (tp->t_state == TCPS_TIME_WAIT) { tcp_timer_close(tp);