From nobody Tue Dec 28 16:53:24 2021 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 8BFA31903A4A; Tue, 28 Dec 2021 16:53: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 4JNgb82Gnkz4qlx; Tue, 28 Dec 2021 16:53:24 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 28B601543A; Tue, 28 Dec 2021 16:53: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 1BSGrOtL072144; Tue, 28 Dec 2021 16:53:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1BSGrOef072143; Tue, 28 Dec 2021 16:53:24 GMT (envelope-from git) Date: Tue, 28 Dec 2021 16:53:24 GMT Message-Id: <202112281653.1BSGrOef072143@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: 4287aa56197f - main - tcp_usr_shutdown: don't cast inp_ppcb to tcpcb before checking inp_flags 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: 4287aa56197fc2e37cad07c23b52f9ed4f1a7fd0 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1640710404; 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=ntLn49A/R7vUQuXbgq5DXtkt+WVXst2VtsTS9Rhf20Y=; b=wUe9urE0Lm8a9VjUiX44IJUJs81/GezACqsQ2nY9GY83NWCAMMnb7z8z/QwdwVpITqUSpI VsLAPn3hfD2yoR8wMYLteN3A1EWguLaNAz03o93K7mPoG2fJrDRswRFVPtDeH8jsgMN94M HVL6hDwuHwQwRylJSzPBrM7+g2NP4lwNwrL1Gf+JOSeTtCJabaD9sKkH0obLHNOjegFPQP 1ZzK2SYXl9wQE/oEd+5axBnm8TCcMtV3kndCypqFp94/2kNubsbqAmdXZa/ebT/gcpggWr JvLeVpZbOIi0qHDvLSlYlCPXycftofgSwpZIV74WPZW+pa07EUScSpWP2ZxkBA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1640710404; a=rsa-sha256; cv=none; b=T5wGXgZAUMujegMsfmUqZ6i1mU/SrT+lT28/12/KycvTjNiCjPFjpNEPpo+yn11i+2qda0 RA1RF0JSWhQh3sJrbbnNvHvKTVo998hvA/sUfMArJPKQ6P4zJ9l1yzuXOzu/UYUX+h6Laz dnAoET3lUNF7gUvr46obJQ5FAyquGJ9ovYMdFjgidYBHP/7t9bQNA6kYQmshefAyJ+PDGs 4SEgPq97jxgKYCbijITDlY2theiOnXtPS46obvMZZHzEEQ0YuiwfULu/tyxfhKXtp/P9Lc 3z4bUhvJK7fs2giug4RJx0+CRH2ZSqKpUZx96yZlx1D+EMlz82s99/lo3jcNsA== 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=4287aa56197fc2e37cad07c23b52f9ed4f1a7fd0 commit 4287aa56197fc2e37cad07c23b52f9ed4f1a7fd0 Author: Gleb Smirnoff AuthorDate: 2021-12-28 16:50:02 +0000 Commit: Gleb Smirnoff CommitDate: 2021-12-28 16:50:02 +0000 tcp_usr_shutdown: don't cast inp_ppcb to tcpcb before checking inp_flags While here move out one more erroneous condition out of the epoch and common return. The only functional change is that if we send control on a shut down socket we would get EINVAL instead of ECONNRESET. Reviewed by: tuexen Reported by: syzbot+8388cf7f401a7b6bece6@syzkaller.appspotmail.com Fixes: f64dc2ab5be38e5366271ef85ea90d8cb1c7841a --- sys/netinet/tcp_usrreq.c | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c index 2dea7253e0d6..def7d477c72b 100644 --- a/sys/netinet/tcp_usrreq.c +++ b/sys/netinet/tcp_usrreq.c @@ -993,34 +993,31 @@ tcp_usr_send(struct socket *so, int flags, struct mbuf *m, bool restoreflags; TCPDEBUG0; - /* - * We require the pcbinfo "read lock" if we will close the socket - * as part of this call. - */ - NET_EPOCH_ENTER(et); - inp = sotoinpcb(so); - KASSERT(inp != NULL, ("tcp_usr_send: inp == NULL")); - INP_WLOCK(inp); - tp = intotcpcb(inp); - vflagsav = inp->inp_vflag; - incflagsav = inp->inp_inc.inc_flags; - restoreflags = false; - if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) { - if (control) - m_freem(control); - error = ECONNRESET; - goto out; - } if (control != NULL) { /* TCP doesn't do control messages (rights, creds, etc) */ if (control->m_len) { m_freem(control); - error = EINVAL; - goto out; + return (EINVAL); } m_freem(control); /* empty control, just free it */ - control = NULL; } + + inp = sotoinpcb(so); + KASSERT(inp != NULL, ("tcp_usr_send: inp == NULL")); + INP_WLOCK(inp); + if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) { + if (m != NULL && (flags & PRUS_NOTREADY) == 0) + m_freem(m); + INP_WUNLOCK(inp); + return (ECONNRESET); + } + + vflagsav = inp->inp_vflag; + incflagsav = inp->inp_inc.inc_flags; + restoreflags = false; + tp = intotcpcb(inp); + + NET_EPOCH_ENTER(et); if ((flags & PRUS_OOB) != 0 && (error = tcp_pru_options_support(tp, PRUS_OOB)) != 0) goto out;