From nobody Wed Oct 04 13:43:46 2023 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 4S0wrg2Zsjz4vxr1; Wed, 4 Oct 2023 13:43:47 +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 4S0wrf6NQzz3ZCB; Wed, 4 Oct 2023 13:43:46 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1696427026; 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=P93G1fDDQDRwDw92xAaoRr4PWQKXkpbxypcCPjzRXpg=; b=ZkewE/ESP+3Csl6O8A6r019vKHWJQ0YwdPzM/NIrCgmOWkjVrC2tvI7d/33fQKhhEebU9O 42LtIX16j69hsYZnqLzfkjZ3K4jfM9rno3imLkk2opuwOyz92c/cDiyjjNgneQqD6nMdK3 kgbC9MWrlONqhRQeN+DhtblN060b9T+GwlFRqEjw8sV21PbppaAGFGf8IZcs+jEq3JdVQM VetJzA1xIu4u3OsxegAHOMzk90lVvN8aI7X4Ga91suDJnuKK8vGTn40AhMtBHcemHTGkyd f62DEPI4CPpbfb0MJ5MJ2IAhMre0Lf35c9xi2xL/9b/VUfNvOIfit0PmgcDQjw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1696427026; a=rsa-sha256; cv=none; b=gCvwABx+VVftkl00s/vvZSdOIVd7rOPrLsSrfXTwkgRNWMC4bi2eEiYFQqS1+5MuaTjvIO r+zvry09bqKsO9AElgxkwpCiUQ4/oRfSTqN/Qo573o2iwr7xGJRh/9O5lOX9RA6Z51yW7j dLNon9N11YpSQLYO5wMAU4h7++RUsiIhsTLYL/8wE3N462ujDBwymSQiSeobhhax5uJnnK tg7bnXVellLvmn8majkL6iS7PjkRr79OLJQelFbF8JaGAq0KoDFsGuzur7kyxeAfBWiAwu 1cf1KC9hmRbnvzRpt4VZ+Z4wYD3jqVet+aWPkVokyviFVKKhgkGpimMar16Bog== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1696427026; 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=P93G1fDDQDRwDw92xAaoRr4PWQKXkpbxypcCPjzRXpg=; b=H+OpNE/phD9itat+Iyb9FyZK6WmB3gftF+VMQKU0YVMEGnsi+sNMJvvt/b9zzC/qcRdM5O n/fseZB4zqiyuo9H+QRY63GNxoP1Gzw4RdLOHjAfrTaJ/mdE4OcGqmz17a7U+5fveBllk6 C10FNaKDUMcSvhxKdY2gVxcIaDVAKRUfzVd8FpCD+iwSg/l2lZFKZKUiQY77tE2jtoziXM QoDlipepTH+7uJZnv7/ZZIf39DmH7852GXwvzRwOGGxe0CByDLr0NTO2qws1/XK03PJFIf 88X5dDwn4Ndq1n9LMp725c+KF2NcueN2iLNc2IRupmMJW+gOn3aJMGYDf0c1IA== 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 4S0wrf5L6pzfYS; Wed, 4 Oct 2023 13:43:46 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 394DhkQT020004; Wed, 4 Oct 2023 13:43:46 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 394Dhku4020001; Wed, 4 Oct 2023 13:43:46 GMT (envelope-from git) Date: Wed, 4 Oct 2023 13:43:46 GMT Message-Id: <202310041343.394Dhku4020001@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 20c494a9d3f2 - stable/14 - unix: Fix a lock order reveral 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: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 20c494a9d3f20e2942c99ca517d0e983a0ac73e8 Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=20c494a9d3f20e2942c99ca517d0e983a0ac73e8 commit 20c494a9d3f20e2942c99ca517d0e983a0ac73e8 Author: Mark Johnston AuthorDate: 2023-09-27 12:24:11 +0000 Commit: Mark Johnston CommitDate: 2023-10-04 13:41:38 +0000 unix: Fix a lock order reveral Running the test suite yields: lock order reversal: 1st 0xfffff80004bc6700 unp (unp, sleep mutex) @ sys/kern/uipc_usrreq.c:390 2nd 0xffffffff81a94b30 unp_link_rwlock (unp_link_rwlock, rw) @ sys/kern/uipc_usrreq.c:2934 lock order unp -> unp_link_rwlock attempted at: 0xffffffff80bc216e at witness_checkorder+0xbbe 0xffffffff80b493a5 at _rw_wlock_cookie+0x65 0xffffffff80c0a8e2 at unp_discard+0x22 0xffffffff80c0a888 at unp_freerights+0x38 0xffffffff80c09fdd at unp_scan+0x9d 0xffffffff80c0f9a7 at uipc_sosend_dgram+0x727 0xffffffff80c00a79 at sousrsend+0x79 0xffffffff80c072d0 at kern_sendit+0x1c0 0xffffffff80c074d7 at sendit+0xb7 0xffffffff80c076f3 at sys_sendmsg+0x63 0xffffffff8104d957 at amd64_syscall+0x6b7 0xffffffff8101f9eb at fast_syscall_common+0xf8 This happens when uipc_sosend_dgram() discards a control message because the receive socket buffer is full. The overflow handling frees internalized file references in the socket buffer before freeing mbufs. It does this with socket PCBs locked, leading to the LOR. Defer handling of file references until the PCBs are unlocked. Reviewed by: glebius MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D41884 (cherry picked from commit 61a14ddfe012ca7b57a101725e5c654269f200ca) --- sys/kern/uipc_usrreq.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index 291ff7cf8cae..f12693f3982a 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -1332,8 +1332,10 @@ uipc_sosend_dgram(struct socket *so, struct sockaddr *addr, struct uio *uio, } else { soroverflow_locked(so2); error = ENOBUFS; - if (f->m_next->m_type == MT_CONTROL) - unp_scan(f->m_next, unp_freerights); + if (f->m_next->m_type == MT_CONTROL) { + c = f->m_next; + f->m_next = NULL; + } } if (addr != NULL)