From nobody Thu Jul 07 04:10:39 2022 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 2AE211CF83D7; Thu, 7 Jul 2022 04:29:44 +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 4Ldk2w0cCHz3C29; Thu, 7 Jul 2022 04:29:44 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1657168184; 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=EmxpHxMJFuFvMBU7mbTXhWoNQyH0iuCMEZI7tXKobtA=; b=ciBDvVaTB0dzxt/xS6v1aOFtjftN3WGMoOu0lnpEEwgbF8i43JJFWFMTJ8ZWrTZVBteMyl KtprOu4ik2OkkNkpDyZoZCLs3CoBzwcsxewBndzkF/CKBaPO6AWzlBN9fcjvuhYgCHA1Vo 78epJMLk/Yd+l1G0RaJzUTjkVnBmKz6PZKFXVKDyG0PMu68InNs9mPtKFGZ8bC6HzXQnQm wa1G59ptVKc9oUjalahs9ESJ9bhTtIGAyKBckt3Nn4ekue8nOG8HMhDhKk1lW2yD6KzO2R qUj7VcOBeZf1ocrNm6CmVuxSyC2w78Zg3sSgc85D2OAbjlxR1yRUAuIm7d1g+Q== 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 E52AD3D4; Thu, 7 Jul 2022 04:29:43 +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 2674Adat087051; Thu, 7 Jul 2022 04:10:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2674AdvN087050; Thu, 7 Jul 2022 04:10:39 GMT (envelope-from git) Date: Thu, 7 Jul 2022 04:10:39 GMT Message-Id: <202207070410.2674AdvN087050@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: 1b91978f6375 - main - tcp: remove a condition in tcp_usr_detach() that never happens 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: 1b91978f6375023b00c7d2b49a778765ce4ee6b8 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1657168184; 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=EmxpHxMJFuFvMBU7mbTXhWoNQyH0iuCMEZI7tXKobtA=; b=UiLWDyT9DJRPkLpj9PSTZOBKxs4is+ZsiBzlH9YnHfSeUgTLt7EHi6eNI+0y6KG5etgp3f e8CnyZkZZIKXBEgF91wsTPbzfPQQqagLy5hME8zbN1KjPUwvZNbnAE0a9RVLgXxxeCzmvr 0BkPtPn09L0t9L5nu0aXXcjHBVp8kccuSuaotA4/+ChY8mIWakwkIBODkI7W2CqqvGpBbO VdplJOlOYeDQ/DEgTmSvBs46tezcEUvbp2uMQc28XVEI5DfwJ6KT38a9GenVjCRBfXIOjf VJT3sRVoZ+0aCzYSpzxapZzMTgwI3oxQHxkP6XUKT2q/72NKelg6aBdAUcGewQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1657168184; a=rsa-sha256; cv=none; b=dT/kcm1MBCFSmZgLWz4afkaL/uNfvrmYjvISIOWsZyPt1L1qiUp5QodWRABUHHCyWjFYmI gwjWr9goa6B8REvMfmPlT2LnjLls2QcbH4/GbB97x5Y19ZjLiElJUTx9DZb/OtOpok8w2z 4f6oq0gfQ6sCgTIdRr+iNDrZNmHiim44Bm+WlxyJsCxOdpa0zNvsgutwNgyz6sk1dO0owA xLSO+r82PPIUZd7/1hOKrSx7BgnQiG2l0TDFCZeKagF5u06fJYT1YOEZlHECUN32ALgDOL FeDtWYps+Vr1Gy8aNeddUEXVsGY61a7mFmMqIW4LCtPvAmjGXxgosmY1Wdriiw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=1b91978f6375023b00c7d2b49a778765ce4ee6b8 commit 1b91978f6375023b00c7d2b49a778765ce4ee6b8 Author: Gleb Smirnoff AuthorDate: 2022-07-07 04:09:45 +0000 Commit: Gleb Smirnoff CommitDate: 2022-07-07 04:09:45 +0000 tcp: remove a condition in tcp_usr_detach() that never happens The comment from Robert Watson doubts that this condition ever happens. Our analysis confirm that. Also, we found that if you manage to create such a connection with help of some other bug, then after the "second case" code is executed, the kernel will panic in other part of the stack. Reviewed by: rrs, tuexen Differential revision: https://reviews.freebsd.org/D35714 --- sys/netinet/tcp_usrreq.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c index cdeb2cbcd98e..158ed5d9658c 100644 --- a/sys/netinet/tcp_usrreq.c +++ b/sys/netinet/tcp_usrreq.c @@ -272,23 +272,15 @@ tcp_usr_detach(struct socket *so) } } else { /* - * If the connection is not in timewait, we consider two - * two conditions: one in which no further processing is - * necessary (dropped || embryonic), and one in which TCP is - * not yet done, but no longer requires the socket, so the - * pcb will persist for the time being. - * - * XXXRW: Does the second case still occur? + * If the connection is not in timewait, it must be either + * dropped or embryonic. */ - if (inp->inp_flags & INP_DROPPED || - tp->t_state < TCPS_SYN_SENT) { - tcp_discardcb(tp); - in_pcbdetach(inp); - in_pcbfree(inp); - } else { - in_pcbdetach(inp); - INP_WUNLOCK(inp); - } + KASSERT(inp->inp_flags & INP_DROPPED || + tp->t_state < TCPS_SYN_SENT, + ("%s: inp %p not dropped or embryonic", __func__, inp)); + tcp_discardcb(tp); + in_pcbdetach(inp); + in_pcbfree(inp); } }