From nobody Wed Sep 27 12:36:56 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 4Rwbhm56hmz4vPgM; Wed, 27 Sep 2023 12:36:56 +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 4Rwbhm481Dz4P0R; Wed, 27 Sep 2023 12:36:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1695818216; 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=hrJvq7V8DZuk1uAggTkuWb56Pmo4HJ0NNzesQ9xKvyM=; b=gJN3+rAGnQNlOM2C5ED5UjsYKW3pqkAXnk8C62XQmtaSH4+331WpF6cjLO1gY+lmBIXS9v rW7Pez75dh8vGD8ByTcCu1S7o4Z27DVOQBgr7xr2ubJBWyPIBpmONkcP3p8KgQC2u7j80U H+7CjfMTUWAgUQrcmNAaimJyk6Zsnsmku7OuaEsGVZqiDo4N/0/EZIuxHsKLCmEcw9uNYy A6DgqT8Pj8oxhjwyqrBgQSKbeRjcqXmT9FuwfyJhmgUlvJcW6Y+xBN44q9cHiLuqBiaIOQ 2Y+/plKunsiEBTAsfWN4RszEDpzb+lSMZXID6p4Di6TuHvuYSqcsDaSn+RIrZQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1695818216; a=rsa-sha256; cv=none; b=u1oYSJdH+MgCn5/n++6KqPGHrQc9MmLxxR4Z3bQojousOmqJ7DWodO0ZBvs1GwaBNRk1xK KgMHQkJ8+hBNkZI3ZDiEMWtctMi6rSUmEaCVYubcZ2VVfFhKOfgzOpjjribCgE1gI30BK9 b1VlIVZjRYgt3AettcF7kuNxJyfIRjfB3SF+5mRH8EW5Yq4v35BSVDDz0d6UGRHG8cYsEP Hxqo9futr+lc8T9HKqXTO4F1tp38lEWvRIqbxx/IJfPfNf7v8AYV8gNR2bk0M0XTRbpdml Y8FAoVnHVoIZQCzA7EzJQcjUgGv8Kz5e6+Z5boVIZdkbnNGfVEZe+c8srpghtA== 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=1695818216; 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=hrJvq7V8DZuk1uAggTkuWb56Pmo4HJ0NNzesQ9xKvyM=; b=yqnfPYaAK5qSRWwVawWglJxFwcTI12nWbjXkeHMFWL9ig9eKEcyCfhuTTK2pLZM9MzTL08 w1xfkFp+/anhUrqP+05zr1LQ5XsanlNSZ8VSelpI1Cwu2en6wNijFvHLbG5kGjthomO76H WJA1Y9n8NHsyAn57iIReP3iERo5ICewZy+Hm2i9fOOoOZE2gwaBjGjflKe5KbLlWyGMr+0 eg8KLRZTX7+z7ccUHT5U2+fi2iDhGAmtuq7SBCJeJNeVU6B3+/aLH8UnABnS6aAKzEospH YayWKpDuMo2m1uKwryZ8Qj42Lilss2JH1OVAiueJOJOSQhhigqFvmGPUOri0XQ== 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 4Rwbhm2g8tzfsf; Wed, 27 Sep 2023 12:36:56 +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 38RCaudu091647; Wed, 27 Sep 2023 12:36:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 38RCaugi091645; Wed, 27 Sep 2023 12:36:56 GMT (envelope-from git) Date: Wed, 27 Sep 2023 12:36:56 GMT Message-Id: <202309271236.38RCaugi091645@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 61a14ddfe012 - main - 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/main X-Git-Reftype: branch X-Git-Commit: 61a14ddfe012ca7b57a101725e5c654269f200ca Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=61a14ddfe012ca7b57a101725e5c654269f200ca commit 61a14ddfe012ca7b57a101725e5c654269f200ca Author: Mark Johnston AuthorDate: 2023-09-27 12:24:11 +0000 Commit: Mark Johnston CommitDate: 2023-09-27 12:29:34 +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 --- 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)