From nobody Wed Feb 1 23:18:04 2023 X-Original-To: dev-commits-src-branches@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 4P6dBN5qrrz3cK48; Wed, 1 Feb 2023 23:18:04 +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 4P6dBN5LYGz3HCy; Wed, 1 Feb 2023 23:18:04 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675293484; 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=boy16oTXxK9LJ1s37QfQbrOLJ5GSEztSC0QqV3mxBqw=; b=lV3k17grk+mRkro1aPR66Y4o19Mjb/Nt7m/7ya2IlU8blfA6QjdXmL50A1dJ0y8hzLLJl4 U+7N3jodyWdi+zflyvQDQ5pLdkvkj7dcWTFPt95P8WFv4DfGFRHNwL1MJC6kQzdT7L5D5l jjYwxrOERrutRYZZbDD3jDRekKvP72TRLbGRc6Z0rXwqmh9EsNomcceelSS9S2+8171g4s IgmyLSpUySXJEU71r4TbOhQ55Bp9zntwy4Qfm/3jGeO9yzw5lt70X/4Cj7ENjhz1VEo1G4 YiTCxJvrDds3bEOCgRbqH9r3az/dFZurhJ0FsMuC3DolKjk09UjPQc7ZjvMjEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675293484; 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=boy16oTXxK9LJ1s37QfQbrOLJ5GSEztSC0QqV3mxBqw=; b=c/VfqnzLu6uZYZjWgne5DHzL2o9Q58Dhy7mJ50RhrrcerFEdqrU66JX9fMvQJHbd3VKsk3 UFk9d0+j0YwZpNC8EW38wdXwFbGtaKp9PGHKhLI0Hra0zKqQYVtcetBgUJCsDxcACqsLCF MMjVFl5Wv/KaXzak5AskAyQNHOTazuEH43ZjowYsDYJNZd7YMRpwY2L7Fyo5+ogdVVP5Xh W2HBn6DGBVejjPnIftEsdKqDNN3ZKvK7NzqrVf4DaGs/4LXkNKKWO2SDx4K7ZFZ8GF7ls9 j+YysD6yfHVOMT8S55R8rSTlJlUjaCtgAOjAc8IQXd9VtojdDBVnyb75+xRJeg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1675293484; a=rsa-sha256; cv=none; b=HHxr/yw2Qjl5STc2g06YUQZw8x/Jt8B29oz89G3xg5rGscFvWT6BcvtzIOBBwuClRTxGPN SN+g1PAA+Zhc6T/R/xLI6PoDdKMczZpJ36Afh+xD5UVp5XFgs7xRBo3YG2G2/tcVjMmM72 yPhZvU5N4B+jE1G1X7zOrSazlHdM/FMmEvyVrB1YHhO/ko7E9hU3OENXR1ykw3EuxZcMeV 9JmPMud1P+ZjkaRuPi4ExbRrR//oTqt51+0N/Ms7P3sGhjlHHW8BQIq0rRq1d+9ZISv1n8 0QU53tfvnBaOEL7ggdFq4vP5JsxwISwlyReUvDL/2w7Tx1bS1958zE2tOv2SBw== 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 4P6dBN4PXDzXgq; Wed, 1 Feb 2023 23:18:04 +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 311NI4Ii047626; Wed, 1 Feb 2023 23:18:04 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 311NI4XY047625; Wed, 1 Feb 2023 23:18:04 GMT (envelope-from git) Date: Wed, 1 Feb 2023 23:18:04 GMT Message-Id: <202302012318.311NI4XY047625@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Michael Tuexen Subject: git: f997df3164c5 - stable/13 - sctp: improve handling of sctp inpcb flags List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: tuexen X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: f997df3164c53be1519ba87b769fc3a87a50fc34 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by tuexen: URL: https://cgit.FreeBSD.org/src/commit/?id=f997df3164c53be1519ba87b769fc3a87a50fc34 commit f997df3164c53be1519ba87b769fc3a87a50fc34 Author: Michael Tuexen AuthorDate: 2022-06-04 05:35:54 +0000 Commit: Michael Tuexen CommitDate: 2023-02-01 23:17:29 +0000 sctp: improve handling of sctp inpcb flags Use an atomic operation when the inp is not write locked. Reported by: syzbot+bf27083e9a3f8fde8b4d@syzkaller.appspotmail.com (cherry picked from commit a5c2009dd8ab562435fb7cc2ac0922668f9511a8) --- sys/netinet/sctp_constants.h | 8 ++++---- sys/netinet/sctp_input.c | 9 ++++----- sys/netinet/sctp_pcb.c | 15 +++++++++++++++ sys/netinet/sctp_pcb.h | 3 +++ sys/netinet/sctputil.c | 2 +- 5 files changed, 27 insertions(+), 10 deletions(-) diff --git a/sys/netinet/sctp_constants.h b/sys/netinet/sctp_constants.h index 66f2cca5ab6d..3df6ad6db2aa 100644 --- a/sys/netinet/sctp_constants.h +++ b/sys/netinet/sctp_constants.h @@ -968,7 +968,7 @@ __FBSDID("$FreeBSD$"); #define sctp_sowwakeup(inp, so) \ do { \ if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) { \ - inp->sctp_flags |= SCTP_PCB_FLAGS_WAKEOUTPUT; \ + sctp_pcb_add_flags(inp, SCTP_PCB_FLAGS_WAKEOUTPUT); \ } else { \ sowwakeup(so); \ } \ @@ -977,8 +977,8 @@ do { \ #define sctp_sowwakeup_locked(inp, so) \ do { \ if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) { \ + sctp_pcb_add_flags(inp, SCTP_PCB_FLAGS_WAKEOUTPUT); \ SOCKBUF_UNLOCK(&((so)->so_snd)); \ - inp->sctp_flags |= SCTP_PCB_FLAGS_WAKEOUTPUT; \ } else { \ sowwakeup_locked(so); \ } \ @@ -987,7 +987,7 @@ do { \ #define sctp_sorwakeup(inp, so) \ do { \ if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) { \ - inp->sctp_flags |= SCTP_PCB_FLAGS_WAKEINPUT; \ + sctp_pcb_add_flags(inp, SCTP_PCB_FLAGS_WAKEINPUT); \ } else { \ sorwakeup(so); \ } \ @@ -996,7 +996,7 @@ do { \ #define sctp_sorwakeup_locked(inp, so) \ do { \ if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) { \ - inp->sctp_flags |= SCTP_PCB_FLAGS_WAKEINPUT; \ + sctp_pcb_add_flags(inp, SCTP_PCB_FLAGS_WAKEINPUT); \ SOCKBUF_UNLOCK(&((so)->so_rcv)); \ } else { \ sorwakeup_locked(so); \ diff --git a/sys/netinet/sctp_input.c b/sys/netinet/sctp_input.c index 95e3be69123e..6fa4d0323d94 100644 --- a/sys/netinet/sctp_input.c +++ b/sys/netinet/sctp_input.c @@ -1491,8 +1491,7 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset, * init/init-ack/cookie done before the * init-ack came back.. */ - stcb->sctp_ep->sctp_flags |= - SCTP_PCB_FLAGS_CONNECTED; + sctp_pcb_add_flags(stcb->sctp_ep, SCTP_PCB_FLAGS_CONNECTED); soisconnected(stcb->sctp_socket); } /* notify upper layer */ @@ -1689,7 +1688,7 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset, if (((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) && (!SCTP_IS_LISTENING(inp))) { - stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED; + sctp_pcb_add_flags(stcb->sctp_ep, SCTP_PCB_FLAGS_CONNECTED); soisconnected(stcb->sctp_socket); } if (SCTP_GET_STATE(stcb) == SCTP_STATE_COOKIE_ECHOED) @@ -2182,7 +2181,7 @@ sctp_process_cookie_new(struct mbuf *m, int iphlen, int offset, * * XXXMJ unlocked */ - stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED; + sctp_pcb_add_flags(stcb->sctp_ep, SCTP_PCB_FLAGS_CONNECTED); soisconnected(stcb->sctp_socket); } else if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) && (SCTP_IS_LISTENING(inp))) { @@ -2793,7 +2792,7 @@ sctp_handle_cookie_ack(struct sctp_cookie_ack_chunk *cp SCTP_UNUSED, sctp_ulp_notify(SCTP_NOTIFY_ASSOC_UP, stcb, 0, NULL, SCTP_SO_NOT_LOCKED); if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { - stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED; + sctp_pcb_add_flags(stcb->sctp_ep, SCTP_PCB_FLAGS_CONNECTED); if ((stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET) == 0) { soisconnected(stcb->sctp_socket); } diff --git a/sys/netinet/sctp_pcb.c b/sys/netinet/sctp_pcb.c index 60aa6f175366..e1a2b74d02f3 100644 --- a/sys/netinet/sctp_pcb.c +++ b/sys/netinet/sctp_pcb.c @@ -7067,3 +7067,18 @@ sctp_initiate_iterator(inp_func inpf, /* sa_ignore MEMLEAK {memory is put on the tailq for the iterator} */ return (0); } + +/* + * Atomically add flags to the sctp_flags of an inp. + * To be used when the write lock of the inp is not held. + */ +void +sctp_pcb_add_flags(struct sctp_inpcb *inp, uint32_t flags) +{ + uint32_t old_flags, new_flags; + + do { + old_flags = inp->sctp_flags; + new_flags = old_flags | flags; + } while (atomic_cmpset_int(&inp->sctp_flags, old_flags, new_flags) == 0); +} diff --git a/sys/netinet/sctp_pcb.h b/sys/netinet/sctp_pcb.h index 736b0f9d54e9..687ccf6a1c50 100644 --- a/sys/netinet/sctp_pcb.h +++ b/sys/netinet/sctp_pcb.h @@ -619,6 +619,9 @@ int sctp_swap_inpcb_for_listen(struct sctp_inpcb *inp); void sctp_clean_up_stream(struct sctp_tcb *stcb, struct sctp_readhead *rh); +void + sctp_pcb_add_flags(struct sctp_inpcb *, uint32_t); + /*- * Null in last arg inpcb indicate run on ALL ep's. Specific inp in last arg * indicates run on ONLY assoc's of the specified endpoint. diff --git a/sys/netinet/sctputil.c b/sys/netinet/sctputil.c index 905bd2be129b..1b2ba9371021 100644 --- a/sys/netinet/sctputil.c +++ b/sys/netinet/sctputil.c @@ -4340,7 +4340,7 @@ sctp_abort_notification(struct sctp_tcb *stcb, bool from_peer, bool timeout, if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) && (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_CONNECTED))) { - stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_WAS_ABORTED; + sctp_pcb_add_flags(stcb->sctp_ep, SCTP_PCB_FLAGS_WAS_ABORTED); } if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) || (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||